feat: add Plan 20 Slice 2A Meson native translation, DX CLI (init/clean/doctor/graph/--native-foreign), and expansion roadmap
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 7s

This commit is contained in:
faumaray committed 2026-11-27 06:14:48 +03:00
1 parent d3d2666965
commit fe0d1a6483
12 files changed
+1317 -41

No files matched your search

+400 -13
View File
@@ -15,6 +15,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/SelfHost/TestRegistryGen.hpp>
#include <Void/Build/Snapshot/Snapshot.hpp>
#include <Void/Build/State/StateStore.hpp>
@@ -496,6 +497,7 @@ struct BuildCmdOptions {
bool no_cache{false};
bool locked{false};
bool offline{false};
bool native_foreign{false};
};
int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
@@ -695,16 +697,34 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
build_root / ".vbs" / "providers",
Provider::ProviderMode::FullBuild,
{}};
auto exp = Provider::resolve_foreign_provider(preq);
if (!exp) {
std::cerr << "vbs: " << exp.error().message() << '\n';
return 1;
}
Void::Log::info("Provider", "[{}] Imported {} target(s) from '{}' ({})",
prof_name, exp->targets.size(), effective_dep.name,
exp->from_cache ? "cached" : "built");
for (const auto &[k, v] : exp->targets) {
imported_targets[k] = v;
if (opts.native_foreign &&
(effective_dep.builder == "cmake" || effective_dep.builder == "meson")) {
auto tr = Provider::resolve_foreign_with_translation(
preq, *state, Provider::TranslationPolicy::FallbackToForeignBuild);
if (!tr) {
std::cerr << "vbs: " << tr.error().message() << '\n';
return 1;
}
Void::Log::info("Provider", "[{}] Imported {} target(s) from '{}' ({})",
prof_name, tr->exported.targets.size(), effective_dep.name,
tr->executed_natively
? "native-translated"
: (tr->exported.from_cache ? "cached" : "built"));
for (const auto &[k, v] : tr->exported.targets) {
imported_targets[k] = v;
}
} else {
auto exp = Provider::resolve_foreign_provider(preq);
if (!exp) {
std::cerr << "vbs: " << exp.error().message() << '\n';
return 1;
}
Void::Log::info("Provider", "[{}] Imported {} target(s) from '{}' ({})",
prof_name, exp->targets.size(), effective_dep.name,
exp->from_cache ? "cached" : "built");
for (const auto &[k, v] : exp->targets) {
imported_targets[k] = v;
}
}
}
}
@@ -1353,6 +1373,318 @@ int execute_deps_command(std::string_view sub, const DepsCmdOptions &opts) {
return 0;
}
struct InitCmdOptions {
std::string dir_arg;
std::optional<std::string> name_arg;
bool library{false};
bool with_toml{false};
bool force{false};
};
int execute_init_command(const InitCmdOptions &opts) {
std::error_code ec;
const std::filesystem::path target_dir = std::filesystem::path{opts.dir_arg}.lexically_normal();
std::filesystem::create_directories(target_dir, ec);
if (ec) {
std::cerr << "vbs init: cannot create directory '" << target_dir.string()
<< "': " << ec.message() << '\n';
return 1;
}
const auto canon = std::filesystem::weakly_canonical(target_dir, ec);
std::string raw_name =
(opts.name_arg && !opts.name_arg->empty()) ? *opts.name_arg : canon.filename().string();
if (raw_name.empty()) {
raw_name = "app";
}
std::string ident;
for (const char c : raw_name) {
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') ||
c == '_') {
ident.push_back(c);
} else if (c == '-' || c == ' ') {
ident.push_back('_');
}
}
if (ident.empty() || (ident.front() >= '0' && ident.front() <= '9')) {
ident = "vbs_" + ident;
}
const auto build_cpp = target_dir / "build.cpp";
if (!opts.force && std::filesystem::exists(build_cpp, ec)) {
std::cerr << "vbs init: '" << build_cpp.string()
<< "' already exists (pass --force to overwrite)\n";
return 2;
}
auto write_checked = [&](const std::filesystem::path &p, std::string_view content) -> bool {
auto w = Platform::atomic_write_file(p, content, false);
if (!w) {
std::cerr << "vbs init: failed writing '" << p.string() << "': " << w.error().message()
<< '\n';
return false;
}
return true;
};
std::string build_src =
"#include <Void/Build.hpp>\n\nvoid build(Void::Build::Project &project) {\n";
if (opts.with_toml) {
build_src += " project.dependencies_file(\"vbs.deps.toml\");\n\n";
}
if (opts.library) {
build_src += " auto lib = project.static_library(\"" + raw_name +
"\");\n"
" lib.cxx_standard(Void::Build::CxxStandard::Cxx26)\n"
" .sources({\"src/" +
ident +
".cpp\"})\n"
" .include_directory(\"include\", Void::Build::Visibility::Public)\n"
" .install(\"lib\");\n"
" project.install_directory(\"include\", \"include\");\n\n"
" auto t = project.test(\"" +
ident +
"_tests\");\n"
" t.cxx_standard(Void::Build::CxxStandard::Cxx26)\n"
" .sources({\"tests/test_main.cpp\"})\n"
" .link(lib);\n";
} else {
build_src += " auto lib = project.static_library(\"" + ident +
"_lib\");\n"
" lib.cxx_standard(Void::Build::CxxStandard::Cxx26)\n"
" .sources({\"src/" +
ident +
".cpp\"})\n"
" .include_directory(\"include\", Void::Build::Visibility::Public);\n\n"
" auto app = project.executable(\"" +
raw_name +
"\");\n"
" app.cxx_standard(Void::Build::CxxStandard::Cxx26)\n"
" .sources({\"src/main.cpp\"})\n"
" .link(lib)\n"
" .install(\"bin\");\n\n"
" auto t = project.test(\"" +
ident +
"_tests\");\n"
" t.cxx_standard(Void::Build::CxxStandard::Cxx26)\n"
" .sources({\"tests/test_main.cpp\"})\n"
" .link(lib);\n";
}
build_src += "}\n";
if (!write_checked(build_cpp, build_src)) {
return 1;
}
if (!write_checked(target_dir / "include" / (ident + ".hpp"),
"#pragma once\n\nnamespace " + ident + " {\nint answer();\n}\n")) {
return 1;
}
if (!write_checked(target_dir / "src" / (ident + ".cpp"),
"#include \"" + ident + ".hpp\"\n\nnamespace " + ident +
" {\nint answer() { return 42; }\n}\n")) {
return 1;
}
if (!opts.library) {
if (!write_checked(target_dir / "src" / "main.cpp",
"#include \"" + ident +
".hpp\"\n#include <iostream>\n\nint main() {\n std::cout << \"" +
raw_name + ": answer=\" << " + ident +
"::answer() << '\\n';\n return 0;\n}\n")) {
return 1;
}
}
if (!write_checked(target_dir / "tests" / "test_main.cpp",
"#include \"" + ident + ".hpp\"\n\nint main() { return " + ident +
"::answer() == 42 ? 0 : 1; }\n")) {
return 1;
}
if (!write_checked(target_dir / ".gitignore",
"/build/\n/.vbs/\n/compile_commands.json\n.env\n")) {
return 1;
}
if (opts.with_toml) {
if (!write_checked(target_dir / "vbs.deps.toml",
"# Declarative dependency manifest for " + raw_name + "\n")) {
return 1;
}
}
Void::Log::info("Init", "Initialized VBS {} project '{}' in '{}'",
opts.library ? "library" : "application", raw_name, target_dir.string());
std::cout << "initialized " << raw_name << " in " << target_dir.string() << '\n';
return 0;
}
struct CleanCmdOptions {
std::string build_arg;
bool clean_all{false};
};
int execute_clean_command(const CleanCmdOptions &opts) {
const std::filesystem::path build_root{opts.build_arg};
std::error_code ec;
if (!std::filesystem::exists(build_root, ec)) {
std::cout << "clean: nothing to remove in " << build_root.string() << '\n';
return 0;
}
if (opts.clean_all) {
Void::Log::info("Clean", "Removing entire build directory '{}'...", build_root.string());
std::filesystem::remove_all(build_root, ec);
if (ec) {
std::cerr << "vbs clean: failed removing '" << build_root.string()
<< "': " << ec.message() << '\n';
return 1;
}
std::cout << "cleaned " << build_root.string() << " (all)\n";
return 0;
}
const auto profiles_dir = build_root / "profiles";
std::size_t removed = 0;
if (std::filesystem::exists(profiles_dir, ec)) {
Void::Log::info("Clean", "Removing profile outputs under '{}' (preserving .vbs/cache)...",
profiles_dir.string());
removed += static_cast<std::size_t>(std::filesystem::remove_all(profiles_dir, ec));
}
const auto compdb = build_root / "compile_commands.json";
if (std::filesystem::exists(compdb, ec) || std::filesystem::is_symlink(compdb, ec)) {
std::filesystem::remove(compdb, ec);
++removed;
}
std::cout << "cleaned " << removed << " path(s) in " << build_root.string()
<< " (preserved .vbs cache/state)\n";
return 0;
}
int execute_doctor_command() {
std::cout << "VoidBuildSystem " << Bootstrap::version << " (" << Bootstrap::os << "/"
<< Bootstrap::architecture << ")\n";
auto check_tool = [](std::string_view label, const char *bin, bool required) {
auto found = Platform::resolve_executable(bin);
std::cout << " " << (found ? "[ok] " : (required ? "[FAIL]" : "[opt] ")) << " " << label
<< ": " << (found ? found->string() : std::string{"not found"}) << '\n';
return found.has_value();
};
const bool has_gcc = check_tool("g++", "g++", true);
(void)check_tool("clang++", "clang++", false);
(void)check_tool("clang-scan-deps", "clang-scan-deps", false);
(void)check_tool("ar", "ar", true);
(void)check_tool("git", "git", false);
(void)check_tool("cmake", "cmake", false);
(void)check_tool("ninja", "ninja", false);
(void)check_tool("meson", "meson", false);
(void)check_tool("conan", "conan", false);
(void)check_tool("clang-format", "clang-format", false);
std::cout << " [ok] Void::Crypto built-in SHA-256: enabled\n";
std::cout << " [ok] Void::Archive built-in USTAR/PAX: enabled\n";
if (has_gcc) {
Void::FileSystem::TempDir tmp{"vbs_doc_"};
auto ctx =
default_profiles().resolve("debug", CompilerFamily::Gcc, Toolchain::host_os_name(),
Toolchain::host_architecture_name());
if (auto tc = Toolchain::discover_and_probe(ctx, tmp.path()); tc) {
std::cout << " [ok] GCC probe: " << tc->version_banner
<< " (c++26=" << (tc->supports_cxx26 ? "yes" : "no")
<< ", reflection=" << (tc->supports_reflection ? "yes" : "no")
<< ", p1689=" << (tc->supports_p1689_scan ? "yes" : "no") << ")\n";
}
}
return has_gcc ? 0 : 1;
}
struct GraphCmdOptions {
std::string project_arg;
std::optional<std::string> build_arg;
std::string profile_name{"debug"};
std::optional<std::string> compiler_arg;
std::string format{"dot"};
};
int execute_graph_command(const GraphCmdOptions &opts) {
if (opts.format != "dot" && opts.format != "json") {
std::cerr << "vbs graph: unsupported --format '" << opts.format
<< "' (expected 'dot' or 'json')\n";
return 2;
}
std::optional<CompilerFamily> compiler_override;
if (opts.compiler_arg) {
try {
compiler_override = parse_compiler(*opts.compiler_arg);
} catch (const std::exception &ex) {
std::cerr << "vbs graph: " << ex.what() << '\n';
return 2;
}
}
const std::filesystem::path project_root{opts.project_arg};
const std::filesystem::path build_root =
opts.build_arg ? std::filesystem::path{*opts.build_arg} : (project_root / "build");
const auto fopts = make_frontend_opts(project_root, build_root, {});
auto compiled = Config::compile_descriptor(fopts);
if (!compiled) {
std::cerr << "vbs graph: " << compiled.error().message() << '\n';
return 1;
}
auto profs = Config::discover_profiles(*compiled, fopts);
if (!profs) {
std::cerr << "vbs graph: " << profs.error().message() << '\n';
return 1;
}
ProfileContext ctx;
try {
ctx = profs->resolve(opts.profile_name, compiler_override, Toolchain::host_os_name(),
Toolchain::host_architecture_name());
} catch (const std::exception &ex) {
std::cerr << "vbs graph: " << ex.what() << '\n';
return 2;
}
auto desc = Config::evaluate_project(*compiled, ctx, fopts);
if (!desc) {
std::cerr << "vbs graph: " << desc.error().message() << '\n';
return 1;
}
if (opts.format == "json") {
std::cout << "{\"profile\":" << Util::json_quote(desc->profile.name) << ",\"targets\":";
std::cout << Util::json_array(desc->targets, [](const TargetRecord &t) {
return "{\"name\":" + Util::json_quote(t.name) +
",\"kind\":" + Util::json_quote(target_kind_name(t.kind)) + ",\"links\":" +
Util::json_array(t.links,
[](const LinkRecord &l) {
return Util::json_quote(
l.kind == LinkKind::Imported
? (l.dependency + "::" + l.target)
: l.target);
}) +
'}';
});
std::cout << "}\n";
return 0;
}
std::cout << "digraph vbs_targets {\n";
std::cout << " rankdir=LR;\n";
for (const auto &t : desc->targets) {
std::cout << " " << Util::json_quote(t.name) << " [label="
<< Util::json_quote(t.name + "\n(" + std::string{target_kind_name(t.kind)} + ")")
<< "];\n";
}
for (const auto &t : desc->targets) {
for (const auto &pre : t.prerequisites) {
std::cout << " " << Util::json_quote(t.name) << " -> " << Util::json_quote(pre)
<< " [style=dashed];\n";
}
for (const auto &l : t.links) {
const std::string dst =
l.kind == LinkKind::Imported ? (l.dependency + "::" + l.target) : l.target;
std::cout << " " << Util::json_quote(t.name) << " -> " << Util::json_quote(dst)
<< ";\n";
}
}
std::cout << "}\n";
return 0;
}
} // namespace
int main(int argc, char **argv) {
@@ -1382,6 +1714,12 @@ int main(int argc, char **argv) {
GcCmdOptions gc_opts;
gc_opts.build_arg = (std::filesystem::path{cwd} / "build").string();
GenTestsCmdOptions gen_tests_opts;
InitCmdOptions init_opts;
init_opts.dir_arg = cwd;
CleanCmdOptions clean_opts;
clean_opts.build_arg = (std::filesystem::path{cwd} / "build").string();
GraphCmdOptions graph_opts;
graph_opts.project_arg = cwd;
auto add_log_flags = [&](Void::Argparse::Parser &p, bool allow_short_v = true) {
p.flag("--verbose", allow_short_v ? "-v" : "", "Enable verbose debug logs", verbose)
@@ -1402,7 +1740,10 @@ int main(int argc, char **argv) {
.option("--jobs", "-j", "Maximum parallel compilation/link jobs", build_opts.jobs_arg)
.flag("--locked", "", "Require existing up-to-date vbs.lock", build_opts.locked)
.flag("--offline", "", "Disallow network fetches", build_opts.offline)
.flag("--no-cache", "", "Bypass action cache reads", build_opts.no_cache);
.flag("--no-cache", "", "Bypass action cache reads", build_opts.no_cache)
.flag("--native-foreign", "",
"Translate supported CMake/Meson dependencies to native VBS actions (Plan 20)",
build_opts.native_foreign);
add_log_flags(p);
};
@@ -1536,6 +1877,39 @@ int main(int argc, char **argv) {
gen_tests_opts.out_arg);
add_log_flags(gen_tests_cmd);
auto &init_cmd =
root.subcommand("init", "Scaffold a new ready-to-build C++26 VoidBuildSystem project");
init_cmd.option_default("--dir", "-C", "Target project directory", init_opts.dir_arg, cwd)
.option("--name", "-n", "Project/target name (defaults to directory name)",
init_opts.name_arg)
.flag("--library", "", "Scaffold a static library project instead of an executable",
init_opts.library)
.flag("--with-toml", "", "Include a vbs.deps.toml dependency manifest", init_opts.with_toml)
.flag("--force", "", "Overwrite existing build.cpp if present", init_opts.force);
add_log_flags(init_cmd);
auto &clean_cmd =
root.subcommand("clean", "Remove generated profile build artifacts (preserving cache)");
clean_cmd
.option_default("--build-dir", "-B", "Build directory", clean_opts.build_arg,
clean_opts.build_arg)
.flag("--all", "", "Also delete .vbs cache, snapshots, and state store",
clean_opts.clean_all);
add_log_flags(clean_cmd);
auto &doctor_cmd =
root.subcommand("doctor", "Check host compilers, tools, and VBS runtime capabilities");
add_log_flags(doctor_cmd);
auto &graph_cmd =
root.subcommand("graph", "Export target dependency graph in Graphviz DOT or JSON format");
graph_cmd.option_default("--project", "-C", "Project directory", graph_opts.project_arg, cwd)
.option("--build-dir", "-B", "Build output directory", graph_opts.build_arg)
.option_default("--profile", "-p", "Profile name", graph_opts.profile_name, "debug")
.option("--compiler", "", "Override compiler family (gcc|clang)", graph_opts.compiler_arg)
.option_default("--format", "-f", "Output format (dot|json)", graph_opts.format, "dot");
add_log_flags(graph_cmd);
const auto parsed = root.parse_detailed(argc, argv);
if (parsed.is_help()) {
std::cout << parsed.message;
@@ -1560,8 +1934,9 @@ int main(int argc, char **argv) {
const std::string_view cmd = parsed.matched_command_path.front();
const bool machine_quiet_default =
(cmd == "describe") || (cmd == "compdb" && parsed.matched_command_path.size() >= 2 &&
parsed.matched_command_path[1] == "show");
(cmd == "describe") || (cmd == "graph") || (cmd == "doctor") ||
(cmd == "compdb" && parsed.matched_command_path.size() >= 2 &&
parsed.matched_command_path[1] == "show");
const Void::Log::Level log_level =
verbose ? Void::Log::Level::Debug
: ((quiet || machine_quiet_default) ? Void::Log::Level::Warning
@@ -1607,6 +1982,18 @@ int main(int argc, char **argv) {
if (cmd == "gen-tests") {
return execute_gen_tests_command(gen_tests_opts);
}
if (cmd == "init") {
return execute_init_command(init_opts);
}
if (cmd == "clean") {
return execute_clean_command(clean_opts);
}
if (cmd == "doctor") {
return execute_doctor_command();
}
if (cmd == "graph") {
return execute_graph_command(graph_opts);
}
std::cerr << "vbs: unhandled subcommand '" << cmd << "'\n";
return 2;