feat: complete Track A zero-CMake self-hosting, full VOID_TEST migration, and bit-identical Stage 2/3 bootstrap
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 2s

This commit is contained in:
faumaray committed 2026-11-27 06:51:43 +03:00
1 parent fe0d1a6483
commit 5e1916dc5c
23 files changed
+945 -141

No files matched your search

+156 -13
View File
@@ -9,6 +9,8 @@
#include <Void/Build/SelfHost/TestRegistryGen.hpp>
#include <Void/Build/State/StateStore.hpp>
#include <Void/Build/Toolchain/Driver.hpp>
#include <Void/Build/Util/Sha256.hpp>
#include <Void/Configuration/Env.hpp>
#include <Void/System/TempDir.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
@@ -25,10 +27,38 @@ void write_file(const std::filesystem::path &path, std::string_view content) {
auto r = Platform::atomic_write_file(path, content, false);
Void::Testing::expect(r.has_value());
}
std::filesystem::path locate_void_source_dir() {
if (auto env = Void::Configuration::get_env("VBS_VOID_SOURCE_DIR");
env && !env->empty() && std::filesystem::is_directory(*env)) {
return std::filesystem::path{*env};
}
#ifdef VBS_VOID_SOURCE_PATH
if (std::filesystem::is_directory(std::filesystem::path{VBS_VOID_SOURCE_PATH})) {
return std::filesystem::path{VBS_VOID_SOURCE_PATH};
}
#endif
return std::filesystem::path{Bootstrap::source_dir} / "build" / "voidlibrary-pinned";
}
std::filesystem::path locate_vbs_binary() {
std::error_code ec;
if (const auto self = std::filesystem::read_symlink("/proc/self/exe", ec);
!ec && !self.empty()) {
const auto sibling = self.parent_path() / "vbs";
if (std::filesystem::exists(sibling, ec)) {
return sibling;
}
}
if (!Bootstrap::binary_dir.empty()) {
return std::filesystem::path{Bootstrap::binary_dir} / "bin" / "vbs";
}
return {};
}
} // namespace
// Plan 18: Native non-CMake Void::Testing scanner avoids equal-basename collisions!
Void::Testing::Test native_test_registration_generator_avoids_basename_collisions() {
VOID_TEST(SelfHostTests, native_test_registration_generator_avoids_basename_collisions) {
Void::FileSystem::TempDir tmp{"vbs_testgen_"};
const auto f1 = tmp / "dir_a" / "SameStem.cpp";
const auto f2 = tmp / "dir_b" / "SameStem.cpp";
@@ -50,8 +80,8 @@ Void::Testing::Test native_test_registration_generator_avoids_basename_collision
// Plan 18: Strict native VoidLibrary closure + native VBS SDK + native test runner built
// completely WITHOUT CMake (trapped cmake shim ahead of PATH!) in a clean stage directory!
Void::Testing::Test strict_native_selfhost_voidlibrary_and_sdk_without_cmake() {
const std::filesystem::path void_src{VBS_VOID_SOURCE_PATH};
VOID_TEST(SelfHostTests, strict_native_selfhost_voidlibrary_and_sdk_without_cmake) {
const auto void_src = locate_void_source_dir();
Void::Testing::expect(std::filesystem::is_directory(void_src));
Void::FileSystem::TempDir tmp{"vbs_selfhost_"};
@@ -85,17 +115,13 @@ Void::Testing::Test strict_native_selfhost_voidlibrary_and_sdk_without_cmake() {
.include_directory((vbs_root / "include").string(), Visibility::Public)
.compile_option("-freflection", Visibility::Public);
// Generate native C++ test registrations for SdkDeclarations.cpp (NO CMake scanner!).
// Compile self-registering VL-009 VOID_TEST suite SdkDeclarations.cpp directly (zero CMake,
// zero external test scanner!).
const auto test_src = vbs_root / "tests" / "SdkDeclarations.cpp";
auto reg = SelfHost::generate_test_registration_unit(test_src, stage1_dir / "gen_tests");
Void::Testing::expect(reg.has_value() && reg->cases.size() >= 14);
if (!reg)
return;
auto native_tests = proj.executable("stage1_sdk_tests");
native_tests.cxx_standard(CxxStandard::Cxx26)
.sources(SourceSet::file(test_src.string()))
.sources(SourceSet::file(reg->generated_cpp.string()))
.link(sdk)
.link(void_libs.modules.at("Testing"))
.link(void_libs.modules.at("Data"));
@@ -230,8 +256,8 @@ int main() {
// VoidBuildSdk + VoidBuildCore + stage-isolated BootstrapConfig.hpp, ZERO CMake!) into stage1_dir,
// then executes that freshly self-hosted `stage1/bin/vbs` binary WITH TRAPPED `cmake` ON PATH to
// build and test a real Stage 2 C++ project!
Void::Testing::Test strict_native_full_vbs_stage1_to_stage2_without_cmake() {
const std::filesystem::path void_src{VBS_VOID_SOURCE_PATH};
VOID_TEST(SelfHostTests, strict_native_full_vbs_stage1_to_stage2_without_cmake) {
const auto void_src = locate_void_source_dir();
const std::filesystem::path vbs_root{Bootstrap::source_dir};
Void::Testing::expect(std::filesystem::is_directory(void_src));
@@ -342,8 +368,8 @@ void build(Void::Build::Project &p) {
// VL-009: Verify VoidLibrary's upstream self-registering `VOID_TEST(suite, name)` macro works
// purely with `g++` (zero CMake AND zero external scanner) including equal-basename files!
Void::Testing::Test native_void_test_macro_zero_cmake_and_basename_collisions() {
const std::filesystem::path void_src{VBS_VOID_SOURCE_PATH};
VOID_TEST(SelfHostTests, native_void_test_macro_zero_cmake_and_basename_collisions) {
const auto void_src = locate_void_source_dir();
Void::Testing::expect(std::filesystem::is_directory(void_src));
Void::FileSystem::TempDir tmp{"vbs_vl009_"};
@@ -434,3 +460,120 @@ VOID_TEST(BetaSuite, multiplication_works) {
Void::Testing::expect(ran->stdout_data.find("2 tests:") != std::string::npos);
}
}
// Track A3: Reproducible bit-identical artifacts across distinct build directories!
VOID_TEST(SelfHostTests, reproducible_stage2_equals_stage3_artifacts_across_build_dirs) {
const auto vbs_bin = locate_vbs_binary();
Void::Testing::expect(!vbs_bin.empty() && std::filesystem::exists(vbs_bin));
if (vbs_bin.empty() || !std::filesystem::exists(vbs_bin)) {
return;
}
Void::FileSystem::TempDir tmp{"vbs_repro_"};
const auto trap_bin = tmp / "trap_bin";
write_file(trap_bin / "cmake",
"#!/bin/sh\necho 'FORBIDDEN CMAKE INVOCATION IN REPRO STAGE' >&2\nexit 99\n");
(void)::chmod((trap_bin / "cmake").c_str(), 0755);
std::string trapped_path = trap_bin.string();
if (const char *old_path = std::getenv("PATH")) {
trapped_path += ":";
trapped_path += old_path;
}
const auto proj = tmp / "repro_proj";
write_file(proj / "build.profiles.cpp", R"cpp(#include <Void/Build.hpp>
void profiles(Void::Build::Profiles &p) {
Void::Build::ProfileDescription d;
d.name = "debug";
d.compile_options = {"-O0", "-g"};
d.reproducibility_epoch = 1700000000;
p.define(std::move(d));
}
)cpp");
write_file(proj / "build.cpp", R"cpp(#include <Void/Build.hpp>
void build(Void::Build::Project &p) {
auto gen = p.custom_action("gen_ver");
gen.command({"/bin/sh", "-c",
"mkdir -p \"$GEN\" && printf '#pragma once\\ninline constexpr int kVer = 7;\\n' "
"> \"$GEN/gen_ver.hpp\""})
.outputs({"gen_ver.hpp"});
auto lib = p.static_library("repro_lib");
lib.cxx_standard(Void::Build::CxxStandard::Cxx26)
.sources({"src/lib.cpp"})
.include_directory("include", Void::Build::Visibility::Public);
auto app = p.executable("repro_app");
app.cxx_standard(Void::Build::CxxStandard::Cxx26)
.sources({"src/main.cpp"})
.depends_on(gen)
.include_directory("$GEN/", Void::Build::Visibility::Private)
.link(lib);
}
)cpp");
write_file(proj / "include" / "repro.hpp", "#pragma once\nint repro_fn();\n");
write_file(proj / "src" / "lib.cpp", R"cpp(#include "repro.hpp"
namespace {
int local_helper() { return 35; }
struct AutoInit { int v{local_helper()}; };
const AutoInit g_init{};
} // namespace
int repro_fn() { return g_init.v; }
)cpp");
write_file(proj / "src" / "main.cpp", R"cpp(#include "repro.hpp"
#include "gen_ver.hpp"
#include <iostream>
int main() {
std::cout << (repro_fn() + kVer) << "|" << __DATE__ << "|" << __FILE__ << "\n";
return 0;
}
)cpp");
const auto stage_a = tmp / "stage_a";
const auto stage_b = tmp / "stage_b";
auto build_stage = [&](const std::filesystem::path &bdir) {
Platform::ProcessRequest req;
req.executable = vbs_bin;
req.arguments = {"build", "--project", proj.string(), "--build-dir",
bdir.string(), "--profile", "debug", "--no-cache"};
req.environment.set_vars["PATH"] = trapped_path;
req.timeout = std::chrono::seconds{120};
return Platform::run_supervised(req);
};
auto ra = build_stage(stage_a);
auto rb = build_stage(stage_b);
Void::Testing::expect(ra.has_value() && ra->succeeded());
Void::Testing::expect(rb.has_value() && rb->succeeded());
if (!ra || !rb || !ra->succeeded() || !rb->succeeded()) {
return;
}
const auto lib_a = stage_a / "profiles" / "debug" / "out" / "librepro_lib.a";
const auto lib_b = stage_b / "profiles" / "debug" / "out" / "librepro_lib.a";
const auto exe_a = stage_a / "profiles" / "debug" / "out" / "bin" / "repro_app";
const auto exe_b = stage_b / "profiles" / "debug" / "out" / "bin" / "repro_app";
auto sha_lib_a = Util::sha256_file_hex(lib_a);
auto sha_lib_b = Util::sha256_file_hex(lib_b);
auto sha_exe_a = Util::sha256_file_hex(exe_a);
auto sha_exe_b = Util::sha256_file_hex(exe_b);
Void::Testing::expect(sha_lib_a.has_value() && sha_lib_b.has_value());
Void::Testing::expect(sha_exe_a.has_value() && sha_exe_b.has_value());
if (sha_lib_a && sha_lib_b) {
Void::Testing::expect_eq(*sha_lib_a, *sha_lib_b);
}
if (sha_exe_a && sha_exe_b) {
Void::Testing::expect_eq(*sha_exe_a, *sha_exe_b);
}
Platform::ProcessRequest run_a;
run_a.executable = exe_a;
auto out_a = Platform::run_supervised(run_a);
Void::Testing::expect(out_a.has_value() && out_a->succeeded());
if (out_a) {
Void::Testing::expect(out_a->stdout_data.starts_with("42|"));
}
}