feat(daemon): materialize project dependencies for daemon build requests
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 58s

This commit is contained in:
faumaray committed 2026-12-03 19:32:06 +03:00
1 parent 42172a24f8
commit f5c0c9f09d
12 files changed
+580 -287

No files matched your search

+1
View File
@@ -54,6 +54,7 @@ add_library(VoidBuild_Core STATIC
src/Package/Archive.cpp
src/Package/Fetch.cpp
src/Package/RegistryClient.cpp
src/Package/Resolver.cpp
src/Provider/Provider.cpp
src/Provider/Translator.cpp
src/Install/Installer.cpp
+1
View File
@@ -42,6 +42,7 @@ void build(Void::Build::Project &project) {
"src/Package/Archive.cpp",
"src/Package/Fetch.cpp",
"src/Package/RegistryClient.cpp",
"src/Package/Resolver.cpp",
"src/Provider/Provider.cpp",
"src/Provider/Translator.cpp",
"src/Install/Installer.cpp",
+5 -1
View File
@@ -89,9 +89,13 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B
- Verified against upstream `main` exported to `/tmp/opencode/vl-main` **without OpenSSL**: `Signing` 4/4 (the crypto round-trip actually runs, 151.8 ms) and `SignatureEnforcement` 3/3.
- The VoidLibrary pin was then bumped to `0002e74a7da94a756f55a4a5574d20b77736c185` (upstream `main`, containing #52) in [CMakeLists.txt](../../CMakeLists.txt) and [build.cpp](../../build.cpp), with the pin assertions in `tests/DescribeContracts.cmake` and `tests/ExampleContexts.cpp` updated.
- **Wave 18 (Track E3 Daemon-Side Dependency Materialization)**:
- Extracted the CLI's dependency resolution/materialization pipeline into the reusable library API `Package::resolve_and_materialize_dependencies` (`include/Void/Build/Package/Resolver.hpp`, `src/Package/Resolver.cpp`) with explicit `ResolveOptions` (project/build root, pinned lock, offline/upgrade, trusted keys, registry URL/auth); `src/Main.cpp` is now a thin adapter over it.
- The daemon `build` request now loads TOML dependency manifests, merges declared dependencies, resolves and materializes them (pinned lock + registry environment), imports native/CMake/Meson/Conan provider targets, and lowers the graph with those imported interfaces before executing. Responses report `dependencies`. Added `Daemon.build_materializes_path_dependency` (path dependency materialized, imported, linked, and built over the socket).
## 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, trusted-key enforcement, the #52 built-in-backend capability probe, and the VoidLibrary pin bump to `0002e74` 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.
- **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, trusted-key enforcement, the #52 built-in-backend capability probe, and the VoidLibrary pin bump to `0002e74` done; binary-variant signing and key distribution remain), Track E3 (daemon core, bounded `describe`, build-serving, and dependency materialization done; external editor plugins remain), and Track E4 (`Void::Net`/`Void::Sqlite` alignment) remain planned scope.
## Environment notes & upstream boundaries
+2 -1
View File
@@ -24,4 +24,5 @@ Base HEAD: `fe0d1a6`
| 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 |
| 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 |
| Wave 17 (VoidLibrary #52 follow-up + pin bump) | `signing_available()` probes the real Ed25519 capability instead of `has_openssl_backend()`; VoidLibrary pin bumped to `0002e74a7da94a756f55a4a5574d20b77736c185` (contains #52) and pin assertions updated | COMPLETE & VERIFIED (GCC 16.2, fresh remote fetch of the pin, no OpenSSL: Signing 4/4 crypto path, SignatureEnforcement 3/3, full CTest 8/8) | `CMakeLists.txt`, `build.cpp`, `src/Provenance/Signing.cpp`, `include/Void/Build/Provenance/Signing.hpp`, `tests/{SigningTests.cpp,ExampleContexts.cpp,DescribeContracts.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) |
| Wave 18 (Track E3 daemon dependency materialization) | Extracted `Package::resolve_and_materialize_dependencies` (`Resolver.hpp/.cpp`) from the CLI; daemon `build` now merges TOML deps, resolves/materializes with the pinned lock, imports provider targets, lowers with imported interfaces, and reports `dependencies` | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 8/8, full CTest 8/8) | `include/Void/Build/Package/Resolver.hpp`, `src/Package/Resolver.cpp`, `src/Main.cpp`, `src/Daemon/Daemon.cpp`, `tests/DaemonTests.cpp`, build lists, docs |
| Future (Plan 20 Slice 3 / Tracks C, D3 binary signing, E3 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) |
+19
View File
@@ -351,6 +351,25 @@ dev cpp-gcc -c ctest --test-dir build/pinned --output-on-failure
`vbs_selfhost_tests` 92.98 s, `vbs_registry_tests` 10.99 s, `vbs_cli_contract` 7.61 s).
- `clang-format --dry-run --Werror` passes on `build.cpp` and `tests/ExampleContexts.cpp`.
## Track E3 Daemon Dependency Materialization (GCC 16.2, pin `0002e74`)
```sh
dev cpp-gcc -c cmake --build build/pinned --parallel 8
dev cpp-gcc -c build/pinned/bin/vbs_v1_tests --suite Daemon --no-color
dev cpp-gcc -c ctest --test-dir build/pinned --output-on-failure
```
- Build: exit 0. Daemon suite: **8 / 8 passed** in 13.11 s, including
`build_materializes_path_dependency`: the daemon loads the project's `build.cpp`, materializes the
declared path dependency through the extracted `Package::resolve_and_materialize_dependencies`,
imports its native provider target, lowers the graph with the imported interface, executes the
compile+link, and reports `dependencies >= 1` with the output binary present.
- Full CTest: **8 / 8 passed** in 197.95 s (`vbs_v1_tests` 74.23 s, `vbs_selfhost_tests` 93.24 s,
`vbs_registry_tests` 10.70 s, `vbs_cli_contract` 7.51 s).
- `clang-format --dry-run --Werror` passes on `src/Daemon/Daemon.cpp`, `src/Main.cpp`,
`src/Package/Resolver.cpp`, `include/Void/Build/Package/Resolver.hpp`, 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).
+1 -1
View File
@@ -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 <pkg>` / `--changed-since <ref>`). | 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); `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`. |
| **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`, including daemon-side dependency resolution/materialization and provider import via `Package::resolve_and_materialize_dependencies`. 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. |
---
+43
View File
@@ -0,0 +1,43 @@
#pragma once
#include <Void/Build.hpp>
#include <Void/Build/Package/Fetch.hpp>
#include <Void/Build/Package/Lockfile.hpp>
#include <Void/Build/Package/RegistryClient.hpp>
#include <Void/Build/Package/Solver.hpp>
#include <Void/Build/Package/Toml.hpp>
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <filesystem>
#include <optional>
#include <string>
#include <utility>
#include <vector>
namespace Void::Build::Package {
struct ResolvedDepMaterialization {
LockContextRecord lock_context;
std::vector<std::pair<DependencyRecord, MaterializedSource>> materialized;
};
struct ResolveOptions {
std::filesystem::path project_root;
std::filesystem::path build_root;
std::optional<PinnedLock> pinned_lock;
bool offline{false};
bool allow_upgrade{false};
std::vector<std::string> trusted_public_keys;
std::string default_registry_url; // Fallback when a dependency has no .registry()
RegistryAuth registry_auth;
};
// Shared dependency resolution + live registry fetching + safe archive extraction + lock context
// builder for `vbs deps resolve|update`, `vbs build`, `vbs test`, and the daemon.
[[nodiscard]] Void::Result::Result<ResolvedDepMaterialization, Void::Result::Error>
resolve_and_materialize_dependencies(const ProfileContext &ctx,
const std::vector<NormalizedDependency> &merged_deps,
const ResolveOptions &options);
} // namespace Void::Build::Package
+1
View File
@@ -95,6 +95,7 @@ add_vbs_selfhost_native(Project &project, const VbsSelfHostConfig &config) {
"src/Package/Archive.cpp",
"src/Package/Fetch.cpp",
"src/Package/RegistryClient.cpp",
"src/Package/Resolver.cpp",
"src/Provider/Provider.cpp",
"src/Provider/Translator.cpp",
"src/Install/Installer.cpp",
+136 -17
View File
@@ -5,9 +5,14 @@
#include <Void/Build/Config/Frontend.hpp>
#include <Void/Build/Execution/Scheduler.hpp>
#include <Void/Build/Graph/Graph.hpp>
#include <Void/Build/Package/Lockfile.hpp>
#include <Void/Build/Package/Resolver.hpp>
#include <Void/Build/Package/Toml.hpp>
#include <Void/Build/Provider/Provider.hpp>
#include <Void/Build/State/StateStore.hpp>
#include <Void/Build/Toolchain/Driver.hpp>
#include <Void/Build/Watch/Watcher.hpp>
#include <Void/Configuration/Env.hpp>
#include <Void/Data/StrictJson.hpp>
#include <Void/Functional/Error.hpp>
@@ -330,7 +335,8 @@ Config::FrontendOptions make_frontend_options(const DaemonOptions &options) {
struct EvaluatedProject {
ProfileContext context;
Graph::BuildGraph graph;
Graph::ProjectDescription description;
Toolchain::ToolchainCapabilities toolchain;
};
// Evaluates the project description in-process and lowers its graph. Workspace roots are
@@ -372,19 +378,118 @@ evaluate_project_graph(const DaemonOptions &options, std::string_view profile_na
return std::unexpected{std::format("{}: {}", op, toolchain.error().format())};
}
Graph::GraphLowerOptions lower_options;
lower_options.project_root = options.project_root;
lower_options.build_root = options.build_root;
auto graph = Graph::lower_project_graph(*description, *toolchain, lower_options);
if (!graph) {
return std::unexpected{std::format("{}: {}", op, graph.error().format())};
}
evaluated.graph = std::move(*graph);
evaluated.description = std::move(*description);
evaluated.toolchain = std::move(*toolchain);
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`.
Void::Result::Result<Graph::BuildGraph, std::string>
lower_graph(const DaemonOptions &options, const EvaluatedProject &evaluated,
std::map<std::string, Graph::ImportedTargetInterface, std::less<>> imported_targets,
std::string_view op) {
Graph::GraphLowerOptions lower_options;
lower_options.project_root = options.project_root;
lower_options.build_root = options.build_root;
lower_options.imported_targets = std::move(imported_targets);
auto graph =
Graph::lower_project_graph(evaluated.description, evaluated.toolchain, lower_options);
if (!graph) {
return std::unexpected{std::format("{}: {}", op, graph.error().format())};
}
return std::move(*graph);
}
// Resolves, materializes, and imports the project's declared dependencies into typed target
// interfaces. Returns the number of materialized sources.
Void::Result::Result<std::size_t, std::string> materialize_project_dependencies(
const DaemonOptions &options, State::StateStore &state, const EvaluatedProject &evaluated,
std::size_t jobs,
std::map<std::string, Graph::ImportedTargetInterface, std::less<>> &imported_targets) {
const auto &description = evaluated.description;
if (description.dependencies.empty() && description.dependency_files.empty()) {
return 0;
}
std::vector<Package::NormalizedDependency> toml_deps;
for (const auto &dep_file : description.dependency_files) {
const auto path = std::filesystem::path{dep_file}.is_absolute()
? std::filesystem::path{dep_file}
: (options.project_root / dep_file);
auto loaded = Package::load_dependencies_toml(path);
if (!loaded) {
return std::unexpected{std::format("build: {}", loaded.error().format())};
}
toml_deps.insert(toml_deps.end(), loaded->begin(), loaded->end());
}
auto merged = Package::merge_dependencies(description.dependencies, toml_deps);
if (!merged) {
return std::unexpected{std::format("build: {}", merged.error().format())};
}
if (merged->empty()) {
return 0;
}
auto pinned_lock = Package::load_pinned_lock(options.project_root / "vbs.lock");
if (!pinned_lock) {
return std::unexpected{std::format("build: {}", pinned_lock.error().format())};
}
Package::ResolveOptions resolve_options;
resolve_options.project_root = options.project_root;
resolve_options.build_root = options.build_root;
resolve_options.pinned_lock = *pinned_lock;
resolve_options.default_registry_url = Void::Configuration::get_env_or("VBS_REGISTRY_URL", "");
resolve_options.registry_auth =
Package::RegistryAuth{Void::Configuration::get_env_or("VBS_REGISTRY_TOKEN", "")};
auto resolved =
Package::resolve_and_materialize_dependencies(evaluated.context, *merged, resolve_options);
if (!resolved) {
return std::unexpected{std::format("build: {}", resolved.error().format())};
}
const auto frontend = make_frontend_options(options);
for (const auto &[dependency, source] : resolved->materialized) {
DependencyRecord effective = dependency;
std::error_code ec;
if (effective.builder.empty()) {
if (std::filesystem::is_regular_file(source.source_dir / "build.cpp", ec)) {
effective.builder = "native";
} else if (std::filesystem::is_regular_file(source.source_dir / "CMakeLists.txt", ec)) {
effective.builder = "cmake";
} else if (std::filesystem::is_regular_file(source.source_dir / "meson.build", ec)) {
effective.builder = "meson";
}
}
if (effective.builder != "cmake" && effective.builder != "meson" &&
effective.builder != "conan" && effective.builder != "native") {
continue;
}
Provider::ProviderRequest request{effective,
source,
evaluated.context,
evaluated.toolchain,
options.build_root / ".vbs" / "providers",
Provider::ProviderMode::FullBuild,
{},
frontend.sdk_include_dir,
frontend.sdk_source_dir,
frontend.sdk_library_path.empty()
? std::nullopt
: std::optional{frontend.sdk_library_path},
&state,
jobs};
auto exported = Provider::resolve_foreign_provider(request);
if (!exported) {
return std::unexpected{std::format("build: {}", exported.error().format())};
}
for (const auto &[name, interface] : exported->targets) {
imported_targets[name] = interface;
}
}
return resolved->materialized.size();
}
// Bounded build-serving request: resolves dependencies, lowers the project graph, and executes it
// in-process against the daemon's warm StateStore.
std::string build_project(const DaemonOptions &options, State::StateStore &state,
std::string_view profile_name,
std::optional<CompilerFamily> compiler_override,
@@ -394,10 +499,21 @@ std::string build_project(const DaemonOptions &options, State::StateStore &state
return error_response(evaluated.error());
}
std::map<std::string, Graph::ImportedTargetInterface, std::less<>> imported_targets;
auto materialized =
materialize_project_dependencies(options, state, *evaluated, jobs, imported_targets);
if (!materialized) {
return error_response(materialized.error());
}
auto graph = lower_graph(options, *evaluated, std::move(imported_targets), "build");
if (!graph) {
return error_response(graph.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);
auto report = Execution::execute_graph(*graph, state, exec_options);
if (!report) {
return error_response(std::format("build: {}", report.error().format()));
}
@@ -417,10 +533,9 @@ std::string build_project(const DaemonOptions &options, State::StateStore &state
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<std::int64_t>(evaluated->graph.targets.size())});
object.emplace("actions",
JsonValue{static_cast<std::int64_t>(evaluated->graph.actions.size())});
object.emplace("targets", JsonValue{static_cast<std::int64_t>(graph->targets.size())});
object.emplace("actions", JsonValue{static_cast<std::int64_t>(graph->actions.size())});
object.emplace("dependencies", JsonValue{static_cast<std::int64_t>(*materialized)});
object.emplace("executed", JsonValue{static_cast<std::int64_t>(report->executed_count)});
object.emplace("cached", JsonValue{static_cast<std::int64_t>(report->cached_count)});
object.emplace("failed", JsonValue{static_cast<std::int64_t>(report->failed_count)});
@@ -436,7 +551,11 @@ std::string describe_project(const DaemonOptions &options, std::string_view prof
if (!evaluated) {
return error_response(evaluated.error());
}
const auto &graph = evaluated->graph;
auto lowered = lower_graph(options, *evaluated, {}, "describe");
if (!lowered) {
return error_response(lowered.error());
}
const auto &graph = *lowered;
const auto &context = evaluated->context;
std::vector<std::string> target_names;
+14 -267
View File
@@ -11,6 +11,7 @@
#include <Void/Build/Package/Fetch.hpp>
#include <Void/Build/Package/Lockfile.hpp>
#include <Void/Build/Package/RegistryClient.hpp>
#include <Void/Build/Package/Resolver.hpp>
#include <Void/Build/Package/Solver.hpp>
#include <Void/Build/Package/Toml.hpp>
#include <Void/Build/Platform/FileOps.hpp>
@@ -260,279 +261,25 @@ SnapshotInputs collect_snapshot_inputs(const Graph::ProjectDescription &desc,
return out;
}
struct ResolvedDepMaterialization {
Package::LockContextRecord lock_context;
std::vector<std::pair<DependencyRecord, Package::MaterializedSource>> materialized;
};
using ResolvedDepMaterialization = Package::ResolvedDepMaterialization;
// Shared dependency resolution + live registry fetching + safe archive extraction + lock context
// builder for `vbs deps resolve|update`, `vbs build`, and `vbs test`.
// Thin CLI adapter over the shared Package resolver (environment-provided registry defaults).
Void::Result::Result<ResolvedDepMaterialization, Void::Result::Error> resolve_and_materialize_deps(
const ProfileContext &ctx, const std::vector<Package::NormalizedDependency> &merged_deps,
const std::filesystem::path &project_root, const std::filesystem::path &build_root,
const std::optional<Package::PinnedLock> &pinned_lock, bool offline, bool allow_upgrade,
const std::vector<std::string> &trusted_public_keys) {
const std::string ctx_key = Package::make_lock_context_key(ctx, "target");
const std::string fp = Package::compute_declaration_fingerprint(ctx, "target", merged_deps);
ResolvedDepMaterialization out;
out.lock_context.context_key = ctx_key;
out.lock_context.profile_name = ctx.name;
out.lock_context.compiler = std::string{compiler_name(ctx.compiler)};
out.lock_context.os = ctx.os;
out.lock_context.architecture = ctx.architecture;
out.lock_context.machine_role = "target";
out.lock_context.declaration_fingerprint = fp;
// Collect existing lock pins (used unless `deps update` requested an upgrade).
Package::SolveOptions solve_opts;
std::map<Package::PackageId, Package::LockedSourceEntry> locked_pkg_entries;
if (!allow_upgrade && pinned_lock && pinned_lock->document.contexts.contains(ctx_key)) {
for (const auto &entry : pinned_lock->document.contexts.at(ctx_key).entries) {
if (entry.source_kind == "package" && !entry.package_name.empty()) {
const Package::PackageId pid{entry.registry_authority, entry.package_name};
locked_pkg_entries[pid] = entry;
if (auto ver = Void::Semver::parse_strict(entry.version); ver) {
solve_opts.pinned_versions[pid] = *ver;
}
}
}
}
// 1. Solve all registry package dependencies together via PubGrub.
const std::string default_registry = Void::Configuration::get_env_or("VBS_REGISTRY_URL", "");
Package::RegistryAuth reg_auth{Void::Configuration::get_env_or("VBS_REGISTRY_TOKEN", "")};
std::vector<Package::DependencyConstraint> root_constraints;
std::map<std::string, Package::PackageId, std::less<>> alias_to_pkg_id;
std::vector<const Package::NormalizedDependency *> package_deps;
for (const auto &nd : merged_deps) {
if (nd.record.source_kind != DependencySourceKind::Package) {
continue;
}
const std::string reg_url =
nd.record.registry_authority.empty() ? default_registry : nd.record.registry_authority;
if (reg_url.empty()) {
return std::unexpected{Void::System::make_system_error(
Void::System::SystemErrorCode::invalid_argument,
std::format("package dependency '{}' requires .registry(url) or VBS_REGISTRY_URL",
nd.record.name))};
}
const std::string pkg_name = nd.record.package.empty() ? nd.record.name : nd.record.package;
const Package::PackageId pid{reg_url, pkg_name};
alias_to_pkg_id[nd.record.name] = pid;
package_deps.push_back(&nd);
root_constraints.push_back(Package::DependencyConstraint{
pid, nd.record.version.empty() ? ">=0.0.0" : nd.record.version, nd.record.features,
"root(" + nd.record.name + ")"});
}
std::map<Package::PackageId, Package::SolvedPackage> solved_packages;
if (!root_constraints.empty()) {
Void::Log::info("Deps", "Solving {} registry package constraint(s)...",
root_constraints.size());
bool all_locked_cached = offline;
const auto pkg_cache_root = build_root / ".vbs" / "cache" / "packages";
if (all_locked_cached) {
for (const auto *nd : package_deps) {
const auto &pid = alias_to_pkg_id.at(nd->record.name);
const auto it = locked_pkg_entries.find(pid);
if (it == locked_pkg_entries.end() || it->second.sha256.empty() ||
!std::filesystem::is_directory(pkg_cache_root / it->second.sha256 / "src")) {
all_locked_cached = false;
break;
}
}
}
if (all_locked_cached) {
Void::Log::info("Deps", "Using offline cached locked package graph");
for (const auto *nd : package_deps) {
const auto &pid = alias_to_pkg_id.at(nd->record.name);
const auto &le = locked_pkg_entries.at(pid);
auto parsed_ver = Void::Semver::parse_strict(le.version);
if (!parsed_ver) {
return std::unexpected{Void::System::make_system_error(
Void::System::SystemErrorCode::invalid_argument,
std::format("corrupt locked version '{}' for package '{}'", le.version,
pid.name))};
}
Package::SolvedPackage sp;
sp.id = pid;
sp.version = *parsed_ver;
sp.source_sha256 = le.sha256;
solved_packages[pid] = std::move(sp);
}
} else {
if (offline) {
return std::unexpected{Void::System::make_system_error(
Void::System::SystemErrorCode::not_found,
"offline mode cannot query live package registry; populate cache first")};
}
Package::PackageIndex index;
std::set<Package::PackageId> fetched_ids;
std::queue<Package::PackageId> pending;
for (const auto &c : root_constraints) {
if (fetched_ids.insert(c.target).second) {
pending.push(c.target);
}
}
while (!pending.empty()) {
const auto pid = pending.front();
pending.pop();
Void::Log::debug("Deps", "Fetching release index for '{}' from {}", pid.name,
pid.registry_authority);
auto releases =
Package::fetch_package_releases(pid.registry_authority, pid.name, reg_auth);
if (!releases) {
return std::unexpected{releases.error()};
}
for (auto &rel : *releases) {
for (const auto &dep_c : rel.dependencies) {
if (fetched_ids.insert(dep_c.target).second) {
pending.push(dep_c.target);
}
}
index.add_release(std::move(rel));
}
}
auto solved = Package::solve_dependencies(root_constraints, index, solve_opts);
if (!solved) {
return std::unexpected{solved.error()};
}
solved_packages = std::move(solved->packages);
}
}
// 2. Materialize every dependency (registry packages + git/path/archive/conan).
const auto pkg_cache_root = build_root / ".vbs" / "cache" / "packages";
std::error_code ec;
for (const auto &nd : merged_deps) {
if (nd.record.source_kind == DependencySourceKind::Package) {
const auto &pid = alias_to_pkg_id.at(nd.record.name);
const auto &sp = solved_packages.at(pid);
const auto tar_path = pkg_cache_root / (sp.source_sha256 + ".tar");
const auto extract_dir = pkg_cache_root / sp.source_sha256 / "src";
std::string package_signature;
std::string package_public_key;
if (const auto it = locked_pkg_entries.find(pid);
it != locked_pkg_entries.end() && it->second.sha256 == sp.source_sha256) {
package_signature = it->second.signature.value_or(std::string{});
package_public_key = it->second.public_key.value_or(std::string{});
} else {
package_signature = sp.signature.value_or(std::string{});
package_public_key = sp.public_key.value_or(std::string{});
}
if (!trusted_public_keys.empty()) {
auto decision = Provenance::verify_trusted_package_signature(
pid.name, sp.version.to_string(),
Provenance::PackageSignature{sp.source_sha256, package_signature,
package_public_key},
trusted_public_keys);
if (!decision) {
return std::unexpected{decision.error()};
}
if (*decision != Provenance::TrustDecision::Verified) {
return std::unexpected{Void::System::make_system_error(
Void::System::SystemErrorCode::permission_denied,
std::format("package {}@{} is not signed by a trusted key ({})", pid.name,
sp.version.to_string(),
Provenance::trust_decision_name(*decision)))};
}
}
if (!std::filesystem::is_directory(extract_dir, ec)) {
bool need_download = true;
if (std::filesystem::is_regular_file(tar_path, ec)) {
auto have_sha = Util::sha256_file_hex(tar_path);
if (have_sha && *have_sha == sp.source_sha256) {
need_download = false;
}
}
if (need_download) {
Void::Log::info("Fetch", "Downloading {}@{} from {}", pid.name,
sp.version.to_string(), pid.registry_authority);
auto dl = Package::download_release_archive(
pid.registry_authority, pid.name, sp.version.to_string(), sp.source_sha256,
tar_path, reg_auth);
if (!dl) {
return std::unexpected{dl.error()};
}
}
Void::Log::info("Fetch", "Extracting {}@{} ({})", pid.name, sp.version.to_string(),
sp.source_sha256.substr(0, 12));
auto ex = Package::extract_safe_tar(tar_path, extract_dir);
if (!ex) {
return std::unexpected{ex.error()};
}
} else {
Void::Log::debug("Fetch", "Using cached package {}@{} ({})", pid.name,
sp.version.to_string(), sp.source_sha256.substr(0, 12));
}
Package::MaterializedSource mat{nd.record.name, extract_dir, sp.source_sha256, false};
out.materialized.emplace_back(nd.record, std::move(mat));
Package::LockedSourceEntry le;
le.alias = nd.record.name;
le.source_kind = "package";
le.registry_authority = pid.registry_authority;
le.package_name = pid.name;
le.version = sp.version.to_string();
le.sha256 = sp.source_sha256;
le.builder = nd.record.builder;
le.features = nd.record.features;
le.build_dependency = nd.record.build_dependency;
if (!package_signature.empty()) {
le.signature = package_signature;
}
if (!package_public_key.empty()) {
le.public_key = package_public_key;
}
out.lock_context.entries.push_back(std::move(le));
} else {
Package::FetchOptions fopt{build_root / ".vbs" / "cache", project_root, offline, {}};
auto mat = Package::materialize_dependency_source(nd.record, fopt);
if (!mat) {
return std::unexpected{mat.error()};
}
Package::LockedSourceEntry le;
le.alias = nd.record.name;
switch (nd.record.source_kind) {
case DependencySourceKind::Git:
le.source_kind = "git";
break;
case DependencySourceKind::Path:
le.source_kind = "path";
break;
case DependencySourceKind::Archive:
le.source_kind = "archive";
break;
case DependencySourceKind::Conan:
le.source_kind = "conan";
break;
case DependencySourceKind::Package:
le.source_kind = "package";
break;
case DependencySourceKind::Unspecified:
le.source_kind = "unspecified";
break;
}
le.location = nd.record.location;
le.revision = nd.record.revision;
le.sha256 = mat->content_identity_hash;
le.builder = nd.record.builder;
le.features = nd.record.features;
le.build_dependency = nd.record.build_dependency;
out.lock_context.entries.push_back(std::move(le));
out.materialized.emplace_back(nd.record, std::move(*mat));
}
}
return out;
Package::ResolveOptions options;
options.project_root = project_root;
options.build_root = build_root;
options.pinned_lock = pinned_lock;
options.offline = offline;
options.allow_upgrade = allow_upgrade;
options.trusted_public_keys = trusted_public_keys;
options.default_registry_url = Void::Configuration::get_env_or("VBS_REGISTRY_URL", "");
options.registry_auth =
Package::RegistryAuth{Void::Configuration::get_env_or("VBS_REGISTRY_TOKEN", "")};
return Package::resolve_and_materialize_dependencies(ctx, merged_deps, options);
}
struct BuildCmdOptions {
+290
View File
@@ -0,0 +1,290 @@
#include <Void/Build/Package/Resolver.hpp>
#include <Void/Build/Package/Archive.hpp>
#include <Void/Build/Provenance/Verification.hpp>
#include <Void/Build/Util/Sha256.hpp>
#include <Void/Log/Log.hpp>
#include <Void/System/Types.hpp>
#include <Void/Text/Semver.hpp>
#include <filesystem>
#include <format>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
namespace Void::Build::Package {
Void::Result::Result<ResolvedDepMaterialization, Void::Result::Error>
resolve_and_materialize_dependencies(const ProfileContext &ctx,
const std::vector<NormalizedDependency> &merged_deps,
const ResolveOptions &options) {
const std::string ctx_key = make_lock_context_key(ctx, "target");
const std::string fp = compute_declaration_fingerprint(ctx, "target", merged_deps);
ResolvedDepMaterialization out;
out.lock_context.context_key = ctx_key;
out.lock_context.profile_name = ctx.name;
out.lock_context.compiler = std::string{compiler_name(ctx.compiler)};
out.lock_context.os = ctx.os;
out.lock_context.architecture = ctx.architecture;
out.lock_context.machine_role = "target";
out.lock_context.declaration_fingerprint = fp;
// Collect existing lock pins (used unless an upgrade was requested).
SolveOptions solve_opts;
std::map<PackageId, LockedSourceEntry> locked_pkg_entries;
if (!options.allow_upgrade && options.pinned_lock &&
options.pinned_lock->document.contexts.contains(ctx_key)) {
for (const auto &entry : options.pinned_lock->document.contexts.at(ctx_key).entries) {
if (entry.source_kind == "package" && !entry.package_name.empty()) {
const PackageId pid{entry.registry_authority, entry.package_name};
locked_pkg_entries[pid] = entry;
if (auto ver = Void::Semver::parse_strict(entry.version); ver) {
solve_opts.pinned_versions[pid] = *ver;
}
}
}
}
// 1. Solve all registry package dependencies together via PubGrub.
std::vector<DependencyConstraint> root_constraints;
std::map<std::string, PackageId, std::less<>> alias_to_pkg_id;
std::vector<const NormalizedDependency *> package_deps;
for (const auto &nd : merged_deps) {
if (nd.record.source_kind != DependencySourceKind::Package) {
continue;
}
const std::string reg_url = nd.record.registry_authority.empty()
? options.default_registry_url
: nd.record.registry_authority;
if (reg_url.empty()) {
return std::unexpected{Void::System::make_system_error(
Void::System::SystemErrorCode::invalid_argument,
std::format("package dependency '{}' requires .registry(url) or "
"VBS_REGISTRY_URL",
nd.record.name))};
}
const std::string pkg_name = nd.record.package.empty() ? nd.record.name : nd.record.package;
const PackageId pid{reg_url, pkg_name};
alias_to_pkg_id[nd.record.name] = pid;
package_deps.push_back(&nd);
root_constraints.push_back(
DependencyConstraint{pid, nd.record.version.empty() ? ">=0.0.0" : nd.record.version,
nd.record.features, "root(" + nd.record.name + ")"});
}
std::map<PackageId, SolvedPackage> solved_packages;
if (!root_constraints.empty()) {
Void::Log::info("Deps", "Solving {} registry package constraint(s)...",
root_constraints.size());
bool all_locked_cached = options.offline;
const auto pkg_cache_root = options.build_root / ".vbs" / "cache" / "packages";
if (all_locked_cached) {
for (const auto *nd : package_deps) {
const auto &pid = alias_to_pkg_id.at(nd->record.name);
const auto it = locked_pkg_entries.find(pid);
if (it == locked_pkg_entries.end() || it->second.sha256.empty() ||
!std::filesystem::is_directory(pkg_cache_root / it->second.sha256 / "src")) {
all_locked_cached = false;
break;
}
}
}
if (all_locked_cached) {
Void::Log::info("Deps", "Using offline cached locked package graph");
for (const auto *nd : package_deps) {
const auto &pid = alias_to_pkg_id.at(nd->record.name);
const auto &le = locked_pkg_entries.at(pid);
auto parsed_ver = Void::Semver::parse_strict(le.version);
if (!parsed_ver) {
return std::unexpected{Void::System::make_system_error(
Void::System::SystemErrorCode::invalid_argument,
std::format("corrupt locked version '{}' for package '{}'", le.version,
pid.name))};
}
SolvedPackage sp;
sp.id = pid;
sp.version = *parsed_ver;
sp.source_sha256 = le.sha256;
solved_packages[pid] = std::move(sp);
}
} else {
if (options.offline) {
return std::unexpected{Void::System::make_system_error(
Void::System::SystemErrorCode::not_found,
"offline mode cannot query live package registry; populate cache first")};
}
PackageIndex index;
std::set<PackageId> fetched_ids;
std::queue<PackageId> pending;
for (const auto &c : root_constraints) {
if (fetched_ids.insert(c.target).second) {
pending.push(c.target);
}
}
while (!pending.empty()) {
const auto pid = pending.front();
pending.pop();
Void::Log::debug("Deps", "Fetching release index for '{}' from {}", pid.name,
pid.registry_authority);
auto releases =
fetch_package_releases(pid.registry_authority, pid.name, options.registry_auth);
if (!releases) {
return std::unexpected{releases.error()};
}
for (auto &rel : *releases) {
for (const auto &dep_c : rel.dependencies) {
if (fetched_ids.insert(dep_c.target).second) {
pending.push(dep_c.target);
}
}
index.add_release(std::move(rel));
}
}
auto solved = solve_dependencies(root_constraints, index, solve_opts);
if (!solved) {
return std::unexpected{solved.error()};
}
solved_packages = std::move(solved->packages);
}
}
// 2. Materialize every dependency (registry packages + git/path/archive/conan).
const auto pkg_cache_root = options.build_root / ".vbs" / "cache" / "packages";
std::error_code ec;
for (const auto &nd : merged_deps) {
if (nd.record.source_kind == DependencySourceKind::Package) {
const auto &pid = alias_to_pkg_id.at(nd.record.name);
const auto &sp = solved_packages.at(pid);
const auto tar_path = pkg_cache_root / (sp.source_sha256 + ".tar");
const auto extract_dir = pkg_cache_root / sp.source_sha256 / "src";
std::string package_signature;
std::string package_public_key;
if (const auto it = locked_pkg_entries.find(pid);
it != locked_pkg_entries.end() && it->second.sha256 == sp.source_sha256) {
package_signature = it->second.signature.value_or(std::string{});
package_public_key = it->second.public_key.value_or(std::string{});
} else {
package_signature = sp.signature.value_or(std::string{});
package_public_key = sp.public_key.value_or(std::string{});
}
if (!options.trusted_public_keys.empty()) {
auto decision = Provenance::verify_trusted_package_signature(
pid.name, sp.version.to_string(),
Provenance::PackageSignature{sp.source_sha256, package_signature,
package_public_key},
options.trusted_public_keys);
if (!decision) {
return std::unexpected{decision.error()};
}
if (*decision != Provenance::TrustDecision::Verified) {
return std::unexpected{Void::System::make_system_error(
Void::System::SystemErrorCode::permission_denied,
std::format("package {}@{} is not signed by a trusted key ({})", pid.name,
sp.version.to_string(),
Provenance::trust_decision_name(*decision)))};
}
}
if (!std::filesystem::is_directory(extract_dir, ec)) {
bool need_download = true;
if (std::filesystem::is_regular_file(tar_path, ec)) {
auto have_sha = Util::sha256_file_hex(tar_path);
if (have_sha && *have_sha == sp.source_sha256) {
need_download = false;
}
}
if (need_download) {
Void::Log::info("Fetch", "Downloading {}@{} from {}", pid.name,
sp.version.to_string(), pid.registry_authority);
auto dl = download_release_archive(pid.registry_authority, pid.name,
sp.version.to_string(), sp.source_sha256,
tar_path, options.registry_auth);
if (!dl) {
return std::unexpected{dl.error()};
}
}
Void::Log::info("Fetch", "Extracting {}@{} ({})", pid.name, sp.version.to_string(),
sp.source_sha256.substr(0, 12));
auto ex = extract_safe_tar(tar_path, extract_dir);
if (!ex) {
return std::unexpected{ex.error()};
}
} else {
Void::Log::debug("Fetch", "Using cached package {}@{} ({})", pid.name,
sp.version.to_string(), sp.source_sha256.substr(0, 12));
}
MaterializedSource mat{nd.record.name, extract_dir, sp.source_sha256, false};
out.materialized.emplace_back(nd.record, std::move(mat));
LockedSourceEntry le;
le.alias = nd.record.name;
le.source_kind = "package";
le.registry_authority = pid.registry_authority;
le.package_name = pid.name;
le.version = sp.version.to_string();
le.sha256 = sp.source_sha256;
le.builder = nd.record.builder;
le.features = nd.record.features;
le.build_dependency = nd.record.build_dependency;
if (!package_signature.empty()) {
le.signature = package_signature;
}
if (!package_public_key.empty()) {
le.public_key = package_public_key;
}
out.lock_context.entries.push_back(std::move(le));
} else {
FetchOptions fopt{
options.build_root / ".vbs" / "cache", options.project_root, options.offline, {}};
auto mat = materialize_dependency_source(nd.record, fopt);
if (!mat) {
return std::unexpected{mat.error()};
}
LockedSourceEntry le;
le.alias = nd.record.name;
switch (nd.record.source_kind) {
case DependencySourceKind::Git:
le.source_kind = "git";
break;
case DependencySourceKind::Path:
le.source_kind = "path";
break;
case DependencySourceKind::Archive:
le.source_kind = "archive";
break;
case DependencySourceKind::Conan:
le.source_kind = "conan";
break;
case DependencySourceKind::Package:
le.source_kind = "package";
break;
case DependencySourceKind::Unspecified:
le.source_kind = "unspecified";
break;
}
le.location = nd.record.location;
le.revision = nd.record.revision;
le.sha256 = mat->content_identity_hash;
le.builder = nd.record.builder;
le.features = nd.record.features;
le.build_dependency = nd.record.build_dependency;
out.lock_context.entries.push_back(std::move(le));
out.materialized.emplace_back(nd.record, std::move(*mat));
}
}
return out;
}
} // namespace Void::Build::Package
+67
View File
@@ -368,6 +368,73 @@ void build(Void::Build::Project &project) {
Void::Testing::expect(!std::filesystem::exists(socket));
}
VOID_TEST(Daemon, build_materializes_path_dependency) {
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
Void::Testing::require(temp.has_value());
const auto options = make_options(temp->path());
const auto helper = temp->path() / "helper";
std::filesystem::create_directories(helper);
{
std::ofstream descriptor{helper / "build.cpp"};
descriptor << R"cpp(#include <Void/Build.hpp>
void build(Void::Build::Project &project) {
project.static_library("helper")
.cxx_standard(Void::Build::CxxStandard::Cxx26)
.sources({"helper.cpp"});
}
)cpp";
Void::Testing::require(descriptor.good());
}
{
std::ofstream source{helper / "helper.cpp"};
source << "int helper_value() { return 3; }\n";
Void::Testing::require(source.good());
}
{
std::ofstream descriptor{options.project_root / "build.cpp"};
descriptor << "#include <Void/Build.hpp>\n"
"void build(Void::Build::Project &project) {\n"
" auto dep = project.dependency(\"helper\")\n"
" .path(\"" +
helper.string() +
"\")\n"
" .native_builder();\n"
" auto app = project.executable(\"app\");\n"
" app.cxx_standard(Void::Build::CxxStandard::Cxx26)\n"
" .sources({\"main.cpp\"})\n"
" .link(dep.target(\"helper\"));\n"
"}\n";
Void::Testing::require(descriptor.good());
}
{
std::ofstream source{options.project_root / "main.cpp"};
source << "int helper_value();\nint main() { return helper_value() == 3 ? 0 : 1; }\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<void, Void::Result::Error> 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"})", std::chrono::seconds{120});
Void::Testing::require(build.has_value());
Void::Testing::expect(bool_field(*build, "ok"));
Void::Testing::expect(int_field(*build, "dependencies") >= 1);
Void::Testing::expect(
std::filesystem::exists(options.build_root / "profiles" / "debug" / "out" / "bin" / "app"));
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_TEST(Daemon, describe_empty_project_reports_zero_targets) {
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
Void::Testing::require(temp.has_value());