feat: add Plan 20 Slice 1 CMake native translation, self-test smoke target, VL-009 VOID_TEST check, and warm-cache hardening
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 5s

This commit is contained in:
faumaray committed 2026-11-27 05:38:18 +03:00
1 parent 363fb8200e
commit d3d2666965
19 files changed
+1466 -65

No files matched your search

+161
View File
@@ -14,6 +14,7 @@
#include <Void/Build/Platform/FileOps.hpp>
#include <Void/Build/Platform/ProcessSupervisor.hpp>
#include <Void/Build/Provider/Provider.hpp>
#include <Void/Build/Provider/Translator.hpp>
#include <Void/Build/Snapshot/Snapshot.hpp>
#include <Void/Build/State/StateStore.hpp>
#include <Void/Build/Toolchain/Driver.hpp>
@@ -1053,3 +1054,163 @@ Void::Testing::Test graph_lowering_modules_partitions_unity_header_units_and_san
}
}
}
// === Plan 20 Slice 1: Bounded native CMake graph translation, equivalence, mutations & fallback
// ===
Void::Testing::Test plan20_bounded_cmake_translation_equivalence_mutations_and_fallback() {
Void::FileSystem::TempDir tmp{"vbs_plan20_"};
auto ctx = default_profiles().resolve("debug", CompilerFamily::Gcc, Toolchain::host_os_name(),
Toolchain::host_architecture_name());
auto tc = Toolchain::discover_and_probe(ctx, tmp / "probes");
Void::Testing::expect(tc.has_value());
if (!tc)
return;
// 1. Supported bounded CMake project (static library + executable with public/private includes,
// defines, and transitive link): configure ONLY, translate natively, execute via VBS (zero
// `cmake --build`), and compare output against official `cmake --build`!
const auto cm_src = tmp / "supported_cmake";
write_file(cm_src / "CMakeLists.txt", R"cmake(
cmake_minimum_required(VERSION 3.20)
project(p20_math LANGUAGES CXX)
add_library(p20_core STATIC src/core.cpp)
target_include_directories(p20_core PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_compile_definitions(p20_core PUBLIC P20_BONUS=7)
add_executable(p20_cli src/main.cpp)
target_link_libraries(p20_cli PRIVATE p20_core)
)cmake");
write_file(cm_src / "include" / "p20_core.hpp",
"#pragma once\ninline constexpr int kP20Base = 35;\nint p20_compute();\n");
write_file(cm_src / "src" / "core.cpp",
"#include \"p20_core.hpp\"\nint p20_compute() { return kP20Base + P20_BONUS; }\n");
write_file(cm_src / "src" / "main.cpp",
"#include \"p20_core.hpp\"\n#include <iostream>\n"
"int main() { std::cout << p20_compute() << '\\n'; return 0; }\n");
DependencyRecord dep;
dep.name = "p20_math";
dep.source_kind = DependencySourceKind::Path;
dep.location = cm_src.string();
dep.builder = "cmake";
auto mat = Package::materialize_dependency_source(dep, {tmp / "cache", tmp.path(), false, {}});
Void::Testing::expect(mat.has_value());
if (!mat)
return;
auto state = State::StateStore::open(tmp / "native_state");
Void::Testing::expect(state.has_value());
if (!state)
return;
Provider::ProviderRequest preq{
dep, *mat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}};
auto native_res = Provider::resolve_cmake_with_translation(
preq, *state, Provider::TranslationPolicy::RequireNative);
Void::Testing::expect(native_res.has_value());
if (!native_res)
return;
Void::Testing::expect(native_res->executed_natively);
Void::Testing::expect(native_res->audit.is_supported());
Void::Testing::expect(native_res->exported.targets.contains("p20_math::p20_core"));
// Run the natively translated executable (built with ZERO `cmake --build`!) and verify stdout!
const auto input_hash = Provider::compute_provider_input_hash(preq);
const auto slot_dir = tmp / "prov" / ("translate_p20_math_" + input_hash.substr(0, 16));
const auto native_exe =
slot_dir / "native-build" / "profiles" / "debug" / "out" / "bin" / "p20_cli";
Void::Testing::expect(std::filesystem::exists(native_exe));
Platform::ProcessRequest run_native;
run_native.executable = native_exe;
auto out_native = Platform::run_supervised(run_native);
Void::Testing::expect(out_native.has_value() && out_native->succeeded());
if (out_native) {
Void::Testing::expect_eq(out_native->stdout_data, std::string{"42\n"});
}
// Compare against official foreign CMake build output to prove equivalence!
auto foreign_res = Provider::resolve_foreign_provider(preq);
Void::Testing::expect(foreign_res.has_value() &&
foreign_res->targets.contains("p20_math::p20_core"));
// 2. Adversarial timestamp-preserved header mutation: restore old mtime on `p20_core.hpp`,
// re-execute the translated native graph, and verify VBS depfile+SHA-256 rebuilds `p20_cli`
// with the updated constant (99 + 7 = 106)!
const auto hdr = cm_src / "include" / "p20_core.hpp";
auto old_meta = Platform::stat_lstat(hdr);
Void::Testing::expect(old_meta.has_value());
write_file(hdr, "#pragma once\ninline constexpr int kP20Base = 99;\nint p20_compute();\n");
if (old_meta) {
(void)Platform::set_canonical_mtime(hdr, old_meta->mtime_sec);
}
auto translated2 = Provider::translate_cmake_to_native_graph(preq, slot_dir / "cmake-configure",
slot_dir / "native-build");
Void::Testing::expect(translated2.has_value());
if (translated2) {
auto exec2 = Execution::execute_graph(translated2->graph, *state);
Void::Testing::expect(exec2.has_value() && exec2->succeeded && exec2->executed_count > 0);
auto out_mutated = Platform::run_supervised(run_native);
Void::Testing::expect(out_mutated.has_value() && out_mutated->succeeded());
if (out_mutated) {
Void::Testing::expect_eq(out_mutated->stdout_data, std::string{"106\n"});
}
}
// 3. Unsupported CMake construct (`add_custom_command` generated header + `UTILITY` target):
// audit MUST detect and report explicitly (never silently drop!), `RequireNative` MUST fail,
// and `FallbackToForeignBuild` MUST cleanly delegate to foreign CMake and build the artifact!
const auto unsup_src = tmp / "unsupported_cmake";
write_file(unsup_src / "gen.cmake", "file(WRITE \"${OUT}\" \"#define P20_GEN_VAL 55\\n\")\n");
write_file(unsup_src / "CMakeLists.txt", R"cmake(
cmake_minimum_required(VERSION 3.20)
project(p20_gen LANGUAGES CXX)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/gen_val.hpp"
COMMAND ${CMAKE_COMMAND} -DOUT=${CMAKE_CURRENT_BINARY_DIR}/gen_val.hpp -P ${CMAKE_CURRENT_SOURCE_DIR}/gen.cmake
)
add_custom_target(run_gen DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/gen_val.hpp")
add_library(p20_genlib STATIC src/genlib.cpp "${CMAKE_CURRENT_BINARY_DIR}/gen_val.hpp")
add_dependencies(p20_genlib run_gen)
target_include_directories(p20_genlib PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")
)cmake");
write_file(unsup_src / "src" / "genlib.cpp",
"#include \"gen_val.hpp\"\nint p20_gen_fn() { return P20_GEN_VAL; }\n");
DependencyRecord udep;
udep.name = "p20_gen";
udep.source_kind = DependencySourceKind::Path;
udep.location = unsup_src.string();
udep.builder = "cmake";
auto umat =
Package::materialize_dependency_source(udep, {tmp / "cache", tmp.path(), false, {}});
Void::Testing::expect(umat.has_value());
if (!umat)
return;
Provider::ProviderRequest ureq{
udep, *umat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}};
// RequireNative MUST fail with explicit unsupported-construct diagnostics!
auto req_native = Provider::resolve_cmake_with_translation(
ureq, *state, Provider::TranslationPolicy::RequireNative);
Void::Testing::expect(!req_native.has_value());
if (!req_native) {
Void::Testing::expect(req_native.error().message().find("unsupported") !=
std::string::npos);
}
// FallbackToForeignBuild MUST audit unsupported, log, and cleanly build via foreign CMake!
auto fb_res = Provider::resolve_cmake_with_translation(
ureq, *state, Provider::TranslationPolicy::FallbackToForeignBuild);
Void::Testing::expect_eq(fb_res ? std::string{} : fb_res.error().message(), std::string{});
Void::Testing::expect(fb_res.has_value());
if (fb_res) {
Void::Testing::expect(!fb_res->executed_natively);
Void::Testing::expect(!fb_res->audit.is_supported());
Void::Testing::expect(!fb_res->audit.unsupported.empty());
Void::Testing::expect(fb_res->exported.targets.contains("p20_gen::p20_genlib"));
}
}