feat: lifecycle commands and native compiler caching (G1, G7)
VoidBuildSystem CI / 1 · Requirements (push) Successful in 3s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 2m30s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 2m40s
VoidBuildSystem CI / 2A · Linux build (coverage) (push) Successful in 3m4s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 4m16s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 5m48s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 4m18s
VoidBuildSystem CI / 3A · Linux test (coverage) (push) Failing after 1m20s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 29s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 16s
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 18s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Failing after 6m4s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Failing after 6m28s
VoidBuildSystem CI / 4A2 · VBS installers (linux target) (push) Skipped
VoidBuildSystem CI / 4A2 · VBS installers (windows target) (push) Skipped
VoidBuildSystem CI / 5 · Release (push) Skipped

G1 (start):
- vbs run builds an executable target, passes program args through `--`,
  inherits stdio via Void::Process (interactive programs keep the terminal)
  and returns the program's exit code; Windows targets run under Wine.
- vbs metadata emits a schema-versioned workspace document built with
  Void::Json::Strict: roots, profile/compiler, targets (sources, includes,
  links, labels, install rules), dependencies and the lockfile revision.
- vbs why walks the target graph root -> target, or explains a dependency
  and the targets linking it.
- vbs add NAME[@RANGE] / vbs remove NAME edit vbs.deps.toml (canonical,
  comment-preserving block editing), validate ranges with
  Void::Semver::parse_range and refresh vbs.lock via the resolver.
- --frozen implies --locked --offline for build/test/run.

G7 (native caching):
- --native-cache off|auto|ccache|sccache (or VBS_NATIVE_CACHE) prepends
  ccache/sccache to compile actions only; the wrapper and real compiler are
  part of the action key, archive/link actions are untouched, and
  vbs doctor reports availability.

VoidLibrary reuse: Void::Process (spawn with inherited stdio),
Void::Json::Strict (metadata document), Void::Str (trim/split/prefix),
Void::Semver (range validation), plus the existing SDK helpers
(target_kind_name/visibility_name) instead of local duplicates.

Verified: lifecycle_run_metadata_why_and_manifest_editing,
native_cache_wrapper_is_lowered_into_compile_commands and
native_cache_wraps_compile_actions pass; CLI contracts pass; clang-format
clean.
This commit is contained in:
faumaray committed 2026-12-06 19:20:39 +03:00
1 parent a12470c072
commit 76f1e2a48c
11 files changed
+1240 -2

No files matched your search

+9
View File
@@ -43,6 +43,15 @@ check_process(2 "" "invalid value 'bazel' for '--from'" migrate --from bazel)
check_process(2 "" "invalid value 'bogus' for '--template'" init --template bogus)
check_process(0 "--template" "" init --help)
check_process(0 "--export" "" presets --help)
check_process(0 "Usage: vbs run " "" run --help)
check_process(0 "Usage: vbs metadata " "" metadata --help)
check_process(0 "Usage: vbs why " "" why --help)
check_process(0 "Usage: vbs add " "" add --help)
check_process(0 "Usage: vbs remove " "" remove --help)
check_process(0 "--frozen" "" build --help)
check_process(0 "--native-cache" "" build --help)
check_process(2 "" "unsupported --native-cache" build --native-cache bogus)
check_process(2 "" "invalid version range" add fmt@bad --no-lock)
check_process(2 "" "invalid --repeat mode" test --repeat bogus)
check_process(2 "" "invalid --repeat count" test --repeat until-pass:0)
check_process(2 "" "invalid --retry value" test --retry 99)
+229
View File
@@ -4347,3 +4347,232 @@ void build(Void::Build::Project &p) {
Void::Testing::expect(preset.build_dir.has_value());
}
}
// === Lifecycle CLI: run, metadata, why, manifest add/remove, frozen ===
VOID_TEST(FullV1Tests, lifecycle_run_metadata_why_and_manifest_editing) {
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_lifecycle_"};
const auto proj = tmp / "proj";
const auto bdir = tmp / "build";
write_file(proj / "build.cpp", R"cpp(#include <Void/Build.hpp>
void build(Void::Build::Project &p) {
auto lib = p.static_library("demo").sources({"src/demo.cpp"});
p.executable("app").sources({"src/main.cpp"}).link(lib);
}
)cpp");
write_file(proj / "src" / "demo.cpp", "int demo() { return 1; }\n");
write_file(proj / "src" / "main.cpp", R"cpp(#include <cstdlib>
#include <iostream>
int demo();
int main(int argc, char **argv) {
for (int i = 1; i < argc; ++i) {
std::cout << "arg:" << argv[i] << "\n";
}
return demo() + (argc > 1 ? std::atoi(argv[1]) : 0);
}
)cpp");
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{600};
return Platform::run_supervised(req);
};
// `vbs run` builds and runs the target with the program arguments and exit code.
auto ran = run_vbs({"run", "--project", proj.string(), "--build-dir", bdir.string(),
"--target", "app", "--jobs", "2", "6", "hello"});
Void::Testing::expect(ran.has_value());
if (ran) {
Void::Testing::expect_eq(ran->exit_code, 7); // demo() == 1, argv[1] == 6
Void::Testing::expect(ran->stdout_data.find("arg:hello") != std::string::npos);
}
// `vbs metadata` is a versioned JSON document built with Void::Json::Strict.
auto metadata = run_vbs({"metadata", "--project", proj.string(), "--build-dir",
bdir.string()});
Void::Testing::expect(metadata.has_value() && metadata->succeeded());
if (metadata) {
auto parsed = Void::Json::Strict::parse(metadata->stdout_data);
Void::Testing::require(parsed.has_value());
const auto *root = std::get_if<Void::Json::Strict::Value::Object>(&parsed->value);
Void::Testing::require(root != nullptr);
const auto *targets = std::get_if<Void::Json::Strict::Value::Array>(
&root->at("targets").value);
Void::Testing::require(targets != nullptr);
Void::Testing::expect_eq(targets->size(), std::size_t{2});
bool saw_app = false;
for (const auto &target : *targets) {
const auto *object = std::get_if<Void::Json::Strict::Value::Object>(&target.value);
if (object == nullptr) {
continue;
}
const auto *kind = std::get_if<std::string>(&object->at("kind").value);
const auto *name = std::get_if<std::string>(&object->at("name").value);
if (name != nullptr && *name == "app" && kind != nullptr && *kind == "executable") {
saw_app = true;
}
}
Void::Testing::expect(saw_app);
}
// `vbs why` walks the target dependency graph.
auto why_lib = run_vbs({"why", "demo", "--project", proj.string(), "--build-dir",
bdir.string()});
Void::Testing::expect(why_lib.has_value() && why_lib->succeeded());
if (why_lib) {
Void::Testing::expect(why_lib->stdout_data.find("app -> demo") != std::string::npos);
}
auto why_app = run_vbs({"why", "app", "--project", proj.string(), "--build-dir",
bdir.string()});
Void::Testing::expect(why_app.has_value() && why_app->succeeded());
auto why_missing = run_vbs({"why", "nope", "--project", proj.string(), "--build-dir",
bdir.string()});
Void::Testing::expect(why_missing.has_value() && why_missing->exit_code == 1);
// `vbs add` / `vbs remove` edit the manifest (canonically, with semver validation).
const auto manifest = tmp / "vbs.deps.toml";
auto added = run_vbs({"add", "zlib@^1.3", "--manifest", manifest.string(), "--no-lock"});
Void::Testing::expect(added.has_value() && added->succeeded());
auto manifest_text = Void::FileSystem::read_file(manifest);
Void::Testing::require(manifest_text.has_value());
Void::Testing::expect(manifest_text->find("[dependencies.zlib]") != std::string::npos);
Void::Testing::expect(manifest_text->find("version = \"^1.3\"") != std::string::npos);
auto duplicate = run_vbs({"add", "zlib", "--manifest", manifest.string(), "--no-lock"});
Void::Testing::expect(duplicate.has_value() && duplicate->exit_code != 0);
auto bad_version = run_vbs({"add", "fmt@not a range", "--manifest", manifest.string(),
"--no-lock"});
Void::Testing::expect(bad_version.has_value() && bad_version->exit_code == 2);
auto removed = run_vbs({"remove", "zlib", "--manifest", manifest.string(), "--no-lock"});
Void::Testing::expect(removed.has_value() && removed->succeeded());
auto removed_text = Void::FileSystem::read_file(manifest);
Void::Testing::require(removed_text.has_value());
Void::Testing::expect(removed_text->find("[dependencies.zlib]") == std::string::npos);
// `--frozen` implies the locked + offline combination.
auto frozen = run_vbs({"build", "--project", proj.string(), "--build-dir", bdir.string(),
"--frozen", "--jobs", "2"});
Void::Testing::expect(frozen.has_value() && frozen->succeeded());
}
// === Native compiler caching (ccache/sccache) ===
VOID_TEST(FullV1Tests, native_cache_wraps_compile_actions) {
const auto vbs_bin = locate_vbs_binary();
Void::Testing::expect(!vbs_bin.empty() && std::filesystem::exists(vbs_bin));
const auto ccache = Platform::resolve_executable("ccache");
const auto sccache = Platform::resolve_executable("sccache");
if (vbs_bin.empty() || (!ccache && !sccache)) {
return; // The tool is not installed; the CI image ships ccache.
}
const std::string wrapper = (ccache ? *ccache : *sccache).string();
const std::string tool_name = ccache ? "ccache" : "sccache";
Void::FileSystem::TempDir tmp{"vbs_native_cache_"};
const auto proj = tmp / "proj";
write_file(proj / "build.cpp", R"cpp(#include <Void/Build.hpp>
void build(Void::Build::Project &p) {
p.executable("app").sources({"src/main.cpp"});
}
)cpp");
write_file(proj / "src" / "main.cpp", "int main() { return 0; }\n");
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{600};
return Platform::run_supervised(req);
};
const auto compile_command_starts_with = [&](const std::filesystem::path &build_dir,
std::string_view prefix) {
auto explained = run_vbs({"explain", "--project", proj.string(), "--build-dir",
build_dir.string(), "--format", "json"});
if (!explained || !explained->succeeded()) {
return false;
}
auto parsed = Void::Json::Strict::parse(explained->stdout_data);
if (!parsed) {
return false;
}
const auto *root = std::get_if<Void::Json::Strict::Value::Object>(&parsed->value);
if (root == nullptr) {
return false;
}
const auto *actions =
std::get_if<Void::Json::Strict::Value::Array>(&root->at("actions").value);
if (actions == nullptr) {
return false;
}
for (const auto &action : *actions) {
const auto *object = std::get_if<Void::Json::Strict::Value::Object>(&action.value);
if (object == nullptr) {
continue;
}
const auto *label = std::get_if<std::string>(&object->at("label").value);
const auto *command = std::get_if<std::string>(&object->at("command").value);
if (label != nullptr && command != nullptr &&
label->starts_with("Compile") && command->starts_with(prefix)) {
return true;
}
}
return false;
};
// With the native cache enabled the compile action runs through the wrapper.
auto cached = run_vbs({"build", "--project", proj.string(), "--build-dir",
(tmp / "build-cache").string(), "--jobs", "2", "--native-cache",
tool_name});
Void::Testing::expect(cached.has_value() && cached->succeeded());
Void::Testing::expect(compile_command_starts_with(tmp / "build-cache", wrapper));
// Disabled: the compile action starts with the compiler itself.
auto plain = run_vbs({"build", "--project", proj.string(), "--build-dir",
(tmp / "build-plain").string(), "--jobs", "2", "--native-cache",
"off"});
Void::Testing::expect(plain.has_value() && plain->succeeded());
Void::Testing::expect(!compile_command_starts_with(tmp / "build-plain", wrapper));
auto bad = run_vbs({"build", "--project", proj.string(), "--build-dir",
(tmp / "build-bad").string(), "--native-cache", "bogus"});
Void::Testing::expect(bad.has_value() && bad->exit_code == 2);
}
// === Native cache lowering (deterministic, no ccache installation required) ===
VOID_TEST(FullV1Tests, native_cache_wrapper_is_lowered_into_compile_commands) {
Toolchain::ToolchainCapabilities caps;
caps.family = CompilerFamily::Gcc;
caps.cxx_compiler = "/usr/bin/g++";
caps.c_compiler = "/usr/bin/gcc";
caps.archiver = "/usr/bin/ar";
caps.supports_cxx26 = true;
caps.supports_file_prefix_map = true;
Toolchain::CompileRequest request;
request.source_file = "/tmp/vbs_native_cache_probe.cpp";
request.output_object = "/tmp/vbs_native_cache_probe.o";
request.cxx_standard = CxxStandard::Cxx26;
request.compile_only = true;
request.nondeterministic = true; // Skip -frandom-seed for a stable assertion target.
auto plain = Toolchain::lower_compile_command(caps, request);
Void::Testing::require(plain.has_value());
Void::Testing::expect(plain->executable == caps.cxx_compiler);
Void::Testing::require(!plain->arguments.empty());
Void::Testing::expect(plain->arguments.front() != caps.cxx_compiler.string());
caps.native_cache_executable = "/usr/bin/ccache";
auto cached = Toolchain::lower_compile_command(caps, request);
Void::Testing::require(cached.has_value());
Void::Testing::expect(cached->executable == std::filesystem::path{"/usr/bin/ccache"});
Void::Testing::require(!cached->arguments.empty());
Void::Testing::expect_eq(cached->arguments.front(), std::string{"/usr/bin/g++"});
// The original compiler flags still follow the wrapped compiler.
Void::Testing::expect(std::ranges::find(cached->arguments, std::string{"-std=c++26"}) !=
cached->arguments.end());
}