Merge issue-38-targets: qualify target support (closes #38)
This commit is contained in:
commit
fe231b0149
8 files changed
+689
No files matched your search
@@ -158,6 +158,23 @@ if(_all_generated)
|
||||
)
|
||||
set_tests_properties(VoidInstalledComponentConsumers PROPERTIES
|
||||
DEPENDS VoidTests)
|
||||
|
||||
add_test(NAME VoidTargetQualification
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DVOID_BUILD_DIR=${CMAKE_BINARY_DIR}
|
||||
-DVOID_SOURCE_DIR=${CMAKE_SOURCE_DIR}
|
||||
-DVOID_TEST_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}/package
|
||||
-DVOID_TEST_ROOT=${CMAKE_CURRENT_BINARY_DIR}/target-qualification
|
||||
-DVOID_CXX_COMPILER=${CMAKE_CXX_COMPILER}
|
||||
-DVOID_CTEST_COMMAND=${CMAKE_CTEST_COMMAND}
|
||||
-DVOID_GENERATOR=${CMAKE_GENERATOR}
|
||||
-DVOID_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
|
||||
-DVOID_TARGET=${VOID_TARGET_DETECTED}
|
||||
-DVOID_CROSSCOMPILING=${CMAKE_CROSSCOMPILING}
|
||||
-DVOID_BUILD_CONFIG=$<CONFIG>
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/package/TargetQualification.cmake)
|
||||
set_tests_properties(VoidTargetQualification PROPERTIES
|
||||
DEPENDS VoidTests)
|
||||
endif()
|
||||
|
||||
# ── Test-support executables & libraries ──────────────────────────────────────
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
cmake_minimum_required(VERSION 4.0)
|
||||
project(VoidTargetProfileConsumer LANGUAGES CXX)
|
||||
|
||||
# Records and asserts the target tuple of an installed Void package. The
|
||||
# qualification driver (tests/package/TargetQualification.cmake) passes the
|
||||
# expected target and then checks the emitted profile file. Core is the
|
||||
# always-present leaf module; per-module consumption is covered by the other
|
||||
# tests/package fixtures.
|
||||
if(NOT DEFINED VOID_EXPECTED_TARGET OR VOID_EXPECTED_TARGET STREQUAL "")
|
||||
message(FATAL_ERROR "VOID_EXPECTED_TARGET is required")
|
||||
endif()
|
||||
|
||||
find_package(Void CONFIG REQUIRED COMPONENTS Core)
|
||||
|
||||
include("${Void_DIR}/void-target-manifest.cmake")
|
||||
|
||||
if(NOT VOID_TARGET_MANIFEST_TARGET STREQUAL VOID_EXPECTED_TARGET)
|
||||
message(FATAL_ERROR
|
||||
"[TargetProfile] installed manifest target "
|
||||
"'${VOID_TARGET_MANIFEST_TARGET}' does not match expected "
|
||||
"'${VOID_EXPECTED_TARGET}'")
|
||||
endif()
|
||||
if(NOT Core IN_LIST VOID_TARGET_MANIFEST_MODULES)
|
||||
message(FATAL_ERROR
|
||||
"[TargetProfile] installed manifest does not record module 'Core' "
|
||||
"(modules: ${VOID_TARGET_MANIFEST_MODULES})")
|
||||
endif()
|
||||
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/target-profile.txt"
|
||||
"target=${VOID_TARGET_MANIFEST_TARGET}\n"
|
||||
"triple=${VOID_TARGET_MANIFEST_TRIPLE}\n"
|
||||
"compiler=${VOID_TARGET_MANIFEST_COMPILER_ID}-${VOID_TARGET_MANIFEST_COMPILER_VERSION}\n"
|
||||
"cxx_standard=${VOID_TARGET_MANIFEST_CXX_STANDARD}\n"
|
||||
"linkage=${VOID_TARGET_MANIFEST_LINKAGE}\n"
|
||||
"reflection=${VOID_TARGET_MANIFEST_REFLECTION}\n"
|
||||
"sanitizers=${VOID_TARGET_MANIFEST_SANITIZERS}\n"
|
||||
"modules=${VOID_TARGET_MANIFEST_MODULES}\n"
|
||||
)
|
||||
message(STATUS
|
||||
"[TargetProfile] target=${VOID_TARGET_MANIFEST_TARGET} "
|
||||
"triple=${VOID_TARGET_MANIFEST_TRIPLE} "
|
||||
"compiler=${VOID_TARGET_MANIFEST_COMPILER_ID}-${VOID_TARGET_MANIFEST_COMPILER_VERSION} "
|
||||
"linkage=${VOID_TARGET_MANIFEST_LINKAGE} "
|
||||
"reflection=${VOID_TARGET_MANIFEST_REFLECTION}")
|
||||
|
||||
add_executable(void_target_profile_consumer main.cpp)
|
||||
target_link_libraries(void_target_profile_consumer PRIVATE Void::Core)
|
||||
|
||||
enable_testing()
|
||||
add_test(NAME VoidTargetProfileConsumer COMMAND void_target_profile_consumer)
|
||||
@@ -0,0 +1,28 @@
|
||||
// Isolated consumer fixture for target qualification. Exercises a small
|
||||
// runtime behaviour from the always-present Core module so an install/consume
|
||||
// check covers headers, linkage and the module dependency closure.
|
||||
#include <Void/Core/CheckedBits.hpp>
|
||||
#include <Void/Core/Hash.hpp>
|
||||
#include <Void/Core/Uuid.hpp>
|
||||
|
||||
#include <random>
|
||||
#include <string_view>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::mt19937_64 rng{11};
|
||||
const auto uuid = Void::Uuid::v4(rng);
|
||||
const auto chars = Void::Uuid::format_chars(uuid);
|
||||
const auto reparsed =
|
||||
Void::Uuid::parse(std::string_view{chars.data(), chars.size()});
|
||||
if (!reparsed || *reparsed != uuid) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const auto aligned = Void::Bits::checked_align_up(13u, 8u);
|
||||
if (!aligned || *aligned != 16u) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return Void::Hash::fnv1a64("target-profile") != 0 ? 0 : 1;
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
# 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")
|
||||
Reference in new issue
Block a user