168 lines
6.8 KiB
CMake
168 lines
6.8 KiB
CMake
# Target qualification driver.
|
|
#
|
|
# 1. Installs the build tree and consumes it through an isolated fixture that
|
|
# records the target tuple (target, triple, compiler, linkage, reflection,
|
|
# modules) and runs one behaviour per module.
|
|
# 2. Re-configures the source tree for negative cases: unknown target,
|
|
# unsupported module on a target, and a missing external dependency. Each
|
|
# must fail at configure time with a useful message.
|
|
# 3. Re-configures the wasm subset positively to prove the allowlist accepts
|
|
# a pure computation selection without native networking/SQLite/reflection.
|
|
|
|
foreach(required IN ITEMS VOID_BUILD_DIR VOID_SOURCE_DIR VOID_TEST_SOURCE_DIR
|
|
VOID_TEST_ROOT VOID_CXX_COMPILER VOID_CTEST_COMMAND)
|
|
if(NOT DEFINED ${required} OR "${${required}}" STREQUAL "")
|
|
message(FATAL_ERROR "${required} is required")
|
|
endif()
|
|
endforeach()
|
|
|
|
file(REMOVE_RECURSE "${VOID_TEST_ROOT}")
|
|
file(MAKE_DIRECTORY "${VOID_TEST_ROOT}")
|
|
|
|
set(_gen_args "")
|
|
if(DEFINED VOID_GENERATOR AND NOT VOID_GENERATOR STREQUAL "")
|
|
list(APPEND _gen_args -G "${VOID_GENERATOR}")
|
|
endif()
|
|
if(DEFINED VOID_MAKE_PROGRAM AND NOT VOID_MAKE_PROGRAM STREQUAL "")
|
|
list(APPEND _gen_args "-DCMAKE_MAKE_PROGRAM=${VOID_MAKE_PROGRAM}")
|
|
endif()
|
|
|
|
# ── 1. Install and consume the current target ─────────────────────────────────
|
|
set(_install_prefix "${VOID_TEST_ROOT}/install")
|
|
set(_install_command "${CMAKE_COMMAND}" --install "${VOID_BUILD_DIR}"
|
|
--prefix "${_install_prefix}")
|
|
if(DEFINED VOID_BUILD_CONFIG AND NOT VOID_BUILD_CONFIG STREQUAL "")
|
|
list(APPEND _install_command --config "${VOID_BUILD_CONFIG}")
|
|
endif()
|
|
execute_process(COMMAND ${_install_command} COMMAND_ERROR_IS_FATAL ANY)
|
|
|
|
set(_consumer_build "${VOID_TEST_ROOT}/TargetProfile")
|
|
set(_consumer_source "${VOID_TEST_SOURCE_DIR}/TargetProfile")
|
|
set(_no_external_deps
|
|
-DCMAKE_DISABLE_FIND_PACKAGE_Boost=TRUE
|
|
-DCMAKE_DISABLE_FIND_PACKAGE_LibArchive=TRUE
|
|
-DCMAKE_DISABLE_FIND_PACKAGE_OpenSSL=TRUE
|
|
-DCMAKE_DISABLE_FIND_PACKAGE_PkgConfig=TRUE
|
|
-DCMAKE_DISABLE_FIND_PACKAGE_SQLite3=TRUE
|
|
-DCMAKE_DISABLE_FIND_PACKAGE_Threads=TRUE)
|
|
execute_process(
|
|
COMMAND "${CMAKE_COMMAND}" -S "${_consumer_source}" -B "${_consumer_build}"
|
|
${_gen_args}
|
|
"-DCMAKE_PREFIX_PATH=${_install_prefix}"
|
|
"-DCMAKE_CXX_COMPILER=${VOID_CXX_COMPILER}"
|
|
"-DVOID_EXPECTED_TARGET=${VOID_TARGET}"
|
|
${_no_external_deps}
|
|
COMMAND_ERROR_IS_FATAL ANY)
|
|
|
|
set(_consumer_build_command "${CMAKE_COMMAND}" --build "${_consumer_build}")
|
|
if(DEFINED VOID_BUILD_CONFIG AND NOT VOID_BUILD_CONFIG STREQUAL "")
|
|
list(APPEND _consumer_build_command --config "${VOID_BUILD_CONFIG}")
|
|
endif()
|
|
execute_process(COMMAND ${_consumer_build_command} COMMAND_ERROR_IS_FATAL ANY)
|
|
|
|
set(_profile_file "${_consumer_build}/target-profile.txt")
|
|
if(NOT EXISTS "${_profile_file}")
|
|
message(FATAL_ERROR "[TargetQualification] consumer did not record a profile")
|
|
endif()
|
|
file(READ "${_profile_file}" _profile)
|
|
foreach(_field IN ITEMS target triple compiler linkage reflection modules)
|
|
if(NOT _profile MATCHES "(^|\n)${_field}=")
|
|
message(FATAL_ERROR
|
|
"[TargetQualification] profile misses '${_field}':\n${_profile}")
|
|
endif()
|
|
endforeach()
|
|
if(NOT _profile MATCHES "(^|\n)target=${VOID_TARGET}(\n|$)")
|
|
message(FATAL_ERROR
|
|
"[TargetQualification] profile target mismatch (expected ${VOID_TARGET}):\n${_profile}")
|
|
endif()
|
|
|
|
if(NOT DEFINED VOID_CROSSCOMPILING OR NOT VOID_CROSSCOMPILING)
|
|
execute_process(
|
|
COMMAND "${VOID_CTEST_COMMAND}" --test-dir "${_consumer_build}"
|
|
--output-on-failure
|
|
COMMAND_ERROR_IS_FATAL ANY)
|
|
endif()
|
|
|
|
# ── 2. Negative and positive configure cases ─────────────────────────────────
|
|
set(_configure_result 0)
|
|
set(_configure_output "")
|
|
|
|
function(run_void_configure name)
|
|
set(_build_dir "${VOID_TEST_ROOT}/configure-${name}")
|
|
file(REMOVE_RECURSE "${_build_dir}")
|
|
execute_process(
|
|
COMMAND "${CMAKE_COMMAND}" -S "${VOID_SOURCE_DIR}" -B "${_build_dir}"
|
|
${_gen_args}
|
|
"-DCMAKE_CXX_COMPILER=${VOID_CXX_COMPILER}"
|
|
-DCMAKE_BUILD_TYPE=Debug
|
|
${ARGN}
|
|
RESULT_VARIABLE _result
|
|
OUTPUT_VARIABLE _stdout
|
|
ERROR_VARIABLE _stderr)
|
|
set(_configure_result "${_result}" PARENT_SCOPE)
|
|
set(_configure_output "${_stdout}${_stderr}" PARENT_SCOPE)
|
|
set(_configure_build_dir "${_build_dir}" PARENT_SCOPE)
|
|
endfunction()
|
|
|
|
function(expect_configure_failure name pattern)
|
|
run_void_configure("${name}" ${ARGN})
|
|
if(_configure_result EQUAL 0)
|
|
message(FATAL_ERROR
|
|
"[TargetQualification] '${name}' configured successfully but "
|
|
"was expected to fail")
|
|
endif()
|
|
if(NOT _configure_output MATCHES "${pattern}")
|
|
message(FATAL_ERROR
|
|
"[TargetQualification] '${name}' failed without matching "
|
|
"'${pattern}'. Output:\n${_configure_output}")
|
|
endif()
|
|
message(STATUS "[TargetQualification] ${name}: rejected as expected")
|
|
endfunction()
|
|
|
|
# Unknown target profile.
|
|
expect_configure_failure(unknown-target "Unknown VOID_TARGET"
|
|
-DVOID_TARGET=plan9
|
|
-DVOID_ENABLED_MODULES=Core
|
|
-DVOID_ENABLE_TESTING=OFF)
|
|
|
|
# Native module on the browser/Wasm target. IPC pulls IO/Async/Resilience,
|
|
# which are also outside the wasm allowlist.
|
|
expect_configure_failure(wasm-rejects-native
|
|
"Modules not supported on target 'wasm'"
|
|
-DVOID_TARGET=wasm
|
|
-DVOID_ENABLED_MODULES=IPC
|
|
-DVOID_ENABLE_TESTING=OFF)
|
|
|
|
# Native networking is rejected before Boost/OpenSSL are even resolved.
|
|
expect_configure_failure(wasm-rejects-net
|
|
"Modules not supported on target 'wasm'"
|
|
-DVOID_TARGET=wasm
|
|
-DVOID_ENABLED_MODULES=Net
|
|
-DVOID_ENABLE_TESTING=OFF)
|
|
|
|
# Missing external dependency fails with the dependency name.
|
|
expect_configure_failure(missing-sqlite "SQLite3"
|
|
-DVOID_ENABLED_MODULES=Sqlite
|
|
-DVOID_ENABLE_TESTING=OFF
|
|
-DCMAKE_DISABLE_FIND_PACKAGE_SQLite3=TRUE)
|
|
|
|
# The pure subset must configure for wasm and record the target.
|
|
run_void_configure(wasm-subset
|
|
-DVOID_TARGET=wasm
|
|
-DVOID_ENABLED_MODULES=Data
|
|
-DVOID_ENABLE_TESTING=OFF)
|
|
if(NOT _configure_result EQUAL 0)
|
|
message(FATAL_ERROR
|
|
"[TargetQualification] wasm subset failed to configure:\n${_configure_output}")
|
|
endif()
|
|
set(_manifest "${_configure_build_dir}/void-target-manifest.cmake")
|
|
if(NOT EXISTS "${_manifest}")
|
|
message(FATAL_ERROR "[TargetQualification] wasm subset wrote no manifest")
|
|
endif()
|
|
file(READ "${_manifest}" _manifest_text)
|
|
if(NOT _manifest_text MATCHES "VOID_TARGET_MANIFEST_TARGET \"wasm\"")
|
|
message(FATAL_ERROR
|
|
"[TargetQualification] wasm manifest does not record target wasm:\n${_manifest_text}")
|
|
endif()
|
|
message(STATUS "[TargetQualification] wasm subset: configured and recorded")
|