feat(workspace): add multi-package workspace builds with shared lock and CAS
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 4s

- SDK: Workspace/workspace() declaration plus Project::workspace_dependency()
- Frontend: workspace.cpp discovery/evaluation alongside build.cpp
- Main: per-member builds sharing the root vbs.lock and build/.vbs CAS, --member and --changed-since selection
- Cross-member native linking; member builds do not steal the root compile_commands.json alias
- Path-dependency snapshots exclude generated editor metadata
- Verified in Docker GCC 16: 8/8 CTest suites; 3-member workspace fixture with unified lockfile
This commit is contained in:
faumaray committed 2026-12-03 13:07:09 +03:00
1 parent 09c0a91d1d
commit 2970fbe25c
12 files changed
+515 -19

No files matched your search

+20 -1
View File
@@ -89,7 +89,7 @@ All CLI help text (`vbs --help`, `vbs <command> --help`, `vbs compdb --help`, `v
- `vbs [--version] [--verbose] [--quiet] <command>`
- `vbs init [--dir DIR] [--name NAME] [--library] [--with-toml] [--force]`
- `vbs build [--project DIR] [--build-dir DIR] [--profile NAME]... [--target NAME]... [--compiler gcc|clang] [--editor-profile NAME] [--build-source FILE]... [--jobs N] [--remote-cache URL] [--remote-cache-token-env VAR] [--locked] [--offline] [--no-cache] [--native-foreign] [--verbose] [--quiet]`
- `vbs build [--project DIR] [--build-dir DIR] [--profile NAME]... [--target NAME]... [--compiler gcc|clang] [--editor-profile NAME] [--build-source FILE]... [--jobs N] [--member PKG]... [--changed-since REF] [--remote-cache URL] [--remote-cache-token-env VAR] [--locked] [--offline] [--no-cache] [--native-foreign] [--verbose] [--quiet]`
- `vbs test ...` (same flags as `vbs build`, then runs selected `TargetKind::Test` binaries)
- `vbs clean [--build-dir DIR] [--all]`
- `vbs doctor`
@@ -130,6 +130,25 @@ void build(Void::Build::Project &project) {
}
```
### Workspaces
A workspace root declares member projects in `workspace.cpp`:
```cpp
#include <Void/Build.hpp>
void workspace(Void::Build::Workspace &ws) {
ws.member("lib", "packages/lib");
ws.member("app", "packages/app");
ws.member("tests", "packages/tests");
}
```
Each member keeps its own `build.cpp` and profiles, while `vbs build`/`vbs test` at the root
share one `vbs.lock` and one `build/.vbs` CAS. Members link each other with
`project.workspace_dependency("lib").target("libcore")`, and `--member PKG` or
`--changed-since REF` select affected members.
See the [SDK reference](docs/SDK.md), [public header](include/Void/Build.hpp), and
[VoidLibrary upstream requests](docs/VOIDLIBRARY_UPSTREAM_REQUESTS.md).
+7 -2
View File
@@ -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 (Docker GCC 16) 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 (Docker GCC 16) complete
## Completed delivery waves
@@ -59,9 +59,14 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B
- **D2**: Snapshot capture revalidation now hashes on a bounded `Void::Concurrency::ThreadPool` for trees of 32+ files.
- **Docker verification**: built and tested in `voidlibrary-dev` (GCC 16.0.1, pinned VoidLibrary `3e25405`) with `8/8` CTest suites passing. D1 acceptance verified end-to-end: a cold `vbs build` populates the remote CAS, and a second clean build directory reports `0 executed` with the binary running. D2 benchmark on 5,001 files: `warm_noop_ms=374` (5,002 cached, 0 executed), meeting the sub-second gate. Also fixed the self-host recipe source list for `RemoteCache.cpp` and accepted GCC 16's `-lgcc_s_asneeded` system link flag.
- **Wave 12 (Track E2 Multi-Package Workspaces)**:
- Added the workspace SDK (`Void::Build::Workspace`, `workspace(Workspace&)`, `Project::workspace_dependency()`), `workspace.cpp` descriptor discovery/evaluation in `Config::Frontend`, and workspace orchestration in `src/Main.cpp`: each member builds with its own `build.cpp`/profiles while sharing the root `vbs.lock` and `build/.vbs` CAS.
- Cross-member linking resolves `workspace_dependency("lib").target("core")` to the member's native path provider through `VBS_WORKSPACE_MEMBER_<name>`; `--member <pkg>` and `--changed-since <ref>` select affected members. Member builds do not steal the project-root `compile_commands.json` alias, and path-dependency snapshots exclude generated editor metadata.
- **Docker verification**: `FullV1Tests.workspace_members_shared_build_and_member_selection` builds a 3-member workspace (shared library + app + test) with a unified root lockfile, runs the app, selects a single member, and selects by changed file; all 8 CTest suites pass.
## 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 D1/D2 acceptance scenarios (suites pass; cache-hit/benchmark pending), Track D3 (SBOM/signatures), Track E2 (`workspace.cpp`), Track E3 (`vbs daemon` local socket server + external editor plugins), 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 D1/D2 acceptance scenarios (suites pass; cache-hit/benchmark pending), Track D3 (SBOM/signatures), Track E3 (`vbs daemon` local socket server + external editor plugins), and Track E4 (`Void::Net`/`Void::Sqlite` alignment) remain planned scope.
## Environment notes & upstream boundaries
+2 -1
View File
@@ -18,4 +18,5 @@ Base HEAD: `fe0d1a6`
| Wave 9 (Track A — Zero-CMake Self-Hosting, Full `VOID_TEST` Suite, & Bit-Identical Stage 2 == Stage 3) | First-class `builder == "native"` provider + `.native_builder()` in `build.cpp`; all tests migrated to `VOID_TEST(Suite, name)` & `VoidTestScanner.cmake` removed; all 13 targets (`vbs_benchmarks` + 6 test suites) declared in `build.cpp`; `binary_dir = ""` + `/vbs-build` prefix map + `-frandom-seed` Stage 2 == Stage 3 reproducibility verified with trapped `cmake` | COMPLETE & VERIFIED | `include/Void/Build/Provider/Provider.hpp`, `src/Provider/Provider.cpp`, `src/Graph/Graph.cpp`, `src/Toolchain/Driver.cpp`, `src/Main.cpp`, `recipes/VoidLibrary/VoidLibraryRecipe.{hpp,cpp}`, `build.cpp`, `CMakeLists.txt`, `tests/*`, docs |
| Wave 10 (Track B [B1–B3] + First-Class `vbs ide` Integration) | Native C driver (`CStandard`) & mixed C/C++ CMake/Meson translation (`PerFileOption`); bounded `build.ninja` `CUSTOM_COMMAND` translation (`CustomAction`); foreign CMake `CXX_MODULES` `fileSets` & cross-target `module_bmis` + Clang `default_include_dirs`; `build.cpp` SDK CompDB indexing + `vbs ide generate\|query` | COMPLETE & VERIFIED | `include/Void/Build.hpp`, `Driver.{hpp,cpp}`, `ModuleScanner.{hpp,cpp}`, `Graph.{hpp,cpp}`, `CompDb.{hpp,cpp}`, `Provider.cpp`, `Translator.{hpp,cpp}`, `Watcher.cpp`, `Main.cpp`, `tests/{FullV1Tests.cpp,CliContracts.cmake}`, docs |
| Wave 11 (Track D1–D2) | Shared HTTP CAS action cache (`/api/v1/cas/{blobs,actions}`, bearer auth, digest verification, portable action keys, `--remote-cache`) + parallel snapshot revalidation hashing | COMPLETE & VERIFIED (Docker GCC 16.0.1, pinned VoidLibrary, 8/8 CTest suites; D1 cross-build-dir 100% cache hit; D2 5,001-file warm no-op 374 ms) | `include/Void/Build/State/RemoteCache.hpp`, `src/State/RemoteCache.cpp`, `StateStore.{hpp,cpp}`, `Scheduler.cpp`, `Snapshot.cpp`, `registry/service/RegistryService.cpp`, `src/Main.cpp`, `tests/RegistryTests.cpp`, docs |
| Future (Plan 20 Slice 3 / Tracks C–D, E2, E3 daemon, E4, live `conan`) | Live `conan` CLI verification; macOS/Windows/cross-compile; shared HTTP CAS & SBOM/signatures; `workspace.cpp`, `vbs daemon`, `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 12 (Track E2 Workspaces) | `workspace.cpp` member declaration/evaluation, shared root `vbs.lock` + `build/.vbs` CAS, `workspace_dependency()` cross-member native linking, `--member` and `--changed-since` selection | COMPLETE & VERIFIED (Docker GCC 16.0.1, 8/8 CTest suites; 3-member fixture with unified lockfile) | `include/Void/Build.hpp`, `src/Build.cpp`, `Config/Frontend.{hpp,cpp}`, `src/Main.cpp`, `src/Package/Fetch.cpp`, `tests/FullV1Tests.cpp`, docs |
| Future (Plan 20 Slice 3 / Tracks C–D, E3 daemon, E4, live `conan`) | Live `conan` CLI verification; macOS/Windows/cross-compile; SBOM/signatures; `vbs daemon`, `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) |
+17
View File
@@ -156,6 +156,23 @@ docker run --rm --user "$(id -u):$(id -g)" -e HOME=/tmp -v "$PWD":/src -w /src \
Warm no-op is **374 ms for 5,001 files** (all 5,002 actions cached, zero executed), meeting
the sub-second D2 acceptance gate.
## Track E2 Workspaces in Docker (2026-12-03)
`FullV1Tests.workspace_members_shared_build_and_member_selection` builds a 3-member
workspace (`packages/lib` shared library, `packages/app` executable, `packages/tests` test)
declared by a root `workspace.cpp`:
- `vbs test` builds and runs all members with one root `vbs.lock` and one shared
`build/.vbs` CAS; `packages/app` links `packages/lib` through
`workspace_dependency("lib").target("libcore")`; the app binary runs successfully.
- No member directory receives its own `vbs.lock`, and member builds do not overwrite the
project-root `compile_commands.json` alias.
- `vbs build --member app` builds only the selected member (plus its workspace dependency).
- `vbs build --changed-since HEAD` after a committed edit selects only the owning member.
Full suite after the change: **8 / 8 CTest suites passed** in 800.22 s (`vbs_v1_tests`
170.33 s, `vbs_registry_tests` 36.82 s, `vbs_selfhost_tests` 568.05 s).
## 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).
+2 -2
View File
@@ -1,6 +1,6 @@
# 21 — Post-v1 Expansion Roadmap
Status: Active execution guide (Plans **01–19**, **Plan 20 Slices 1–2C**, **Track A [A1–A3]**, **Track B [B1–B3, except live `conan` CLI container]**, **Track E1**, and **Track E3 IDE config/query tooling** are implemented and verified; **Track D1/D2** are implemented and verified in Docker GCC 16 (D1 cross-build-directory 100% cache hit; D2 5,001-file warm no-op 374 ms); **Track C**, **Track D3**, **Track E2 (`workspace.cpp`)**, **Track E3 (`vbs daemon`)**, **Track E4**, and live `conan` CLI verification remain planned; see [STATE](../agent-workflow/STATE.md) and [VERIFICATION](../agent-workflow/VERIFICATION.md)).
Status: Active execution guide (Plans **01–19**, **Plan 20 Slices 1–2C**, **Track A [A1–A3]**, **Track B [B1–B3, except live `conan` CLI container]**, **Track E1**, and **Track E3 IDE config/query tooling** are implemented and verified; **Track D1/D2** are implemented and verified in Docker GCC 16 (D1 cross-build-directory 100% cache hit; D2 5,001-file warm no-op 374 ms); **Track E2 (`workspace.cpp`)** is implemented and verified in Docker GCC 16; **Track C**, **Track D3**, **Track E3 (`vbs daemon`)**, **Track E4**, and live `conan` CLI verification remain planned; see [STATE](../agent-workflow/STATE.md) and [VERIFICATION](../agent-workflow/VERIFICATION.md)).
This roadmap defines five orthogonal expansion tracks for taking VoidBuildSystem from a verified self-hosting Linux C++26 build system into a multi-platform, distributed, daily-driver ecosystem. Each track preserves core architectural invariants: ordinary C++ descriptions, hermetic content-verified snapshots, isolated profiles, immutable CAS publication, and explicit diagnostics over silent approximation.
@@ -72,7 +72,7 @@ flowchart LR
| Phase | Concrete Scope | Acceptance Gate |
| --- | --- | --- |
| **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`)** | Shared `vbs.lock`, shared CAS, cross-member local target linking, and affected-target graph selection (`vbs build --member <pkg>` / `--changed-since <ref>`). | 3-package workspace fixture building shared library + app + tests with unified lockfile. |
| **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**); optional Unix-socket `vbs daemon` holding warm `StateStore`/`RunDigestCache`/`DirectoryWatcher` (**Planned**). | `vbs ide` & `build.cpp` syntax-check verified in `FullV1Tests.cpp`; `vbs daemon` & dedicated editor extensions pending. |
| **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. |
+22
View File
@@ -221,6 +221,24 @@ struct DependencyRecord {
bool build_dependency{false};
};
// Workspace declaration (E2): a root workspace.cpp lists member projects that share one
// vbs.lock and one build/.vbs CAS while each keeps its own build.cpp and profile outputs.
struct WorkspaceMemberRecord {
std::string name;
std::string path; // Relative to the workspace root (or absolute).
};
class Workspace {
public:
Workspace() = default;
Workspace &member(std::string name, std::string path);
[[nodiscard]] const std::vector<WorkspaceMemberRecord> &members() const noexcept;
[[nodiscard]] std::string to_json() const;
private:
std::vector<WorkspaceMemberRecord> members_;
};
namespace detail {
struct ProjectState;
}
@@ -319,6 +337,9 @@ class Project {
[[nodiscard]] Target custom_action(std::string name);
[[nodiscard]] Target test(std::string name);
[[nodiscard]] Dependency dependency(std::string name);
// Links to another member of the enclosing workspace. The member path is supplied by the
// workspace driver through VBS_WORKSPACE_MEMBER_<name> and built with the native provider.
[[nodiscard]] Dependency workspace_dependency(std::string name);
void dependencies_file(std::string toml_path = "vbs.deps.toml");
void install_file(std::string source_path, std::string destination,
std::string component = "default");
@@ -342,3 +363,4 @@ class Project {
// Description entry points supplied by ordinary user C++ translation units.
void build(Void::Build::Project &project);
void profiles(Void::Build::Profiles &profiles);
void workspace(Void::Build::Workspace &workspace);
+17
View File
@@ -34,6 +34,19 @@ struct CompiledDescriptor {
bool recompiled{false};
};
struct WorkspaceMember {
std::string name;
std::string path;
};
struct WorkspaceDescription {
int schema_version{1};
std::vector<WorkspaceMember> members;
};
// True when project_root contains workspace.cpp (a multi-member workspace root).
[[nodiscard]] bool is_workspace_root(const std::filesystem::path &project_root);
// Discovers configuration C++ sources purely from filesystem membership (works without .git!):
// build.cpp, optional build.profiles.cpp, sorted build-support/**/*.cpp, and explicit extra
// sources.
@@ -57,4 +70,8 @@ discover_profiles(const CompiledDescriptor &descriptor, const FrontendOptions &o
evaluate_project(const CompiledDescriptor &descriptor, const ProfileContext &context,
const FrontendOptions &options);
// Evaluates workspace(Workspace&) from a workspace.cpp descriptor and returns its members.
[[nodiscard]] Void::Result::Result<WorkspaceDescription, Void::Result::Error>
evaluate_workspace(const CompiledDescriptor &descriptor, const FrontendOptions &options);
} // namespace Void::Build::Config
+39
View File
@@ -2,6 +2,7 @@
#include <Void/Build/Util/Json.hpp>
#include <algorithm>
#include <cstdlib>
#include <set>
#include <type_traits>
@@ -1064,6 +1065,44 @@ Dependency Project::dependency(std::string name) {
state_->dependencies.push_back(std::move(record));
return Dependency{state_, state_->dependencies.size() - 1};
}
Dependency Project::workspace_dependency(std::string name) {
auto dep = dependency(name);
auto &record = state_->dependencies.back();
const std::string env_name = "VBS_WORKSPACE_MEMBER_" + record.name;
const char *member_path = std::getenv(env_name.c_str());
if (!member_path || member_path[0] == '\0') {
throw std::invalid_argument{"workspace member '" + record.name +
"' is not provided by the enclosing workspace"};
}
record.source_kind = DependencySourceKind::Path;
record.location = member_path;
record.builder = "native";
record.options.insert_or_assign("vbs.workspace.member", OptionValue{record.name});
return dep;
}
Workspace &Workspace::member(std::string name, std::string path) {
require_text(name, "workspace member name");
require_text(path, "workspace member path");
if (std::ranges::any_of(members_, [&](const auto &member) { return member.name == name; })) {
throw std::invalid_argument{"duplicate workspace member '" + name + "'"};
}
members_.push_back({std::move(name), std::move(path)});
return *this;
}
const std::vector<WorkspaceMemberRecord> &Workspace::members() const noexcept { return members_; }
std::string Workspace::to_json() const {
return "{\"schema_version\":1,\"members\":" +
json_array(members_,
[](const WorkspaceMemberRecord &member) {
return "{\"name\":" + json_quote(member.name) +
",\"path\":" + json_quote(member.path) + '}';
}) +
'}';
}
void Project::dependencies_file(std::string toml_path) {
require_text(toml_path, "dependencies manifest path");
state_->dependency_files.push_back(std::move(toml_path));
+130 -5
View File
@@ -32,7 +32,8 @@ bool is_cpp_file(const std::filesystem::path &p) {
return ext == ".cpp" || ext == ".cc" || ext == ".cxx";
}
std::string generate_driver_source(bool has_profiles_file) {
std::string generate_driver_source(bool has_profiles_file, bool has_build_file,
bool has_workspace_file) {
std::string code = R"cpp(#include <Void/Build.hpp>
#include <Void/Build/Util/Json.hpp>
@@ -49,6 +50,18 @@ std::string generate_driver_source(bool has_profiles_file) {
code += R"cpp(void profiles(Void::Build::Profiles &descriptions) {
descriptions = Void::Build::default_profiles();
}
)cpp";
}
if (!has_build_file) {
code += R"cpp(void build(Void::Build::Project &) {
throw std::runtime_error{"this descriptor declares no build() entry point"};
}
)cpp";
}
if (!has_workspace_file) {
code += R"cpp(void workspace(Void::Build::Workspace &) {
throw std::runtime_error{"this descriptor declares no workspace() entry point"};
}
)cpp";
}
code += R"cpp(
@@ -166,6 +179,16 @@ int main(int argc, char **argv) {
write_text(output_path, payload);
return 0;
}
if (mode == "workspace") {
Void::Build::Workspace ws;
workspace(ws);
const std::string payload =
"{\"protocol_version\":1,\"request_id\":" +
Void::Build::Util::json_quote(request_id) +
",\"payload\":" + ws.to_json() + "}\n";
write_text(output_path, payload);
return 0;
}
std::cerr << "vbs-config-driver: unknown mode '" << mode << "'\n";
return 2;
} catch (const std::exception &err) {
@@ -257,9 +280,13 @@ discover_config_sources(const std::filesystem::path &project_root,
}
const auto root_build = canonical_root / "build.cpp";
if (!std::filesystem::is_regular_file(root_build, ec)) {
const auto root_workspace = canonical_root / "workspace.cpp";
const bool has_build = std::filesystem::is_regular_file(root_build, ec);
const bool has_workspace = std::filesystem::is_regular_file(root_workspace, ec);
if (!has_build && !has_workspace) {
return std::unexpected{
make_error(std::format("missing required root description '{}'", root_build.string()))};
make_error(std::format("missing required root description '{}' or '{}'",
root_build.string(), root_workspace.string()))};
}
std::vector<std::filesystem::path> sources;
@@ -271,7 +298,12 @@ discover_config_sources(const std::filesystem::path &project_root,
}
};
push(root_build);
if (has_build) {
push(root_build);
}
if (has_workspace) {
push(root_workspace);
}
const auto profiles_cpp = canonical_root / "build.profiles.cpp";
if (std::filesystem::is_regular_file(profiles_cpp, ec)) {
@@ -349,7 +381,10 @@ compile_descriptor(const FrontendOptions &options) {
const bool has_profiles =
std::filesystem::is_regular_file(canonical_root / "build.profiles.cpp", ec);
const std::string driver_src = generate_driver_source(has_profiles);
const bool has_build = std::filesystem::is_regular_file(canonical_root / "build.cpp", ec);
const bool has_workspace =
std::filesystem::is_regular_file(canonical_root / "workspace.cpp", ec);
const std::string driver_src = generate_driver_source(has_profiles, has_build, has_workspace);
const auto driver_cpp = config_dir / "Driver.cpp";
if (auto wrote = Platform::atomic_write_file(driver_cpp, driver_src, false); !wrote) {
return std::unexpected{wrote.error()};
@@ -552,6 +587,11 @@ compile_descriptor(const FrontendOptions &options) {
return desc;
}
bool is_workspace_root(const std::filesystem::path &project_root) {
std::error_code ec;
return std::filesystem::is_regular_file(project_root / "workspace.cpp", ec);
}
Void::Result::Result<Profiles, Void::Result::Error>
discover_profiles(const CompiledDescriptor &descriptor, const FrontendOptions &options) {
std::error_code ec;
@@ -763,4 +803,89 @@ evaluate_project(const CompiledDescriptor &descriptor, const ProfileContext &con
return desc;
}
Void::Result::Result<WorkspaceDescription, Void::Result::Error>
evaluate_workspace(const CompiledDescriptor &descriptor, const FrontendOptions &options) {
std::error_code ec;
const auto run_dir =
std::filesystem::weakly_canonical(options.build_root, ec) / ".vbs" / "config" / "eval";
std::filesystem::create_directories(run_dir, ec);
const std::string req_id = std::format("ws_{}_{}", static_cast<long long>(::getpid()),
g_req_seq.fetch_add(1, std::memory_order_relaxed));
const auto out_file = run_dir / (req_id + ".json");
Platform::ProcessRequest req;
req.executable = descriptor.executable_path;
req.arguments = {"--mode", "workspace", "--output", out_file.string(), "--request-id", req_id};
req.working_directory = options.project_root;
req.timeout = options.eval_timeout;
auto proc = Platform::run_supervised(req);
auto cleanup = [&] { std::filesystem::remove(out_file, ec); };
if (!proc) {
cleanup();
return std::unexpected{proc.error()};
}
if (!proc->succeeded()) {
cleanup();
return std::unexpected{
make_error(std::format("workspace evaluation failed (exit={}, signal={}): {}",
proc->exit_code, proc->term_signal, proc->stderr_data))};
}
auto text = Void::FileSystem::read_file_bounded(out_file, {16ULL * 1024ULL * 1024ULL});
cleanup();
if (!text) {
return std::unexpected{make_error("workspace evaluation did not produce a result file")};
}
if (!Util::is_valid_utf8(*text)) {
return std::unexpected{make_error("workspace evaluation result contains invalid UTF-8")};
}
auto parsed = Void::Json::Strict::parse(*text);
if (!parsed) {
return std::unexpected{make_error("workspace evaluation emitted malformed JSON")};
}
const auto *root = std::get_if<JsonVal::Object>(&parsed->value);
if (!root) {
return std::unexpected{make_error("workspace evaluation envelope must be a JSON object")};
}
if (get_i64(*root, "protocol_version").value_or(0) != kFrontendProtocolVersion) {
return std::unexpected{make_error("workspace evaluation protocol version mismatch")};
}
if (get_str(*root, "request_id").value_or("") != req_id) {
return std::unexpected{make_error("workspace evaluation request_id mismatch")};
}
const auto *payload_v = find_key(*root, "payload");
const auto *payload = payload_v ? std::get_if<JsonVal::Object>(&payload_v->value) : nullptr;
if (!payload) {
return std::unexpected{make_error("workspace evaluation missing payload")};
}
const auto *members_v = find_key(*payload, "members");
const auto *arr = members_v ? std::get_if<JsonVal::Array>(&members_v->value) : nullptr;
if (!arr) {
return std::unexpected{make_error("workspace evaluation payload missing members array")};
}
WorkspaceDescription result;
std::set<std::string> seen;
for (const auto &mv : *arr) {
const auto *mobj = std::get_if<JsonVal::Object>(&mv.value);
if (!mobj) {
continue;
}
WorkspaceMember member;
member.name = get_str(*mobj, "name").value_or("");
member.path = get_str(*mobj, "path").value_or("");
if (member.name.empty() || member.path.empty()) {
return std::unexpected{make_error("workspace member requires nonempty name and path")};
}
if (!seen.insert(member.name).second) {
return std::unexpected{make_error("duplicate workspace member '" + member.name + "'")};
}
result.members.push_back(std::move(member));
}
return result;
}
} // namespace Void::Build::Config
+143 -8
View File
@@ -36,6 +36,7 @@
#include <array>
#include <charconv>
#include <cstdint>
#include <cstdlib>
#include <filesystem>
#include <format>
#include <iostream>
@@ -504,6 +505,11 @@ struct BuildCmdOptions {
std::optional<std::string> jobs_arg;
std::optional<std::string> remote_cache_arg;
std::optional<std::string> remote_cache_token_env;
std::vector<std::string> members;
std::optional<std::string> changed_since;
std::optional<std::filesystem::path> lock_root;
std::optional<std::filesystem::path> state_dir;
bool publish_editor_selection{true};
bool no_cache{false};
bool locked{false};
bool offline{false};
@@ -587,7 +593,7 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
return 1;
}
auto state = State::StateStore::open(build_root / ".vbs");
auto state = State::StateStore::open(opts.state_dir ? *opts.state_dir : build_root / ".vbs");
if (!state) {
std::cerr << "vbs: " << state.error().message() << '\n';
return 1;
@@ -608,7 +614,7 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
Void::Log::info("Cache", "Using shared remote action cache at {}", remote_cache_url);
}
const auto lock_path = project_root / "vbs.lock";
const auto lock_path = (opts.lock_root ? *opts.lock_root : project_root) / "vbs.lock";
auto pinned_lock = Package::load_pinned_lock(lock_path);
if (!pinned_lock) {
std::cerr << "vbs: " << pinned_lock.error().message() << '\n';
@@ -813,7 +819,8 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
Editor::PublishOptions popts;
popts.project_root = project_root;
popts.build_root = build_root;
popts.update_selection = (*opts.editor_profile == prof_name);
popts.update_selection =
opts.publish_editor_selection && (*opts.editor_profile == prof_name);
popts.reserved_ticket = *reserved_ticket;
popts.sdk_include_dir = fopts.sdk_include_dir;
popts.extra_build_sources = extra_build_sources;
@@ -888,6 +895,130 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
return all_ok ? 0 : 1;
}
int execute_workspace(BuildCmdOptions opts, bool run_tests) {
const std::filesystem::path project_root = std::filesystem::absolute(opts.project_arg);
const std::filesystem::path build_root =
opts.build_arg ? std::filesystem::path{*opts.build_arg} : (project_root / "build");
std::vector<std::filesystem::path> extra_sources;
for (const auto &source : opts.extra_build_sources) {
extra_sources.emplace_back(source);
}
const auto fopts = make_frontend_opts(project_root, build_root, extra_sources);
auto compiled = Config::compile_descriptor(fopts);
if (!compiled) {
std::cerr << "vbs: " << compiled.error().message() << '\n';
return 1;
}
auto workspace = Config::evaluate_workspace(*compiled, fopts);
if (!workspace) {
std::cerr << "vbs: " << workspace.error().message() << '\n';
return 1;
}
if (workspace->members.empty()) {
std::cerr << "vbs: workspace declares no members\n";
return 1;
}
std::map<std::string, std::filesystem::path, std::less<>> member_dirs;
for (const auto &member : workspace->members) {
std::filesystem::path dir = member.path;
if (!dir.is_absolute()) {
dir = project_root / dir;
}
std::error_code ec;
const auto canonical = std::filesystem::weakly_canonical(dir, ec);
if (ec || !std::filesystem::is_directory(canonical)) {
std::cerr << "vbs: workspace member '" << member.name << "' path '" << dir.string()
<< "' is not a directory\n";
return 1;
}
member_dirs[member.name] = canonical;
const std::string env_name = "VBS_WORKSPACE_MEMBER_" + member.name;
(void)::setenv(env_name.c_str(), canonical.c_str(), 1);
}
std::set<std::string> selected;
if (!opts.members.empty()) {
for (const auto &name : opts.members) {
if (!member_dirs.contains(name)) {
std::cerr << "vbs: unknown workspace member '" << name << "'\n";
return 2;
}
selected.insert(name);
}
} else if (opts.changed_since) {
auto git = Platform::resolve_executable("git");
if (!git) {
std::cerr << "vbs: --changed-since requires git in PATH\n";
return 1;
}
Platform::ProcessRequest req;
req.executable = *git;
req.arguments = {"-C", project_root.string(), "diff", "--name-only", *opts.changed_since};
auto proc = Platform::run_supervised(req);
if (!proc || !proc->succeeded()) {
std::cerr << "vbs: git diff --name-only " << *opts.changed_since
<< " failed: " << (proc ? proc->stderr_data : proc.error().message()) << '\n';
return 1;
}
std::size_t pos = 0;
while (pos < proc->stdout_data.size()) {
const auto nl = proc->stdout_data.find('\n', pos);
const auto line = proc->stdout_data.substr(
pos, nl == std::string::npos ? std::string::npos : nl - pos);
if (!line.empty()) {
const auto changed = std::filesystem::weakly_canonical(project_root / line);
std::string best;
std::size_t best_len = 0;
for (const auto &[name, dir] : member_dirs) {
if (Platform::path_is_within(dir, changed) && dir.string().size() > best_len) {
best = name;
best_len = dir.string().size();
}
}
if (!best.empty()) {
selected.insert(best);
}
}
if (nl == std::string::npos) {
break;
}
pos = nl + 1;
}
if (selected.empty()) {
std::cout << "vbs: no workspace members changed since " << *opts.changed_since << '\n';
return 0;
}
} else {
for (const auto &[name, dir] : member_dirs) {
selected.insert(name);
}
}
bool all_ok = true;
for (const auto &member : workspace->members) {
if (!selected.contains(member.name)) {
continue;
}
BuildCmdOptions member_opts = opts;
member_opts.project_arg = member_dirs.at(member.name).string();
member_opts.build_arg = (build_root / "members" / member.name).string();
member_opts.lock_root = project_root;
member_opts.state_dir = build_root / ".vbs";
member_opts.members.clear();
member_opts.changed_since.reset();
// Members must not overwrite each other's project-root compile_commands.json alias.
member_opts.publish_editor_selection = false;
Void::Log::info("Workspace", "[{}] {}", member.name,
run_tests ? "building and testing member" : "building member");
if (execute_build_or_test(std::move(member_opts), run_tests) != 0) {
all_ok = false;
}
}
return all_ok ? 0 : 1;
}
struct CompDbCmdOptions {
std::string project_arg;
std::optional<std::string> build_arg;
@@ -1997,6 +2128,9 @@ int main(int argc, char **argv) {
.option_many("--build-source", "", "Additional build description source",
build_opts.extra_build_sources)
.option("--jobs", "-j", "Maximum parallel compilation/link jobs", build_opts.jobs_arg)
.option_many("--member", "", "Workspace member to build/test", build_opts.members)
.option("--changed-since", "", "Build/test workspace members changed since a git ref",
build_opts.changed_since)
.option("--remote-cache", "", "Shared HTTP action cache URL (or VBS_REMOTE_CACHE)",
build_opts.remote_cache_arg)
.option("--remote-cache-token-env", "",
@@ -2229,11 +2363,12 @@ int main(int argc, char **argv) {
: Void::Log::Level::Info);
ConsoleLogGuard log_guard{log_level};
if (cmd == "build") {
return execute_build_or_test(std::move(build_opts), false);
}
if (cmd == "test") {
return execute_build_or_test(std::move(build_opts), true);
if (cmd == "build" || cmd == "test") {
const bool run_tests = cmd == "test";
if (Config::is_workspace_root(std::filesystem::path{build_opts.project_arg})) {
return execute_workspace(std::move(build_opts), run_tests);
}
return execute_build_or_test(std::move(build_opts), run_tests);
}
if (cmd == "describe") {
return execute_describe_command(describe_opts);
+2
View File
@@ -161,6 +161,8 @@ materialize_dependency_source(const DependencyRecord &dep, const FetchOptions &o
sopts.project_root = canon;
sopts.snapshot_store_dir = options.cache_dir / "path-snapshots";
sopts.materialize = false;
// Generated editor metadata is never a build input and may be an out-of-tree symlink.
sopts.excluded_names.push_back("compile_commands.json");
auto snap = Snapshot::capture_snapshot(sopts, {}, {canon});
if (!snap) {
return std::unexpected{snap.error()};
+114
View File
@@ -28,6 +28,7 @@
#include <cstring>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <thread>
using namespace Void::Build;
@@ -100,6 +101,119 @@ std::filesystem::path locate_vbs_binary() {
} // namespace
VOID_TEST(FullV1Tests, workspace_members_shared_build_and_member_selection) {
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_ws_"};
const auto ws = tmp / "ws";
write_file(ws / "workspace.cpp", R"cpp(#include <Void/Build.hpp>
void workspace(Void::Build::Workspace &ws) {
ws.member("lib", "packages/lib");
ws.member("app", "packages/app");
ws.member("tests", "packages/tests");
}
)cpp");
write_file(ws / "packages" / "lib" / "include" / "core.hpp", "#pragma once\nint ws_core();\n");
write_file(ws / "packages" / "lib" / "src" / "core.cpp",
"#include \"core.hpp\"\nint ws_core() { return 7; }\n");
write_file(ws / "packages" / "lib" / "build.cpp", R"cpp(#include <Void/Build.hpp>
void build(Void::Build::Project &p) {
p.static_library("libcore")
.sources({"src/core.cpp"})
.include_directory("include", Void::Build::Visibility::Public);
}
)cpp");
write_file(ws / "packages" / "app" / "src" / "main.cpp",
"#include \"core.hpp\"\nint main() { return ws_core() == 7 ? 0 : 1; }\n");
write_file(ws / "packages" / "app" / "build.cpp", R"cpp(#include <Void/Build.hpp>
void build(Void::Build::Project &p) {
auto lib = p.workspace_dependency("lib").target("libcore");
p.executable("ws_app").sources({"src/main.cpp"}).link(lib);
}
)cpp");
write_file(ws / "packages" / "tests" / "src" / "test.cpp",
"#include \"core.hpp\"\nint main() { return ws_core() == 7 ? 0 : 1; }\n");
write_file(ws / "packages" / "tests" / "build.cpp", R"cpp(#include <Void/Build.hpp>
void build(Void::Build::Project &p) {
auto lib = p.workspace_dependency("lib").target("libcore");
p.test("ws_test").sources({"src/test.cpp"}).link(lib);
}
)cpp");
auto run_vbs = [&](std::vector<std::string> args) {
Platform::ProcessRequest req;
req.executable = vbs_bin;
req.arguments = std::move(args);
return Platform::run_supervised(req);
};
const auto build_dir = tmp / "build";
auto full = run_vbs({"test", "--project", ws.string(), "--build-dir", build_dir.string()});
Void::Testing::expect(full.has_value() && full->succeeded());
if (!full || !full->succeeded()) {
if (full) {
std::cerr << full->stderr_data << '\n';
}
return;
}
Platform::ProcessRequest app_req;
app_req.executable =
build_dir / "members" / "app" / "profiles" / "debug" / "out" / "bin" / "ws_app";
auto app_run = Platform::run_supervised(app_req);
Void::Testing::expect(app_run.has_value() && app_run->succeeded());
// The workspace root owns the unified lock; members never get their own lockfiles.
std::error_code ec;
Void::Testing::expect(std::filesystem::exists(ws / "vbs.lock", ec));
Void::Testing::expect(!std::filesystem::exists(ws / "packages" / "app" / "vbs.lock", ec));
Void::Testing::expect(!std::filesystem::exists(ws / "packages" / "lib" / "vbs.lock", ec));
const auto selected_build = tmp / "build_selected";
auto selected = run_vbs({"build", "--project", ws.string(), "--build-dir",
selected_build.string(), "--member", "app"});
Void::Testing::expect(selected.has_value() && selected->succeeded());
Void::Testing::expect(std::filesystem::exists(selected_build / "members" / "app" / "profiles" /
"debug" / "out" / "bin" / "ws_app"));
Void::Testing::expect(!std::filesystem::exists(selected_build / "members" / "tests"));
// --changed-since selects only the member owning the changed file.
auto git = Platform::resolve_executable("git");
Void::Testing::expect(git.has_value());
if (git) {
auto run_git = [&](std::vector<std::string> args) {
Platform::ProcessRequest req;
req.executable = *git;
req.arguments = {"-C", ws.string()};
req.arguments.insert(req.arguments.end(), args.begin(), args.end());
return Platform::run_supervised(req);
};
auto init = run_git({"init"});
Void::Testing::expect(init.has_value() && init->succeeded());
auto added = run_git({"add", "-A"});
Void::Testing::expect(added.has_value() && added->succeeded());
auto committed = run_git({"-c", "user.email=ws@example.invalid", "-c",
"user.name=Workspace", "commit", "-m", "init"});
Void::Testing::expect(committed.has_value() && committed->succeeded());
write_file(ws / "packages" / "app" / "src" / "main.cpp",
"#include \"core.hpp\"\nint main() { return ws_core() == 7 ? 0 : 2; }\n");
const auto changed_build = tmp / "build_changed";
auto changed = run_vbs({"build", "--project", ws.string(), "--build-dir",
changed_build.string(), "--changed-since", "HEAD"});
Void::Testing::expect(changed.has_value() && changed->succeeded());
Void::Testing::expect(std::filesystem::exists(
changed_build / "members" / "app" / "profiles" / "debug" / "out" / "bin" / "ws_app"));
Void::Testing::expect(!std::filesystem::exists(changed_build / "members" / "tests"));
}
}
// === Plan 09: CompDB projection, selection ticket races, user-file preservation, recovery ===
VOID_TEST(FullV1Tests, compdb_projection_ticket_races_and_user_file_preservation) {
Void::FileSystem::TempDir tmp{"vbs_compdb_"};