Files
Build-System/docs/build-system/consumer/workspaces.md
T

5.9 KiB

title, description, section, badge, order, tags, updated
title description section badge order tags updated
Multi-Package Workspaces Declare members in workspace.cpp, share one lockfile and CAS, link across members, and select affected builds Workspaces workspace.cpp 1
workspace
monorepo
members
changed-since
lockfile
cas
2026-12-06

Multi-Package Workspaces

A workspace root is a directory containing workspace.cpp instead of build.cpp. It lists member projects; each member keeps its own build.cpp, profiles and targets, while the workspace shares one vbs.lock and one build cache.

#include <Void/Build.hpp>

void workspace(Void::Build::Workspace &workspace) {
    workspace.member("lib", "packages/lib");
    workspace.member("app", "packages/app");
    workspace.member("tests", "packages/tests");
}

Member names are unique and non-empty. Paths may be relative to the workspace root or absolute; every member must exist and resolve to a directory. Members build sequentially in declaration order; a failure does not stop later members, but the final exit code is 1.

Workspace-wide --target NAME requires every selected member to declare that target; a name missing from one member fails the run.

Build and select members

vbs build                           # every member, in declared order
vbs test                            # build and test every member
vbs build --member app              # one member
vbs test --member app --member lib  # several members
vbs build --changed-since origin/main

--changed-since REF runs git diff --name-only REF from the workspace root and selects the deepest member containing each changed path. Only tracked changes are considered; untracked files are not included. A change outside every member selects nothing and exits successfully with vbs: no workspace members changed since REF. Selection is by member directory, not by target. --member takes precedence over --changed-since; both flags are silently ignored for a non-workspace project.

What is shared and what is not

Workspace orchestration is implemented for vbs build and vbs test at the root. Root-level vbs describe, graph, ide, compdb*, deps, install and watch do not evaluate a workspace; they see the generated build() stub and fail with “this descriptor declares no build() entry point”. Use member-scoped daemon requests (vbs daemon describe --member, vbs daemon ide query --member, and so on) or run the command inside a member with its VBS_WORKSPACE_MEMBER_* environment supplied.

Resource Scope
vbs.lock Shared at the workspace root
Build state / CAS Shared <workspace>/build/.vbs
Profiles Each member declares its own; the same profile name builds with each member's description
Outputs Per member under build/members/<name>/profiles/<profile>/
Editor selection Members do not steal the workspace root compile_commands.json alias

A workspace member build is internally a normal project build with:

  • project_root set to the member directory;
  • build_root set to build/members/<name>;
  • lock_root set to the workspace root;
  • state_dir set to the workspace build/.vbs.

Member outputs therefore look like:

build/
├── .vbs/                                  # shared state and CAS
└── members/
    ├── lib/profiles/debug/out/libcore.a
    ├── app/profiles/debug/out/bin/app
    └── tests/profiles/debug/out/bin/tests

vbs clean at the root removes only build/profiles and build/compile_commands.json; member outputs under build/members/** survive unless vbs clean --all removes the whole build root.

A member declares a workspace dependency by name:

void build(Void::Build::Project &project) {
    auto lib = project.workspace_dependency("lib");
    auto app = project.executable("app");
    app.sources({"src/main.cpp"})
       .link(lib.target("core"));
}

During member evaluation vbs exports VBS_WORKSPACE_MEMBER_<member> with the canonical member directory. workspace_dependency records that path as a native builder dependency, so the target is imported through the same native provider path as an external build.cpp dependency. Calling it outside a workspace, or naming an undeclared member, is an explicit error.

The exported target name is the dependency's own target name. In the example, the lib member must declare a target named core.

Daemon and workspaces

The daemon understands workspace roots:

  • vbs daemon describe returns a bounded per-member summary and accepts --member to describe one member.
  • vbs daemon build with no member builds every member in declared order against the warm state store and returns per-member outcomes plus aggregate counts. The wire protocol also accepts a member field for a member-scoped build.
  • vbs daemon test builds and runs declared tests, including workspace-wide runs.
  • vbs daemon ide query|generate and vbs daemon compdb export accept --member; a workspace root requires it, while a plain project rejects it.

Member-scoped daemon IDE requests write editor metadata inside the member directory (for example packages/app/.clangd), not at the workspace root.

Practical rules

:::callout{type="tip" title="Keep member ownership clear"}

  • Give each member a unique target namespace; cross-member references use the member's exported target name, not a path.
  • Keep shared tooling in its own member and depend on it with workspace_dependency(...) instead of relative include_directories.
  • Use --changed-since in CI to avoid rebuilding unaffected members; use explicit --member flags when a pipeline already knows the affected set.
  • The workspace root has no build() entry point. Running vbs build there is workspace orchestration, not a hidden root target graph. :::

Next: use the everyday CLI or wire an editor and daemon.