--- title: Configuration and Graph Lowering description: How build.cpp is discovered, compiled and evaluated, how profiles resolve, and how targets become validated actions section: Configuration & Execution badge: internals order: 1 tags: [internals, frontend, descriptor, profiles, graph, actions, modules, unity, pch] updated: 2026-12-06 --- # Configuration and Graph Lowering The frontend turns ordinary C++ into one immutable JSON description per profile; the graph layer turns that description plus a toolchain and snapshot into one immutable action graph. Neither step executes project targets. ## Description discovery `discover_config_sources()` is filesystem-only: - requires `build.cpp` **or** `workspace.cpp` at the project root; - adds both if present (a workspace root takes precedence for orchestration); - adds optional `build.profiles.cpp`; - recursively globs `build-support/**/*.cpp|.cc|.cxx`, sorted; - adds explicit `--build-source` files, resolved against the project root; - de-duplicates by normalized path; - never consults Git. Headers are not enumerated up front. The compile step uses `-MMD` depfiles, and the discovered headers are recorded beside the descriptor for cache validation. ## Descriptor compilation The descriptor is a host executable built against the fixed SDK: ```text /.vbs/config/ ├── Driver.cpp ├── descriptor_ ├── descriptor_.headers.json ├── obj_/ ├── identity_cache.json └── seed.lock ``` `seed_identity_hash` covers: - the host compiler path and its SHA-256; - the generated driver source; - `/Void/Build.hpp` and the SDK library (or SDK sources); - every configuration source's path and SHA-256. Large files are hashed once and memoized by size + mtime in `identity_cache.json`. A cache hit also revalidates every previously discovered header (content hash; stat fingerprint short-circuit). If `build.profiles.cpp` is absent, the generated driver supplies `default_profiles()`. If `build.cpp` or `workspace.cpp` is absent, the driver supplies a throwing stub so the corresponding mode fails clearly. Each translation unit is compiled with roughly: ```text g++ -std=c++26 -O1 -I -I -MMD -MF -c -o ``` and linked into the descriptor. The host compiler defaults to `g++`; `--compiler gcc|clang` selects the **target** compiler and does not change the host compiler. ## Evaluation protocol The descriptor runs out of process in `profiles`, `describe` or `workspace` mode. It writes a versioned JSON result to a private per-request file under `/.vbs/config/eval/`. The parent enforces: - bounded reads (16 MiB for profiles/workspace, 64 MiB for a project description); - protocol version, request id and context hash checks; - UTF-8 validation; - a default 30 s evaluation timeout. stdout and stderr are logs, not protocol. A `build.cpp` that prints arbitrary text cannot corrupt the result. ## Profile resolution `Profiles::resolve(name, compiler_override, os, architecture)` walks the parent chain: - unknown names, unknown parents, self-inheritance and cycles throw; - ancestor fields apply first, then child fields; - scalar fields are last-writer-wins; - compile options, link options and defines are appended; - sanitizers are de-duplicated; - the compiler override applies last. `default_profiles()` contains only: | Profile | Compile options | | --- | --- | | `debug` | `-O0 -g` | | `release` | `-O3 -DNDEBUG` | No `-std`, PIC, LTO or sanitizer flag is added by default. `CStandard::Default` and `CxxStandard::Default` mean **no standard flag** unless a target or profile sets one, except module translation units, which force C++20 when the profile is Default. The build root defaults to `/build`, but a relative `--build-dir` is resolved against the current working directory, not the project root. A typical CI invocation passes an absolute path. When multiple profiles are requested, `--editor-profile` must name one of them; this is checked before descriptor work. ## From description to graph The pipeline after evaluation is: ```text merge C++/TOML dependencies → validate/publish lock → materialize → import providers → capture snapshot → lower targets to actions → execute selected closure ``` `lower_project_graph()` receives the description, toolchain capabilities, project/build roots, an optional snapshot and imported targets. It produces `BuildGraph` with topologically ordered actions and no filesystem mutation except module scanning. ### Target validation - duplicate target names; - unknown prerequisite or local link targets; - target-level cycles, reported as a chain; - incompatible sanitizer combinations; - missing explicit sources, header units or shader sources; - custom actions without a command or output; - duplicate output paths and outputs overlapping editable source files outside the profile build tree; - Windows reserved device names and case-insensitive output collisions. `enabled(false)` excludes a target from default selection, but its actions are still lowered and can be pulled in as prerequisites. Unknown `--target` names are errors. ### Usage propagation For each local link: - compile usage from the dependency is applied when the link visibility is `Public` or `Private` (not `Interface`); - it is re-exported when the link visibility is `Public` or `Interface` (not `Private`); - link inputs are always added in declaration order, dependency first, then transitive libraries; - private dependencies of static libraries, header-only libraries and object libraries still propagate their link closure to final consumers; private dependencies of executables and shared libraries do not. Imported targets follow the same compile-usage rules, with a link closure supplied by the provider. A missing imported target is an error. ### Actions `ActionKind` values are `Compile`, `PrecompiledHeader`, `HeaderUnit`, `ModuleScan`, `ModuleBmi`, `Archive`, `Link` and `Custom`. `ModuleScan` exists in the enum but scanning currently runs synchronously during graph lowering, not as a scheduled action. Action IDs are deterministic: ```text compile:: pch: headerunit:: bmi:: archive: link: custom: shader::: ``` Each action carries argv, environment, working directory, optional response file, declared inputs/outputs, depfile, logical/physical source/output paths, include dirs, defines, options, standard/LTO/sanitizer/PIC/PCH metadata, dependency action ids, nondeterminism and an action key. ### Output layout ```text /profiles// ├── .profile.lock ├── gen/ # custom action outputs and $GEN ├── obj//_.o + .d ├── obj//pch/
.gch ├── bmi//... # .gcm/.pcm, module mappers ├── modscan// ├── unity// ├── rsp/ ├── shaders// └── out/ ├── lib.a ├── lib.so # POSIX shared library ├── .dll # Windows shared library, directly in out/ └── bin/[.exe] ``` A relative custom-action output goes under `gen/`; an absolute output must stay inside the profile build tree. The scheduler deletes a pre-existing static archive before `ar`, so removed objects do not linger in archive membership. ### Modules, header units, unity and PCH - The P1689 scanner runs during lowering. GCC uses `-fdeps-format=p1689r5`; Clang uses `clang-scan-deps` with probed system include directories. - Module collation rejects duplicate providers, self-imports, missing providers and cycles. - BMIs are stored per target and profile identity. GCC uses a module mapper; Clang emits `.pcm` through a separate BMI action and compiles the `.pcm` to an object. - Header units are lowered explicitly. Their default standard is C++20 when the profile standard is Default. - Unity batches default to 8 and exclude `.c`, assembly, module sources and any source with a per-file option. - PCH lowering exists, but capability probing and end-to-end coverage are weak in 1.0.0; treat PCH as experimental and verify it for your toolchain. ### Determinism inputs The graph applies a reproducibility epoch and canonical path prefixes: - `SOURCE_DATE_EPOCH=`, `TZ=UTC`, `LC_ALL=C` on compile/custom/shader actions; - snapshot root → project root and profile build dir → `/vbs-build` prefix maps; - GCC `-frandom-seed=` when deterministic; - deterministic archive mode (`ar rcsD`). Prefix maps are capability-checked. A compiler that supports none of the required mapping flags fails compilation instead of silently emitting non-reproducible objects. Link actions get `TZ`/`LC_ALL`, but no canonical output mtime in 1.0.0. ## Current limits - Action keys include the whole-project `snapshot_id`, so a source edit re-keys every action; only a true no-op is fully cached. Single-file incremental reuse is not implemented. - Snapshot lookup guards and `is_snapshot_fresh()` exist but are not populated/used by the CLI build path. - `ModuleScan` is not a DAG action; scans are serial during lowering. - PCH is unprobed; MemorySanitizer and LeakSanitizer requests are not capability-checked. - Daemon builds lower without a snapshot, so their action keys differ from CLI builds. Next: [trace snapshots, scheduling and state](/build-system/developer/snapshots-and-execution).