feat(translation,ide): add native C driver, Ninja custom commands, CMake CXX_MODULES, and vbs ide integration
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s

This commit is contained in:
faumaray committed 2026-11-27 07:50:54 +03:00
1 parent 5e1916dc5c
commit 6c225c2dff
27 files changed
+3443 -331

No files matched your search

+6 -1
View File
@@ -45,10 +45,15 @@ check_process(2 "" "--prefix is required" uninstall)
check_process(2 "" "--input and --output-dir are required" gen-tests)
check_process(0 "Usage: vbs publish " "" publish --help)
check_process(2 "" "--registry, --name, and --version are required" publish)
check_process(0 "Usage: vbs ide <command>.*Commands:.*generate.*query" "" ide --help)
check_process(0 "Usage: vbs ide generate " "" ide generate --help)
check_process(0 "Usage: vbs ide query " "" ide query --help)
check_process(2 "" "missing subcommand for 'vbs ide'" ide)
check_process(2 "" "unknown IDE kind" ide generate --editor invalid_ide)
execute_process(COMMAND "${VBS_REGISTRY}" --help
RESULT_VARIABLE reg_code OUTPUT_VARIABLE reg_out ERROR_VARIABLE reg_err TIMEOUT 15)
if(NOT "${reg_code}" STREQUAL "0" OR NOT reg_out MATCHES "Usage: vbs-registry")
message(FATAL_ERROR "vbs-registry --help failed: code=${reg_code}\nstdout=[${reg_out}]\nstderr=[${reg_err}]")
endif()
message(STATUS "32 native CLI and auto-generated Argparse help contracts verified")
message(STATUS "37 native CLI and auto-generated Argparse help contracts verified")
+688 -14
View File
@@ -1174,25 +1174,18 @@ target_link_libraries(p20_cli PRIVATE p20_core)
}
}
// 3. Unsupported CMake construct (`add_custom_command` generated header + `UTILITY` target):
// 3. Unsupported CMake construct (`USES_TERMINAL` console-pool custom 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}")
add_custom_target(run_console COMMAND ${CMAKE_COMMAND} -E echo p20_console USES_TERMINAL)
add_library(p20_genlib STATIC src/genlib.cpp)
add_dependencies(p20_genlib run_console)
)cmake");
write_file(unsup_src / "src" / "genlib.cpp",
"#include \"gen_val.hpp\"\nint p20_gen_fn() { return P20_GEN_VAL; }\n");
write_file(unsup_src / "src" / "genlib.cpp", "int p20_gen_fn() { return 55; }\n");
DependencyRecord udep;
udep.name = "p20_gen";
@@ -1306,13 +1299,14 @@ executable('mapp', 'src/main.cpp', include_directories: inc, link_with: lib)
Void::Testing::expect_eq(run_out->stdout_data, std::string{"42\n"});
}
// 2. Unsupported Meson `custom_target`: RequireNative MUST fail cleanly; FallbackToForeignBuild
// MUST build via foreign Meson provider!
// 2. Unsupported Meson `console: true` custom_target: RequireNative MUST fail cleanly;
// FallbackToForeignBuild MUST build via foreign Meson provider!
const auto u_src = tmp / "meson_custom";
write_file(u_src / "meson.build", R"meson(
project('p20m_custom', 'cpp')
gen = custom_target('gen_hdr',
output: 'gen_num.hpp',
console: true,
command: ['/bin/sh', '-c', 'printf "#define M_GEN_NUM 88\n" > "$1"', '--', '@OUTPUT@'])
static_library('mgenlib', ['src/gen.cpp', gen])
)meson");
@@ -1486,3 +1480,683 @@ void build(Void::Build::Project &p) {
Void::Testing::expect(res->stdout_data.find("PASSED 'consumer_test'") != std::string::npos);
}
}
// === Track B1: First-class C driver & mixed C/C++ native CMake + Meson translation ===
VOID_TEST(FullV1Tests, track_b1_native_c_driver_and_mixed_c_cpp_cmake_meson_translation) {
Void::FileSystem::TempDir tmp{"vbs_track_b1_"};
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;
}
Void::Testing::expect(!tc->c_compiler.empty());
Void::Testing::expect(tc->supports_c11 && tc->supports_c17 && tc->supports_c23);
auto state = State::StateStore::open(tmp / "state");
Void::Testing::expect(state.has_value());
if (!state) {
return;
}
// 1. Pure VBS native C17 static library + C++23 executable + CompDB separation.
{
const auto proj = tmp / "native_mixed";
const auto bdir = tmp / "native_mixed_build";
write_file(proj / "include" / "c_math.h",
"#pragma once\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n"
"int vbs_c_add(int a, int b);\n#ifdef __cplusplus\n}\n#endif\n");
write_file(proj / "src" / "c_math.c",
"#include \"c_math.h\"\n"
"_Static_assert(sizeof(int) >= 4, \"C11 _Static_assert check\");\n"
"int vbs_c_add(int a, int b) { return a + b; }\n");
write_file(proj / "src" / "main.cpp",
"#include \"c_math.h\"\n#include <iostream>\n"
"int main() { std::cout << \"c17+cxx23=\" << vbs_c_add(19, 23) << '\\n'; "
"return 0; }\n");
Graph::ProjectDescription desc;
desc.profile = ctx;
TargetRecord clib;
clib.name = "c_core";
clib.kind = TargetKind::StaticLibrary;
clib.c_standard = CStandard::C17;
clib.sources.push_back({SourceKind::File, "src/c_math.c"});
clib.include_directories.push_back({"include", Visibility::Public, false});
desc.targets.push_back(clib);
TargetRecord app;
app.name = "mixed_app";
app.kind = TargetKind::Executable;
app.cxx_standard = CxxStandard::Cxx23;
app.sources.push_back({SourceKind::File, "src/main.cpp"});
app.links.push_back({LinkKind::Local, "c_core", {}, Visibility::Private});
desc.targets.push_back(app);
auto graph = Graph::lower_project_graph(desc, *tc, {proj, bdir, nullptr, {}, 32768});
Void::Testing::expect(graph.has_value());
if (!graph) {
return;
}
const auto cmds = Editor::project_editor_commands(*graph);
bool checked_c_entry = false;
bool checked_cxx_entry = false;
for (const auto &e : cmds) {
if (e.file.filename() == "c_math.c") {
checked_c_entry = true;
Void::Testing::expect(std::ranges::contains(e.arguments, std::string{"-std=c17"}));
Void::Testing::expect(
!std::ranges::contains(e.arguments, std::string{"-std=c++23"}));
Void::Testing::expect_eq(e.arguments.front(), tc->c_compiler.string());
} else if (e.file.filename() == "main.cpp") {
checked_cxx_entry = true;
Void::Testing::expect(
std::ranges::contains(e.arguments, std::string{"-std=c++23"}));
Void::Testing::expect_eq(e.arguments.front(), tc->cxx_compiler.string());
}
}
Void::Testing::expect(checked_c_entry && checked_cxx_entry);
auto exec = Execution::execute_graph(*graph, *state);
Void::Testing::expect(exec.has_value() && exec->succeeded);
Platform::ProcessRequest r;
r.executable = bdir / "profiles" / "debug" / "out" / "bin" / "mixed_app";
auto out = Platform::run_supervised(r);
Void::Testing::expect(out.has_value() && out->succeeded());
if (out) {
Void::Testing::expect_eq(out->stdout_data, std::string{"c17+cxx23=42\n"});
}
}
// 2. CMake mixed C11 + C++20 native translation (zero cmake --build).
{
const auto cm_src = tmp / "cmake_mixed";
write_file(cm_src / "include" / "cmix.h",
"#pragma once\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n"
"int cmix_c_base(void);\n#ifdef __cplusplus\n}\n#endif\n"
"#ifdef __cplusplus\nint cmix_cxx_total();\n#endif\n");
write_file(cm_src / "src" / "helper.c",
"#include \"cmix.h\"\nint cmix_c_base(void) { return 30 + C_EXTRA; }\n");
write_file(cm_src / "src" / "wrapper.cpp",
"#include \"cmix.h\"\nint cmix_cxx_total() { return cmix_c_base() + CXX_EXTRA; "
"}\n");
write_file(cm_src / "src" / "cli.cpp",
"#include \"cmix.h\"\n#include <iostream>\n"
"int main() { std::cout << \"cmix=\" << cmix_cxx_total() << '\\n'; return 0; "
"}\n");
write_file(cm_src / "CMakeLists.txt", R"cmake(
cmake_minimum_required(VERSION 3.20)
project(tb1_cmake LANGUAGES C CXX)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)
add_library(cmix STATIC src/helper.c src/wrapper.cpp)
target_include_directories(cmix PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_compile_definitions(cmix PRIVATE
$<$<COMPILE_LANGUAGE:C>:C_EXTRA=5>
$<$<COMPILE_LANGUAGE:CXX>:CXX_EXTRA=7>)
add_executable(cmix_cli src/cli.cpp)
target_link_libraries(cmix_cli PRIVATE cmix)
)cmake");
DependencyRecord dep;
dep.name = "tb1_cm";
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;
}
Provider::ProviderRequest req{
dep, *mat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}};
auto res = Provider::resolve_cmake_with_translation(
req, *state, Provider::TranslationPolicy::RequireNative);
Void::Testing::expect_eq(res ? std::string{} : res.error().message(), std::string{});
Void::Testing::expect(res.has_value() && res->executed_natively &&
res->audit.is_supported());
const auto hash = Provider::compute_provider_input_hash(req);
const auto exe = tmp / "prov" / ("translate_tb1_cm_" + hash.substr(0, 16)) /
"native-build" / "profiles" / "debug" / "out" / "bin" / "cmix_cli";
Platform::ProcessRequest rr;
rr.executable = exe;
auto out = Platform::run_supervised(rr);
Void::Testing::expect(out.has_value() && out->succeeded());
if (out) {
Void::Testing::expect_eq(out->stdout_data, std::string{"cmix=42\n"});
}
}
// 3. Meson mixed C17 + C++20 native translation (zero meson compile).
if (Platform::resolve_executable("meson").has_value()) {
const auto m_src = tmp / "meson_mixed";
write_file(m_src / "include" / "mmix.h",
"#pragma once\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n"
"int mmix_c_base(void);\n#ifdef __cplusplus\n}\n#endif\n"
"#ifdef __cplusplus\nint mmix_cxx_total();\n#endif\n");
write_file(m_src / "src" / "helper.c",
"#include \"mmix.h\"\nint mmix_c_base(void) { return 20 + MC_ADD; }\n");
write_file(m_src / "src" / "wrap.cpp",
"#include \"mmix.h\"\nint mmix_cxx_total() { return mmix_c_base() + 15; }\n");
write_file(m_src / "src" / "main.cpp",
"#include \"mmix.h\"\n#include <iostream>\n"
"int main() { std::cout << \"mmix=\" << mmix_cxx_total() << '\\n'; return 0; "
"}\n");
write_file(m_src / "meson.build", R"meson(
project('tb1_meson', ['c', 'cpp'], default_options: ['c_std=c17', 'cpp_std=c++20'])
inc = include_directories('include')
lib = static_library('mmix', ['src/helper.c', 'src/wrap.cpp'],
include_directories: inc,
c_args: ['-DMC_ADD=7'])
executable('mmix_cli', ['src/main.cpp'], include_directories: inc, link_with: lib)
)meson");
DependencyRecord dep;
dep.name = "tb1_me";
dep.source_kind = DependencySourceKind::Path;
dep.location = m_src.string();
dep.builder = "meson";
auto mat =
Package::materialize_dependency_source(dep, {tmp / "cache", tmp.path(), false, {}});
Void::Testing::expect(mat.has_value());
if (!mat) {
return;
}
Provider::ProviderRequest req{
dep, *mat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}};
auto res = Provider::resolve_meson_with_translation(
req, *state, Provider::TranslationPolicy::RequireNative);
Void::Testing::expect_eq(res ? std::string{} : res.error().message(), std::string{});
Void::Testing::expect(res.has_value() && res->executed_natively &&
res->audit.is_supported());
const auto hash = Provider::compute_provider_input_hash(req);
const auto exe = tmp / "prov" / ("translate_meson_tb1_me_" + hash.substr(0, 16)) /
"native-build" / "profiles" / "debug" / "out" / "bin" / "mmix_cli";
Platform::ProcessRequest rr;
rr.executable = exe;
auto out = Platform::run_supervised(rr);
Void::Testing::expect(out.has_value() && out->succeeded());
if (out) {
Void::Testing::expect_eq(out->stdout_data, std::string{"mmix=42\n"});
}
}
}
// === Track B2: Bounded build.ninja CUSTOM_COMMAND translation & unsafe-rule rejection ===
VOID_TEST(FullV1Tests, track_b2_bounded_ninja_custom_command_cmake_and_meson_translation) {
Void::FileSystem::TempDir tmp{"vbs_track_b2_"};
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;
}
auto state = State::StateStore::open(tmp / "state");
Void::Testing::expect(state.has_value());
if (!state) {
return;
}
// 1. CMake hermetic custom command (generated header + generated .cpp + UTILITY DEPENDS).
{
const auto src = tmp / "cm_gen";
write_file(src / "gen_hdr.cmake",
"file(WRITE \"${OUT}\" \"#pragma once\\n#define B2_CM_HDR 50\\n\")\n");
write_file(src / "gen_cpp.cmake", "file(WRITE \"${OUT}\" \"#include \\\"gen_val.hpp\\\"\\n"
"int b2_cm_val() { return B2_CM_HDR + 27; }\\n\")\n");
write_file(src / "CMakeLists.txt", R"cmake(
cmake_minimum_required(VERSION 3.20)
project(tb2_cmake 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_hdr.cmake
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/gen_hdr.cmake"
)
add_custom_target(run_gen DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/gen_val.hpp")
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/gen_src.cpp"
COMMAND ${CMAKE_COMMAND} -DOUT=${CMAKE_CURRENT_BINARY_DIR}/gen_src.cpp -P ${CMAKE_CURRENT_SOURCE_DIR}/gen_cpp.cmake
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/gen_cpp.cmake" "${CMAKE_CURRENT_BINARY_DIR}/gen_val.hpp"
)
add_library(b2_lib STATIC "${CMAKE_CURRENT_BINARY_DIR}/gen_src.cpp" "${CMAKE_CURRENT_BINARY_DIR}/gen_val.hpp")
add_dependencies(b2_lib run_gen)
target_include_directories(b2_lib PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")
add_executable(b2_app src/main.cpp)
target_link_libraries(b2_app PRIVATE b2_lib)
)cmake");
write_file(src / "src" / "main.cpp",
"#include \"gen_val.hpp\"\n#include <iostream>\n"
"int b2_cm_val();\n"
"int main() { std::cout << \"cm_gen=\" << b2_cm_val() << '\\n'; return 0; }\n");
DependencyRecord dep;
dep.name = "tb2_cm";
dep.source_kind = DependencySourceKind::Path;
dep.location = 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;
}
Provider::ProviderRequest req{
dep, *mat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}};
auto res = Provider::resolve_cmake_with_translation(
req, *state, Provider::TranslationPolicy::RequireNative);
Void::Testing::expect_eq(res ? std::string{} : res.error().message(), std::string{});
Void::Testing::expect(res.has_value() && res->executed_natively &&
res->audit.is_supported());
const auto hash = Provider::compute_provider_input_hash(req);
const auto exe = tmp / "prov" / ("translate_tb2_cm_" + hash.substr(0, 16)) /
"native-build" / "profiles" / "debug" / "out" / "bin" / "b2_app";
Platform::ProcessRequest rr;
rr.executable = exe;
auto out = Platform::run_supervised(rr);
Void::Testing::expect(out.has_value() && out->succeeded());
if (out) {
Void::Testing::expect_eq(out->stdout_data, std::string{"cm_gen=77\n"});
}
}
// 2. CMake negative checks: side-effect-only .util target AND out-of-tree OUTPUT MUST fail
// RequireNative!
{
const auto bad_util_src = tmp / "cm_bad_util";
write_file(bad_util_src / "CMakeLists.txt", R"cmake(
cmake_minimum_required(VERSION 3.20)
project(tb2_bad_util LANGUAGES CXX)
add_custom_target(side_effect COMMAND ${CMAKE_COMMAND} -E echo side_effect_only)
add_library(b2_u_lib STATIC src/lib.cpp)
add_dependencies(b2_u_lib side_effect)
)cmake");
write_file(bad_util_src / "src" / "lib.cpp", "int b2_u() { return 1; }\n");
DependencyRecord bdep;
bdep.name = "tb2_bad_u";
bdep.source_kind = DependencySourceKind::Path;
bdep.location = bad_util_src.string();
bdep.builder = "cmake";
auto bmat =
Package::materialize_dependency_source(bdep, {tmp / "cache", tmp.path(), false, {}});
Void::Testing::expect(bmat.has_value());
if (bmat) {
Provider::ProviderRequest breq{
bdep, *bmat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}};
auto bad = Provider::resolve_cmake_with_translation(
breq, *state, Provider::TranslationPolicy::RequireNative);
Void::Testing::expect(!bad.has_value());
}
const auto bad_oot_src = tmp / "cm_bad_oot";
const auto outside_file = tmp / "outside_generated.hpp";
write_file(bad_oot_src / "CMakeLists.txt",
"cmake_minimum_required(VERSION 3.20)\nproject(tb2_bad_oot LANGUAGES CXX)\n"
"add_custom_command(OUTPUT \"" +
outside_file.string() + "\" COMMAND ${CMAKE_COMMAND} -E touch \"" +
outside_file.string() +
"\")\n"
"add_library(b2_oot_lib STATIC src/lib.cpp \"" +
outside_file.string() + "\")\n");
write_file(bad_oot_src / "src" / "lib.cpp", "int b2_oot() { return 1; }\n");
DependencyRecord odep;
odep.name = "tb2_bad_oot";
odep.source_kind = DependencySourceKind::Path;
odep.location = bad_oot_src.string();
odep.builder = "cmake";
auto omat =
Package::materialize_dependency_source(odep, {tmp / "cache", tmp.path(), false, {}});
Void::Testing::expect(omat.has_value());
if (omat) {
Provider::ProviderRequest oreq{
odep, *omat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}};
auto ocfg = Provider::configure_cmake_for_translation(oreq, tmp / "oot_cfg");
Void::Testing::expect(ocfg.has_value());
auto oaudit = Provider::audit_cmake_codemodel(tmp / "oot_cfg");
Void::Testing::expect(oaudit.has_value() && !oaudit->is_supported());
}
}
// 3. Meson hermetic custom_target (generated header + generated .cpp) under RequireNative,
// plus negative rejection on Meson run_target.
if (Platform::resolve_executable("meson").has_value()) {
const auto m_src = tmp / "meson_gen_native";
write_file(m_src / "meson.build", R"meson(
project('tb2_meson', 'cpp')
gen_hdr = custom_target('gen_hdr',
output: 'gen_num.hpp',
command: ['/bin/sh', '-c', 'printf "#pragma once\n#define M_GEN_NUM 80\n" > "$1"', '--', '@OUTPUT@'])
gen_cpp = custom_target('gen_cpp',
output: 'gen_num.cpp',
command: ['/bin/sh', '-c', 'printf "int m_gen_extra() { return 8; }\n" > "$1"', '--', '@OUTPUT@'])
lib = static_library('mgenlib', ['src/gen.cpp', gen_hdr, gen_cpp])
executable('mgen_app', ['src/main.cpp', gen_hdr], link_with: lib)
)meson");
write_file(m_src / "src" / "gen.cpp",
"#include \"gen_num.hpp\"\nint m_gen_extra();\n"
"int m_gen_fn() { return M_GEN_NUM + m_gen_extra(); }\n");
write_file(m_src / "src" / "main.cpp",
"#include \"gen_num.hpp\"\n#include <iostream>\n"
"int m_gen_fn();\n"
"int main() { std::cout << \"m_gen=\" << m_gen_fn() << '\\n'; return 0; }\n");
DependencyRecord mdep;
mdep.name = "tb2_me";
mdep.source_kind = DependencySourceKind::Path;
mdep.location = m_src.string();
mdep.builder = "meson";
auto mat =
Package::materialize_dependency_source(mdep, {tmp / "cache", tmp.path(), false, {}});
Void::Testing::expect(mat.has_value());
if (!mat) {
return;
}
Provider::ProviderRequest req{
mdep, *mat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}};
auto res = Provider::resolve_meson_with_translation(
req, *state, Provider::TranslationPolicy::RequireNative);
Void::Testing::expect_eq(res ? std::string{} : res.error().message(), std::string{});
Void::Testing::expect(res.has_value() && res->executed_natively &&
res->audit.is_supported());
const auto hash = Provider::compute_provider_input_hash(req);
const auto exe = tmp / "prov" / ("translate_meson_tb2_me_" + hash.substr(0, 16)) /
"native-build" / "profiles" / "debug" / "out" / "bin" / "mgen_app";
Platform::ProcessRequest rr;
rr.executable = exe;
auto out = Platform::run_supervised(rr);
Void::Testing::expect(out.has_value() && out->succeeded());
if (out) {
Void::Testing::expect_eq(out->stdout_data, std::string{"m_gen=88\n"});
}
const auto run_src = tmp / "meson_run_tgt";
write_file(run_src / "meson.build", R"meson(
project('tb2_m_run', 'cpp')
run_target('do_run', command: ['echo', 'hi'])
static_library('mrunlib', ['src/a.cpp'])
)meson");
write_file(run_src / "src" / "a.cpp", "int m_run_a() { return 1; }\n");
DependencyRecord rdep;
rdep.name = "tb2_m_run";
rdep.source_kind = DependencySourceKind::Path;
rdep.location = run_src.string();
rdep.builder = "meson";
auto rmat =
Package::materialize_dependency_source(rdep, {tmp / "cache", tmp.path(), false, {}});
Void::Testing::expect(rmat.has_value());
if (rmat) {
Provider::ProviderRequest rreq{
rdep, *rmat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}};
auto rstrict = Provider::resolve_meson_with_translation(
rreq, *state, Provider::TranslationPolicy::RequireNative);
Void::Testing::expect(!rstrict.has_value());
}
}
}
// === Track B3: Foreign CMake C++20 CXX_MODULES native translation & cross-target import ===
VOID_TEST(FullV1Tests, track_b3_foreign_cmake_cxx20_modules_native_translation) {
Void::FileSystem::TempDir tmp{"vbs_track_b3_"};
auto state = State::StateStore::open(tmp / "state");
Void::Testing::expect(state.has_value());
if (!state) {
return;
}
auto verify_for_family = [&](CompilerFamily family, std::string_view label) {
auto ctx = default_profiles().resolve("debug", family, Toolchain::host_os_name(),
Toolchain::host_architecture_name());
auto tc = Toolchain::discover_and_probe(ctx, tmp / ("probes_" + std::string{label}));
Void::Testing::expect(tc.has_value());
if (!tc || !tc->supports_p1689_scan) {
return;
}
const auto cm_src = tmp / ("cm_mods_" + std::string{label});
write_file(cm_src / "src" / "math_mod.cppm",
"export module vbs.trackb3.math;\n"
"export int b3_mul7(int x) { return x * 7; }\n");
write_file(cm_src / "src" / "app.cpp",
"import vbs.trackb3.math;\n#include <iostream>\n"
"int main() { std::cout << b3_mul7(6) << '\\n'; return 0; }\n");
write_file(cm_src / "CMakeLists.txt", R"cmake(
cmake_minimum_required(VERSION 3.28)
project(tb3_mods LANGUAGES CXX)
add_library(mod_math STATIC)
target_sources(mod_math PUBLIC FILE_SET CXX_MODULES FILES src/math_mod.cppm)
target_compile_features(mod_math PUBLIC cxx_std_20)
add_executable(mod_app src/app.cpp)
target_link_libraries(mod_app PRIVATE mod_math)
target_compile_features(mod_app PRIVATE cxx_std_20)
)cmake");
DependencyRecord dep;
dep.name = std::string{"tb3_cm_"} + std::string{label};
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;
}
Provider::ProviderRequest req{
dep, *mat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}};
auto res = Provider::resolve_cmake_with_translation(
req, *state, Provider::TranslationPolicy::RequireNative);
Void::Testing::expect_eq(res ? std::string{} : res.error().message(), std::string{});
Void::Testing::expect(res.has_value() && res->executed_natively &&
res->audit.is_supported());
if (!res) {
return;
}
const auto hash = Provider::compute_provider_input_hash(req);
const auto mod_exe = tmp / "prov" / ("translate_" + dep.name + "_" + hash.substr(0, 16)) /
"native-build" / "profiles" / "debug" / "out" / "bin" / "mod_app";
Platform::ProcessRequest rr;
rr.executable = mod_exe;
auto out = Platform::run_supervised(rr);
Void::Testing::expect(out.has_value() && out->succeeded());
if (out) {
Void::Testing::expect_eq(out->stdout_data, std::string{"42\n"});
}
// Verify cross-target / imported BMI propagation: a native VBS executable importing
// `vbs.trackb3.math` from the translated CMake module library!
const auto iface_it = res->exported.targets.find(dep.name + "::mod_math");
Void::Testing::expect(iface_it != res->exported.targets.end());
if (iface_it != res->exported.targets.end()) {
Void::Testing::expect(iface_it->second.module_bmis.contains("vbs.trackb3.math"));
const auto cons_root = tmp / ("vbs_cons_" + std::string{label});
const auto cons_build = tmp / ("vbs_cons_build_" + std::string{label});
write_file(cons_root / "src" / "cons.cpp",
"import vbs.trackb3.math;\n#include <iostream>\n"
"int main() { std::cout << (b3_mul7(7) + 1) << '\\n'; return 0; }\n");
Graph::ProjectDescription cdesc;
cdesc.profile = ctx;
TargetRecord capp;
capp.name = "vbs_mod_consumer";
capp.kind = TargetKind::Executable;
capp.cxx_standard = CxxStandard::Cxx20;
capp.sources.push_back({SourceKind::File, "src/cons.cpp"});
capp.links.push_back({LinkKind::Imported, "mod_math", dep.name, Visibility::Private});
cdesc.targets.push_back(capp);
Graph::GraphLowerOptions gopts{cons_root, cons_build, nullptr, res->exported.targets,
32768};
auto cgraph = Graph::lower_project_graph(cdesc, *tc, gopts);
Void::Testing::expect_eq(cgraph ? std::string{} : cgraph.error().message(),
std::string{});
Void::Testing::expect(cgraph.has_value());
if (cgraph) {
auto cexec = Execution::execute_graph(*cgraph, *state);
Void::Testing::expect(cexec.has_value() && cexec->succeeded);
Platform::ProcessRequest cr;
cr.executable =
cons_build / "profiles" / "debug" / "out" / "bin" / "vbs_mod_consumer";
auto cout = Platform::run_supervised(cr);
Void::Testing::expect(cout.has_value() && cout->succeeded());
if (cout) {
Void::Testing::expect_eq(cout->stdout_data, std::string{"50\n"});
}
}
}
};
if (Platform::resolve_executable("g++").has_value()) {
verify_for_family(CompilerFamily::Gcc, "gcc16");
}
if (Platform::resolve_executable("clang++").has_value()) {
verify_for_family(CompilerFamily::Clang, "clang23");
}
}
// === IDE Integration: `build.cpp` CompDB indexing + `vbs ide generate` & `vbs ide query` ===
VOID_TEST(FullV1Tests, ide_integration_compdb_build_cpp_and_editor_configs_end_to_end) {
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_ide_"};
const auto proj = tmp / "ide_proj";
const auto bdir = tmp / "ide_build";
auto run_vbs = [&](std::vector<std::string> args) {
Platform::ProcessRequest req;
req.executable = vbs_bin;
req.arguments = std::move(args);
req.timeout = std::chrono::seconds{120};
return Platform::run_supervised(req);
};
// 1. Scaffold a C++26 project via `vbs init`.
auto r_init = run_vbs({"init", "--dir", proj.string(), "--name", "ide_demo"});
Void::Testing::expect(r_init.has_value() && r_init->succeeded());
// 2. Generate all IDE configs (`--editor all`) BEFORE any full build has run.
auto r_gen = run_vbs({"ide", "generate", "--project", proj.string(), "--build-dir",
bdir.string(), "--editor", "all"});
Void::Testing::expect_eq(
r_gen ? (r_gen->succeeded() ? std::string{} : (r_gen->stdout_data + r_gen->stderr_data))
: r_gen.error().message(),
std::string{});
Void::Testing::expect(r_gen.has_value() && r_gen->succeeded());
// Check every generated file exists and every JSON file parses strictly.
Void::Testing::expect(std::filesystem::exists(proj / ".clangd"));
Void::Testing::expect(std::filesystem::exists(proj / ".idea" / "customTargets.xml"));
for (const auto &json_file : {proj / ".vscode" / "tasks.json", proj / ".vscode" / "launch.json",
proj / ".vscode" / "settings.json", proj / ".zed" / "tasks.json",
proj / ".zed" / "debug.json"}) {
Void::Testing::expect(std::filesystem::exists(json_file));
auto content = Void::FileSystem::read_file(json_file);
Void::Testing::expect(content.has_value());
if (content) {
auto parsed = Void::Json::Strict::parse(*content);
Void::Testing::expect(parsed.has_value());
}
}
// 3. Non-destructive overwrite preservation without `--force`, and overwrite with `--force`.
write_file(proj / ".clangd", "# user-customized clangd\n");
auto r_keep = run_vbs({"ide", "generate", "--project", proj.string(), "--build-dir",
bdir.string(), "--editor", "clangd"});
Void::Testing::expect(r_keep.has_value() && r_keep->succeeded());
Void::Testing::expect_eq(Void::FileSystem::read_file(proj / ".clangd").value_or(""),
std::string{"# user-customized clangd\n"});
auto r_force = run_vbs({"ide", "generate", "--project", proj.string(), "--build-dir",
bdir.string(), "--editor", "clangd", "--force"});
Void::Testing::expect(r_force.has_value() && r_force->succeeded());
const auto refreshed_clangd = Void::FileSystem::read_file(proj / ".clangd").value_or("");
Void::Testing::expect(refreshed_clangd.find("CompilationDatabase:") != std::string::npos);
Void::Testing::expect(refreshed_clangd.find("-freflection") != std::string::npos);
// 4. Verify `compile_commands.json` contains a real, valid compiler invocation for `build.cpp`
// and syntax-check `build.cpp` using that exact CompDB entry!
const auto compdb_text = Void::FileSystem::read_file(bdir / "compile_commands.json");
Void::Testing::expect(compdb_text.has_value());
if (compdb_text) {
auto parsed_db = Void::Json::Strict::parse(*compdb_text);
Void::Testing::expect(parsed_db.has_value());
bool checked_build_cpp = false;
if (parsed_db) {
if (const auto *arr =
std::get_if<Void::Json::Strict::Value::Array>(&parsed_db->value)) {
for (const auto &ev : *arr) {
const auto *eo = std::get_if<Void::Json::Strict::Value::Object>(&ev.value);
if (!eo) {
continue;
}
const auto fit = eo->find("file");
const auto ait = eo->find("arguments");
if (fit == eo->end() || ait == eo->end()) {
continue;
}
const auto *fs = std::get_if<std::string>(&fit->second.value);
const auto *aarr =
std::get_if<Void::Json::Strict::Value::Array>(&ait->second.value);
if (!fs || !aarr || std::filesystem::path{*fs}.filename() != "build.cpp") {
continue;
}
checked_build_cpp = true;
std::vector<std::string> argv;
for (const auto &av : *aarr) {
if (const auto *as = std::get_if<std::string>(&av.value)) {
argv.push_back(*as);
}
}
Void::Testing::expect(!argv.empty());
Void::Testing::expect(std::ranges::contains(argv, std::string{"-std=c++26"}));
Platform::ProcessRequest check_req;
check_req.executable = argv.front();
for (std::size_t i = 1; i < argv.size(); ++i) {
if (argv[i] == "-c") {
check_req.arguments.push_back("-fsyntax-only");
} else if (argv[i] == "-o" && i + 1 < argv.size()) {
++i;
} else {
check_req.arguments.push_back(argv[i]);
}
}
check_req.timeout = std::chrono::seconds{30};
auto syntax_ok = Platform::run_supervised(check_req);
Void::Testing::expect(syntax_ok.has_value() && syntax_ok->succeeded());
}
}
}
Void::Testing::expect(checked_build_cpp);
}
// 5. Verify `vbs ide query` emits valid JSON workspace & target metadata.
auto r_query =
run_vbs({"ide", "query", "--project", proj.string(), "--build-dir", bdir.string()});
Void::Testing::expect(r_query.has_value() && r_query->succeeded());
if (r_query) {
auto pq = Void::Json::Strict::parse(r_query->stdout_data);
Void::Testing::expect(pq.has_value());
Void::Testing::expect(r_query->stdout_data.find("\"ide_demo\"") != std::string::npos);
Void::Testing::expect(r_query->stdout_data.find("\"ide_demo_lib\"") != std::string::npos);
Void::Testing::expect(r_query->stdout_data.find("\"ide_demo_tests\"") != std::string::npos);
Void::Testing::expect(r_query->stdout_data.find("\"compdb_path\"") != std::string::npos);
Void::Testing::expect(r_query->stdout_data.find("\"sdk_include_dir\"") !=
std::string::npos);
}
}