diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index be32bb6..ff65fa8 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -2,7 +2,7 @@ Updated: 2026-12-03 Branch: main -Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B1–B3) + Track E1 + `vbs ide` & `build.cpp` CompDB integration + Track D1/D2 + Track E2 + Track D3 SBOM (Docker GCC 16) + Track D3 Ed25519 signing primitives & trusted-key enforcement (OpenSSL-gated crypto) + Track E3 daemon core & bounded describe + Track C1 Linux platform split complete +Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B1–B3) + Track E1 + `vbs ide` & `build.cpp` CompDB integration + Track D1/D2 + Track E2 + Track D3 SBOM (Docker GCC 16) + Track D3 Ed25519 signing primitives & trusted-key enforcement (OpenSSL-gated crypto) + Track E3 daemon core, bounded describe & build-serving + Track C1 Linux platform split complete ## Completed delivery waves @@ -80,9 +80,13 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B - `vbs publish --signing-key FILE` signs the canonical `vbs-package-v1` message; `vbs-registry` stores and serves `X-Package-Signature`/`X-Package-Public-Key` metadata with strict 128/64 hex validation; `vbs build|test --trusted-public-key HEX` (repeatable) fails closed before package extraction unless the signature verifies against a trusted key. - Added `Void::Build::Provenance::verify_trusted_package_signature` (`include/Void/Build/Provenance/Verification.hpp`, `src/Provenance/Verification.cpp`) with explicit `Verified`/`Unsigned`/`UntrustedKey`/`InvalidSignature` decisions, plus `tests/SignatureEnforcementTests.cpp` and registry metadata/signed-E2E coverage. +- **Wave 16 (Track E3 Daemon Build-Serving)**: + - Added the `build` daemon request in `src/Daemon/Daemon.cpp`: graph evaluation is shared with `describe` (`evaluate_project_graph`), then executed in-process through `Execution::execute_graph` against the daemon's warm `StateStore`. The response is bounded JSON (`ok`, `profile`, `targets`, `actions`, `executed`, `cached`, `failed`, `diagnostic`, `failed_actions`). Requests accept `profile`, `compiler`, `targets` (≤ 64 bounded strings) and `jobs` (0–256). + - Wired `vbs daemon build [--profile] [--target]... [--jobs]` in `src/Main.cpp` with a long-running client timeout, plus `Daemon.build_executes_project_graph_and_reuses_cache` (cold build creates the binary, second request is fully cached, invalid `targets` type rejected) and a CLI help contract. Dependency materialization stays with `vbs build`/`vbs deps`; the daemon builds the already-describable graph. + ## Remaining future scope -- **Post-v1 Expansion Roadmap ([21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md) & [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md))**: Live `conan` CLI verification (Track B3), Track C (macOS/Windows ports + dual-profile cross-compilation), Track D3 signing (SBOM, Ed25519 primitives, and trusted-key enforcement done; binary-variant signing and key distribution remain), Track E3 (daemon core and bounded `describe` done; build-serving requests and external editor plugins remain), and Track E4 (`Void::Net`/`Void::Sqlite` alignment) remain planned scope. +- **Post-v1 Expansion Roadmap ([21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md) & [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md))**: Live `conan` CLI verification (Track B3), Track C (macOS/Windows ports + dual-profile cross-compilation), Track D3 signing (SBOM, Ed25519 primitives, and trusted-key enforcement done; binary-variant signing and key distribution remain), Track E3 (daemon core, bounded `describe` and build-serving done; external editor plugins and dependency materialization inside the daemon remain), and Track E4 (`Void::Net`/`Void::Sqlite` alignment) remain planned scope. ## Environment notes & upstream boundaries diff --git a/docs/agent-workflow/TASKS.md b/docs/agent-workflow/TASKS.md index fc51e8a..9c5a530 100644 --- a/docs/agent-workflow/TASKS.md +++ b/docs/agent-workflow/TASKS.md @@ -22,4 +22,5 @@ Base HEAD: `fe0d1a6` | Wave 13 (Track D3 SBOM + Ed25519 signing primitives) | Deterministic SPDX 2.3 / CycloneDX 1.5 SBOM from `vbs.lock` packages + `BuildGraph` outputs; `vbs build\|test --sbom FILE --sbom-format spdx\|cyclonedx`; Ed25519 detached-signature primitives (`Void::Build::Provenance::Signing`: 0600 seed generation, public-key derivation, canonical package message, sign/verify) capability-gated on `Void::Crypto`'s OpenSSL backend | SBOM COMPLETE & VERIFIED (Docker GCC 16, 8/8 CTest suites); signing primitives IMPLEMENTED & VERIFIED in `dev cpp-gcc` (OpenSSL-gated: 4/4 `SigningTests`; OpenSSL-backed round-trip pending an OpenSSL-enabled environment) | `include/Void/Build/Provenance/Sbom.hpp`, `src/Provenance/Sbom.cpp`, `include/Void/Build/Provenance/Signing.hpp`, `src/Provenance/Signing.cpp`, `tests/SigningTests.cpp`, `src/Main.cpp`, `tests/FullV1Tests.cpp`, docs | | Wave 14 (Track E3 daemon core + bounded `describe` + Track C1 platform split) | Unix-socket `vbs daemon` holding warm `StateStore`/`InotifyWatcher` with `ping/status/gc/recover/describe/shutdown`, CLI + tests; bounded `describe` graph summary (`target_names` ≤ 128 × 200 bytes, `profile` ≤ 128 bytes, 10 s eval timeout); `src/Platform/Linux/` backend split with `HostOs` boundary; CMake 4.5 `@cmake_cxx_std@` feature-carrier translation fix | COMPLETE & VERIFIED (GCC 16.2, pinned VoidLibrary `3e25405`, 8/8 CTest suites; `Daemon` suite 6/6 under `dev cpp-gcc`; live `vbs daemon describe` CLI round-trip verified in `vbs_cli_contract`) | `include/Void/Build/Daemon/Daemon.hpp`, `src/Daemon/Daemon.cpp`, `tests/DaemonTests.cpp`, `include/Void/Build/Platform/Host.hpp`, `src/Platform/Linux/`, `src/Main.cpp`, `src/Provider/Translator.cpp`, `tests/CliContracts.cmake`, docs | | Wave 15 (Track D3 signed-package enforcement) | Optional `signature`/`public_key` in `ReleaseRecord`/`SolvedPackage`/`LockedSourceEntry` + `vbs.lock`; `vbs publish --signing-key`; registry signature metadata storage/serving with hex validation; `vbs build\|test --trusted-public-key` fail-closed enforcement before extraction; `Provenance::verify_trusted_package_signature` trust policy | COMPLETE & VERIFIED (GCC 16.2, pinned VoidLibrary `3e25405`, 8/8 CTest; OpenSSL-enabled Signing 4/4, SignatureEnforcement 3/3, signed registry E2E) | `include/Void/Build/Provenance/Verification.hpp`, `src/Provenance/Verification.cpp`, `include/Void/Build/Package/{Solver,Lockfile,RegistryClient}.hpp`, `src/Package/{Solver,Lockfile,RegistryClient}.cpp`, `registry/`, `src/Main.cpp`, `tests/{SignatureEnforcementTests.cpp,RegistryTests.cpp}`, docs | -| Future (Plan 20 Slice 3 / Tracks C, D3 binary signing, E3 daemon build serving, E4, live `conan`) | Live `conan` CLI verification; macOS/Windows/cross-compile; binary-variant signing and key distribution; daemon build serving; `Void::Net`/`Void::Sqlite` alignment | PLANNED (unimplemented) | [21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md), [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md) | +| Wave 16 (Track E3 daemon build serving) | In-process daemon `build` request reusing graph lowering + `Execution::execute_graph` against the warm `StateStore`; bounded `profile`/`targets`/`jobs`; `vbs daemon build` CLI; cache-reuse test | COMPLETE & VERIFIED (GCC 16.2; Daemon suite 7/7) | `src/Daemon/Daemon.cpp`, `include/Void/Build/Daemon/Daemon.hpp`, `src/Main.cpp`, `tests/DaemonTests.cpp`, `tests/CliContracts.cmake`, docs | +| Future (Plan 20 Slice 3 / Tracks C, D3 binary signing, E3 daemon dependency materialization/editor plugins, E4, live `conan`) | Live `conan` CLI verification; macOS/Windows/cross-compile; binary-variant signing and key distribution; daemon-side dependency materialization and editor plugins; `Void::Net`/`Void::Sqlite` alignment | PLANNED (unimplemented) | [21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md), [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md) | diff --git a/docs/agent-workflow/VERIFICATION.md b/docs/agent-workflow/VERIFICATION.md index d1458bf..1068da8 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -295,6 +295,23 @@ dev cpp-gcc -c build/openssl/bin/vbs_registry_tests --filter cli_publish_deps_re closed (and the unsigned locked package also fails closed with `not signed by a trusted key`). - `clang-format --dry-run --Werror` passes on all changed/new C++ files. +## Track E3 Daemon Build-Serving (2026-12-03, `dev cpp-gcc`) + +```sh +dev cpp-gcc -c cmake --build build/bootstrap --parallel 8 +dev cpp-gcc -c build/bootstrap/bin/vbs_v1_tests --suite Daemon --no-color +dev cpp-gcc -c ctest --test-dir build/bootstrap --output-on-failure +``` + +- Build: exit 0. Daemon suite: **7 / 7 passed** in 8.88 s, including + `build_executes_project_graph_and_reuses_cache` (cold request executes the compile+link graph and + produces `profiles/debug/out/bin/app`; the second request reports `executed=0` with cached + actions; a non-array `targets` value is rejected). +- Full CTest: **8 / 8 passed** in 190.28 s (`vbs_v1_tests` 68.93 s, `vbs_selfhost_tests` 91.47 s, + `vbs_cli_contract` 7.44 s including `vbs daemon build --help`). +- `clang-format --dry-run --Werror` passes after formatting `src/Daemon/Daemon.cpp`, + `src/Main.cpp`, and `tests/DaemonTests.cpp`. + ## Limits and Unrun Checks 1. **HTTPS git fetch**: the host shell is proxy-restricted, but the Docker container could clone `https://git.faumaray.com/Void/VoidLibrary.git`; the pinned commit `3e254055e081a104f08df68dde39711bc7813518` was fetched directly for the verification above. A separate configure against the local `/home/faumaray/Projects/Library` checkout via `VBS_VOID_SOURCE_DIR` also succeeded (development-only override, checkout unmodified). diff --git a/docs/roadmap/21-expansion-roadmap.md b/docs/roadmap/21-expansion-roadmap.md index e90d20a..90ef827 100644 --- a/docs/roadmap/21-expansion-roadmap.md +++ b/docs/roadmap/21-expansion-roadmap.md @@ -73,7 +73,7 @@ flowchart LR | --- | --- | --- | | **E1 — Everyday CLI Ergonomics (Implemented in Wave 8)** | `vbs init` project scaffolding, `vbs clean`, `vbs doctor` environment diagnostics, `vbs graph --format dot|json`, and `vbs build --native-foreign`. | End-to-end CLI & integration tests passing in `vbs_cli_contract` and `vbs_v1_tests`. | | **E2 — Multi-Package Workspaces (`workspace.cpp`)** *(verified in Docker GCC 16)* | Shared root `vbs.lock` and `build/.vbs` CAS, `workspace_dependency()` cross-member native linking, and affected-member selection (`vbs build/test --member ` / `--changed-since `). | 3-package workspace fixture (shared library + app + tests) builds/tests with one root lockfile; member selection and `--changed-since` verified in `FullV1Tests.workspace_members_shared_build_and_member_selection`. | -| **E3 — IDE Config/Query & Background Daemon** | `build.cpp`/`build.profiles.cpp`/`build-support/` SDK entries in `compile_commands.json` + `vbs ide generate` (`.clangd`, `.vscode/`, `.zed/`, `.idea/customTargets.xml`) & `vbs ide query` (**Implemented & Verified in Wave 10**); Unix-socket daemon core holding a warm `StateStore` + project `DirectoryWatcher` with `vbs daemon run\|status\|stop\|gc\|recover\|describe` (**Implemented & Verified in Wave 14; bounded `describe` added in the post-v1 daemon follow-up**). `describe` returns a bounded graph summary (`target_names` ≤ 128 entries × 200 bytes, `profile` ≤ 128 bytes, 10 s evaluation timeout). Build-serving daemon requests and dedicated editor extensions remain planned. | `vbs ide` & `build.cpp` syntax-check verified in `FullV1Tests.cpp`; daemon lifecycle/status/gc/shutdown/describe verified in `DaemonTests.cpp` (6/6 under `dev cpp-gcc`); the live `vbs daemon describe` CLI round-trip is verified in `vbs_cli_contract`. | +| **E3 — IDE Config/Query & Background Daemon** | `build.cpp`/`build.profiles.cpp`/`build-support/` SDK entries in `compile_commands.json` + `vbs ide generate` (`.clangd`, `.vscode/`, `.zed/`, `.idea/customTargets.xml`) & `vbs ide query` (**Implemented & Verified in Wave 10**); Unix-socket daemon core holding a warm `StateStore` + project `DirectoryWatcher` with `vbs daemon run\|status\|stop\|gc\|recover\|describe` (**Implemented & Verified in Wave 14; bounded `describe` added in the post-v1 daemon follow-up**). `describe` returns a bounded graph summary (`target_names` ≤ 128 entries × 200 bytes, `profile` ≤ 128 bytes, 10 s evaluation timeout); `vbs daemon build` executes the lowered graph in-process against the warm state store with bounded `profile`/`targets`/`jobs` (dependency materialization stays with `vbs build`/`vbs deps`). Dedicated editor extensions remain planned. | `vbs ide` & `build.cpp` syntax-check verified in `FullV1Tests.cpp`; daemon lifecycle/status/gc/shutdown/describe verified in `DaemonTests.cpp` (6/6 under `dev cpp-gcc`); the live `vbs daemon describe` CLI round-trip is verified in `vbs_cli_contract`. | | **E4 — Transport & Storage Upstream Alignment** | Adopt `Void::Net` (`VL-004`/`VL-005`) and `Void::Sqlite` (`VL-011b`) when lightweight/bundled builds become available in minimal Nix toolchains, reducing VBS transport code further. | All `vbs_registry_tests` and `vbs_core_tests` pass on both minimal and full toolchains. | --- diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index e92757c..fb9892f 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +48,7 @@ constexpr auto kDescribeEvalTimeout = std::chrono::seconds{10}; constexpr std::size_t kMaxDescribeProfileBytes = 128U; constexpr std::size_t kMaxDescribeTargetNames = 128U; constexpr std::size_t kMaxDescribeTargetNameBytes = 200U; +constexpr std::size_t kMaxBuildTargets = 64U; Void::Result::Error make_error(Void::Result::ErrorKind kind, std::string message, int system_errno = 0) { @@ -326,39 +328,48 @@ Config::FrontendOptions make_frontend_options(const DaemonOptions &options) { return frontend; } -// Evaluates the project description in-process and lowers it to a bounded graph summary. -// Workspace roots are rejected explicitly: member selection belongs to the CLI. -std::string describe_project(const DaemonOptions &options, std::string_view profile_name, - std::optional compiler_override) { +struct EvaluatedProject { + ProfileContext context; + Graph::BuildGraph graph; +}; + +// Evaluates the project description in-process and lowers its graph. Workspace roots are +// rejected explicitly: member selection belongs to the CLI. +Void::Result::Result +evaluate_project_graph(const DaemonOptions &options, std::string_view profile_name, + std::optional compiler_override, std::string_view op) { if (Config::is_workspace_root(options.project_root)) { - return error_response("describe: workspace roots are not supported by the daemon yet"); + return std::unexpected{ + std::format("{}: workspace roots are not supported by the daemon yet", op)}; } const auto frontend = make_frontend_options(options); auto compiled = Config::compile_descriptor(frontend); if (!compiled) { - return error_response(std::format("describe: {}", compiled.error().format())); + return std::unexpected{std::format("{}: {}", op, compiled.error().format())}; } auto profiles = Config::discover_profiles(*compiled, frontend); if (!profiles) { - return error_response(std::format("describe: {}", profiles.error().format())); + return std::unexpected{std::format("{}: {}", op, profiles.error().format())}; } - ProfileContext context; + EvaluatedProject evaluated; try { - context = profiles->resolve(profile_name, compiler_override, Toolchain::host_os_name(), - Toolchain::host_architecture_name()); + evaluated.context = + profiles->resolve(profile_name, compiler_override, Toolchain::host_os_name(), + Toolchain::host_architecture_name()); } catch (const std::exception &ex) { - return error_response(std::format("describe: {}", ex.what())); + return std::unexpected{std::format("{}: {}", op, ex.what())}; } - auto description = Config::evaluate_project(*compiled, context, frontend); + auto description = Config::evaluate_project(*compiled, evaluated.context, frontend); if (!description) { - return error_response(std::format("describe: {}", description.error().format())); + return std::unexpected{std::format("{}: {}", op, description.error().format())}; } - auto toolchain = Toolchain::discover_and_probe(context, options.build_root / ".vbs" / "probes"); + auto toolchain = + Toolchain::discover_and_probe(evaluated.context, options.build_root / ".vbs" / "probes"); if (!toolchain) { - return error_response(std::format("describe: {}", toolchain.error().format())); + return std::unexpected{std::format("{}: {}", op, toolchain.error().format())}; } Graph::GraphLowerOptions lower_options; @@ -366,12 +377,71 @@ std::string describe_project(const DaemonOptions &options, std::string_view prof lower_options.build_root = options.build_root; auto graph = Graph::lower_project_graph(*description, *toolchain, lower_options); if (!graph) { - return error_response(std::format("describe: {}", graph.error().format())); + return std::unexpected{std::format("{}: {}", op, graph.error().format())}; + } + evaluated.graph = std::move(*graph); + return evaluated; +} + +// Bounded build-serving request: lowers the project graph and executes it in-process against the +// daemon's warm StateStore. Dependency materialization belongs to `vbs build`/`vbs deps`. +std::string build_project(const DaemonOptions &options, State::StateStore &state, + std::string_view profile_name, + std::optional compiler_override, + const std::vector &selected_targets, std::size_t jobs) { + auto evaluated = evaluate_project_graph(options, profile_name, compiler_override, "build"); + if (!evaluated) { + return error_response(evaluated.error()); } + Execution::ExecutionOptions exec_options; + exec_options.jobs = jobs; + exec_options.selected_targets = selected_targets; + auto report = Execution::execute_graph(evaluated->graph, state, exec_options); + if (!report) { + return error_response(std::format("build: {}", report.error().format())); + } + + JsonValue::Array failed_actions; + for (const auto &result : report->results) { + if (!result.succeeded) { + JsonValue::Object failure; + failure.emplace("action", JsonValue{result.action_id}); + failure.emplace("target", JsonValue{result.target_name}); + failure.emplace("error", JsonValue{result.error_message}); + failed_actions.emplace_back(std::move(failure)); + } + } + + JsonValue::Object object; + object.emplace("ok", JsonValue{report->succeeded}); + object.emplace("op", JsonValue{std::string{"build"}}); + object.emplace("profile", JsonValue{evaluated->context.name}); + object.emplace("targets", + JsonValue{static_cast(evaluated->graph.targets.size())}); + object.emplace("actions", + JsonValue{static_cast(evaluated->graph.actions.size())}); + object.emplace("executed", JsonValue{static_cast(report->executed_count)}); + object.emplace("cached", JsonValue{static_cast(report->cached_count)}); + object.emplace("failed", JsonValue{static_cast(report->failed_count)}); + object.emplace("diagnostic", JsonValue{report->diagnostic}); + object.emplace("failed_actions", JsonValue{std::move(failed_actions)}); + return serialize_response(JsonValue{std::move(object)}); +} + +// Lowers the project graph to a bounded summary without executing it. +std::string describe_project(const DaemonOptions &options, std::string_view profile_name, + std::optional compiler_override) { + auto evaluated = evaluate_project_graph(options, profile_name, compiler_override, "describe"); + if (!evaluated) { + return error_response(evaluated.error()); + } + const auto &graph = evaluated->graph; + const auto &context = evaluated->context; + std::vector target_names; - target_names.reserve(graph->targets.size()); - for (const auto &target : graph->targets) { + target_names.reserve(graph.targets.size()); + for (const auto &target : graph.targets) { target_names.push_back(target.name); } std::ranges::sort(target_names); @@ -395,8 +465,8 @@ std::string describe_project(const DaemonOptions &options, std::string_view prof object.emplace("ok", JsonValue{true}); object.emplace("op", JsonValue{std::string{"describe"}}); object.emplace("profile", JsonValue{context.name}); - object.emplace("targets", JsonValue{static_cast(graph->targets.size())}); - object.emplace("actions", JsonValue{static_cast(graph->actions.size())}); + object.emplace("targets", JsonValue{static_cast(graph.targets.size())}); + object.emplace("actions", JsonValue{static_cast(graph.actions.size())}); object.emplace("target_names", JsonValue{std::move(names_json)}); if (truncated) { object.emplace("target_names_truncated", JsonValue{true}); @@ -511,7 +581,7 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view if (*name == "status") { return {status_response(), false}; } - if (*name == "describe") { + if (*name == "describe" || *name == "build") { std::string profile_name{"debug"}; if (const auto entry = object->find("profile"); entry != object->end()) { const auto *value = std::get_if(&entry->second.value); @@ -538,7 +608,40 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view return {error_response(ex.what()), false}; } } - return {describe_project(options, profile_name, compiler_override), false}; + if (*name == "describe") { + return {describe_project(options, profile_name, compiler_override), false}; + } + + std::vector selected_targets; + if (const auto entry = object->find("targets"); entry != object->end()) { + const auto *array = std::get_if(&entry->second.value); + if (array == nullptr) { + return {error_response("\"targets\" must be an array of strings"), false}; + } + if (array->size() > kMaxBuildTargets) { + return {error_response("\"targets\" has too many entries"), false}; + } + for (const auto &item : *array) { + const auto *text = std::get_if(&item.value); + if (text == nullptr || text->empty() || + text->size() > kMaxDescribeTargetNameBytes) { + return {error_response("\"targets\" entries must be non-empty bounded strings"), + false}; + } + selected_targets.push_back(*text); + } + } + std::size_t jobs = 0; + if (const auto entry = object->find("jobs"); entry != object->end()) { + const auto *value = std::get_if(&entry->second.value); + if (value == nullptr || *value < 0 || *value > 256) { + return {error_response("\"jobs\" must be an integer in [0, 256]"), false}; + } + jobs = static_cast(*value); + } + return {build_project(options, state_store, profile_name, compiler_override, + selected_targets, jobs), + false}; } if (*name == "shutdown") { return {ok_response("shutdown"), true}; diff --git a/src/Main.cpp b/src/Main.cpp index 6cfccd2..b253dbe 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1580,6 +1580,8 @@ struct DaemonCmdOptions { std::optional build_arg; std::optional socket_arg; std::string profile_arg{"debug"}; + std::vector targets; + std::string jobs_arg{"0"}; std::string max_bytes_arg{"0"}; std::string max_requests_arg{"0"}; }; @@ -1659,6 +1661,22 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) { } request_json = std::format(R"({{"op":"describe","profile":{}}})", Util::json_quote(opts.profile_arg)); + } else if (sub == "build") { + std::size_t jobs = 0; + const auto [ptr, ec] = std::from_chars(opts.jobs_arg.data(), + opts.jobs_arg.data() + opts.jobs_arg.size(), jobs); + if (ec != std::errc{} || ptr != opts.jobs_arg.data() + opts.jobs_arg.size() || jobs > 256) { + std::cerr << "vbs daemon build: invalid --jobs value '" << opts.jobs_arg << "'\n"; + return 2; + } + if (opts.profile_arg.empty()) { + std::cerr << "vbs daemon build: --profile must not be empty\n"; + return 2; + } + const std::string targets_json = Util::json_array( + opts.targets, [](const std::string &target) { return Util::json_quote(target); }); + request_json = std::format(R"({{"op":"build","profile":{},"targets":{},"jobs":{}}})", + Util::json_quote(opts.profile_arg), targets_json, jobs); } else { std::cerr << "vbs daemon: unknown command '" << sub << "'\n"; return 2; @@ -1666,8 +1684,9 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) { // Describe evaluates the whole project graph (descriptor compile, toolchain probe, lowering), // which can exceed the 2 s default; the daemon bounds evaluation at 10 s. - const auto request_timeout = - sub == "describe" ? std::chrono::milliseconds{15000} : std::chrono::milliseconds{2000}; + const auto request_timeout = sub == "build" ? std::chrono::milliseconds{std::chrono::hours{1}} + : sub == "describe" ? std::chrono::milliseconds{15000} + : std::chrono::milliseconds{2000}; auto response = Daemon::request(socket_path, request_json, request_timeout); if (!response) { std::cerr << "vbs daemon: " << response.error().message() << '\n'; @@ -2600,6 +2619,13 @@ int main(int argc, char **argv) { configure_daemon_common(daemon_describe_cmd); daemon_describe_cmd.option_default("--profile", "-p", "Profile to evaluate", daemon_opts.profile_arg, "debug"); + auto &daemon_build_cmd = daemon_cmd.subcommand("build", "Build a project graph via the daemon"); + configure_daemon_common(daemon_build_cmd); + daemon_build_cmd + .option_default("--profile", "-p", "Profile to build", daemon_opts.profile_arg, "debug") + .option_many("--target", "-t", "Target to build", daemon_opts.targets) + .option_default("--jobs", "-j", "Maximum parallel jobs (0 = hardware concurrency)", + daemon_opts.jobs_arg, "0"); const auto parsed = root.parse_detailed(argc, argv); if (parsed.is_help()) { diff --git a/tests/CliContracts.cmake b/tests/CliContracts.cmake index 2752c0e..d921e7d 100644 --- a/tests/CliContracts.cmake +++ b/tests/CliContracts.cmake @@ -48,6 +48,7 @@ check_process(2 "" "--registry, --name, and --version are required" publish) check_process(0 "Usage: vbs daemon .*Commands:.*run.*status.*stop.*recover.*gc.*describe" "" daemon --help) check_process(0 "Usage: vbs daemon run " "" daemon run --help) check_process(0 "Usage: vbs daemon describe .*--profile" "" daemon describe --help) +check_process(0 "Usage: vbs daemon build .*--profile.*--target.*--jobs" "" daemon build --help) check_process(2 "" "missing subcommand for 'vbs daemon'" daemon) # Daemon-backed describe contract: start `vbs daemon run`, query the bounded graph summary over diff --git a/tests/DaemonTests.cpp b/tests/DaemonTests.cpp index 3cef14f..131fa56 100644 --- a/tests/DaemonTests.cpp +++ b/tests/DaemonTests.cpp @@ -310,6 +310,64 @@ void build(Void::Build::Project &project) { Void::Testing::expect(!std::filesystem::exists(socket)); } +VOID_TEST(Daemon, build_executes_project_graph_and_reuses_cache) { + auto temp = Void::FileSystem::TempDir::open("vbs_daemon_"); + Void::Testing::require(temp.has_value()); + const auto options = make_options(temp->path()); + + { + std::ofstream descriptor{options.project_root / "build.cpp"}; + descriptor << R"cpp(#include + +void build(Void::Build::Project &project) { + auto app = project.executable("app"); + app.sources({"main.cpp"}); +} +)cpp"; + Void::Testing::require(descriptor.good()); + } + { + std::ofstream source{options.project_root / "main.cpp"}; + source << "int main() { return 0; }\n"; + Void::Testing::require(source.good()); + } + + auto server = Void::Build::Daemon::DaemonServer::create(options); + Void::Testing::require(server.has_value()); + const auto socket = server->socket_path(); + + Void::Result::Result run_result; + std::jthread worker{[&] { run_result = server->run(); }}; + Void::Testing::require(wait_for_path(socket, std::chrono::seconds{5})); + + auto build = request_object(socket, R"({"op":"build"})"); + Void::Testing::require(build.has_value()); + Void::Testing::expect(bool_field(*build, "ok")); + Void::Testing::expect_eq(str_field(*build, "op"), std::string{"build"}); + Void::Testing::expect(int_field(*build, "executed") >= 1); + Void::Testing::expect(int_field(*build, "failed") == 0); + Void::Testing::expect( + std::filesystem::exists(options.build_root / "profiles" / "debug" / "out" / "bin" / "app")); + + auto cached = request_object(socket, R"({"op":"build"})"); + Void::Testing::require(cached.has_value()); + Void::Testing::expect(bool_field(*cached, "ok")); + Void::Testing::expect(int_field(*cached, "executed") == 0); + Void::Testing::expect(int_field(*cached, "cached") >= 1); + + auto bad_targets = request_object(socket, R"({"op":"build","targets":"app"})"); + Void::Testing::require(bad_targets.has_value()); + Void::Testing::expect(!bool_field(*bad_targets, "ok", true)); + Void::Testing::expect(str_field(*bad_targets, "error").find("must be an array") != + std::string::npos); + + auto shutdown = Void::Build::Daemon::request(socket, R"({"op":"shutdown"})"); + Void::Testing::expect(shutdown.has_value()); + worker.join(); + Void::Testing::expect(run_result.has_value()); + Void::Testing::expect(!std::filesystem::exists(socket)); +} + VOID_TEST(Daemon, describe_empty_project_reports_zero_targets) { auto temp = Void::FileSystem::TempDir::open("vbs_daemon_"); Void::Testing::require(temp.has_value());