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

13 KiB

title, description, section, badge, order, tags, updated
title description section badge order tags updated
Declaring Builds in C++26 build.cpp entry points, targets, usage requirements, custom actions, profiles, modules, shaders and install rules Build Descriptions build.cpp 1
build.cpp
sdk
targets
profiles
visibility
modules
shaders
2026-12-06

Declaring Builds in C++26

A VBS project is ordinary C++26. The description is compiled once on the host, then executed out of process for each resolved profile. The program emits a versioned (schema_version: 1) JSON description that the engine validates and lowers; it never calls back into the engine while declaring targets.

#include <Void/Build.hpp>

void build(Void::Build::Project &project) {
    project.dependencies_file("vbs.deps.toml");

    auto core = project.static_library("core");
    core.cxx_standard(Void::Build::CxxStandard::Cxx26)
        .sources(project.glob("src/core/**/*.cpp"))
        .include_directory("include", Void::Build::Visibility::Public);

    auto app = project.executable("app");
    app.sources({"src/main.cpp"}).link(core).install("bin");

    auto tests = project.test("app_tests");
    tests.sources({"tests/app_test.cpp"}).link(core).label("unit");
}

What the engine discovers

File Role
build.cpp Required for a single-package project. Must define void build(Void::Build::Project &).
build.profiles.cpp Optional. Must define void profiles(Void::Build::Profiles &); without it the default profiles are used.
build-support/**/*.{cpp,cc,cxx} and .hpp Optional helpers. C++ implementation files are compiled into the host description; headers are discovered through depfiles. Sorted deterministically.
workspace.cpp Marks a workspace root and defines void workspace(Void::Build::Workspace &).
vbs.deps.toml Optional declarative dependency manifest, when referenced by project.dependencies_file(...).
vbs.lock Generated lockfile; never edited by hand.
compile_commands.json, .vbs/, build/ Generated editor and build state; ignored by convention.

Discovery is filesystem-based and works without .git. Additional description sources can be passed with vbs build --build-source FILE; the same files may be declared in a package manifest so exported sources remain buildable.

:::callout{type="info" title="Host compilation is separate from target evaluation"} build.cpp is compiled with the fixed SDK and the host compiler before any project dependency is resolved. It may use the C++ standard library, your own build-support helpers, project.context(), and environment variables. It must not depend on a target toolchain or on files produced by the build. :::

Profiles and context

void profiles(Profiles &) declares named profiles once. Profiles::resolve(name, compiler_override, os, architecture) produces an immutable ProfileContext; project.context() exposes it while the description evaluates.

void profiles(Void::Build::Profiles &profiles) {
    profiles.add("debug", {"-O0", "-g"});

    Void::Build::ProfileDescription release;
    release.name = "release";
    release.parent = "debug";
    release.compile_options = {"-O3", "-DNDEBUG"};
    release.lto = Void::Build::LtoMode::Thin;
    profiles.define(release);

    Void::Build::ProfileDescription asan;
    asan.name = "asan";
    asan.parent = "debug";
    asan.sanitizers = {Void::Build::Sanitizer::Address, Void::Build::Sanitizer::Undefined};
    profiles.define(asan);
}

The default profiles when no build.profiles.cpp exists are:

Profile Compile options
debug -O0 -g
release -O3 -DNDEBUG

ProfileDescription also accepts link_options, defines, compiler, c_standard, cxx_standard, sysroot, compiler_path, reproducibility_epoch and nondeterministic. Inheritance is resolved transitively; unknown parents, self-inheritance and cycles are explicit errors.

ProfileContext carries name, compiler, os, architecture, compile_options, link_options, defines, c_standard, cxx_standard, lto, sanitizers, sysroot, compiler_path, reproducibility_epoch and nondeterministic.

:::callout{type="tip" title="Ordinary C++ conditionals are the point"} Because the description is compiled C++, context-sensitive declarations use normal if/else rather than generator expressions. os is the host system name (Linux) or the --target-os spelling (windows), so compare it case-insensitively:

#include <Void/Text/Str.hpp>

if (Void::Str::to_lower_ascii(project.context().os) == "windows") {
    app.link_option("-lws2_32");
}
if (project.context().compiler == Void::Build::CompilerFamily::Clang) {
    app.compile_option("-Wextra-semi");
}

:::

Targets

There are seven TargetKinds, created by these project methods:

Method Kind Primary output
project.executable(name) Executable out/bin/<name> (.exe on Windows targets)
project.static_library(name) StaticLibrary out/lib<name>.a
project.shared_library(name) SharedLibrary out/lib<name>.so (.dll on Windows targets)
project.header_only_library(name) HeaderOnly No compiled artifact; exports usage requirements
project.object_library(name) ObjectLibrary Object files linked into consumers
project.custom_action(name) CustomAction Declared outputs under gen/ unless absolute
project.test(name) Test Executable in out/bin/ that vbs test runs

project.shader_bundle(name) is a helper that creates a CustomAction with shader sources and per-source SPIR-V outputs.

Target names must be non-empty and unique. Handles validate ownership and lifetime; a stale handle or a link across projects throws instead of recording an invalid edge.

Sources

target.sources({"src/main.cpp", "src/window.cpp"});          // explicit files
target.sources(project.glob("src/**/*.cpp"));                 // glob
target.sources(Void::Build::SourceSet::file("src/one.cpp"));
target.sources(Void::Build::SourceSet::module_interface("src/core.cppm"));
target.module_sources(Void::Build::SourceSet::module_partition("src/part.cppm"));
target.header_unit("include/legacy.hpp");
target.conventional_sources();                                // src/, source/, include/
  • project.glob(...) returns a symbolic SourceSet; expansion happens during graph lowering against the validated project root.
  • conventional_sources() scans src/ and source/ recursively for C++ and assembly sources, and adds include/ as an include directory. It does not add files from build/, .vbs/, build-support/, .git/ or editor metadata.
  • module_interface, module_partition and header_unit mark module-aware sources for the P1689 scanner.
  • $GEN/<path> refers to the profile's generated directory (build/profiles/<profile>/gen). Generated sources and headers produced by a custom_action can be consumed with $GEN/... or gen/....

C and C++ sources share one target graph. .c files use the C driver and c_standard(...); .cpp files use the C++ driver and cxx_standard(...). .s and preprocessed .S assembly compile through the C driver without C/C++ standard flags, LTO or sanitizers, and are excluded from unity and module scanning.

Usage requirements and visibility

Every scoped requirement takes a Visibility:

Visibility Applied to the declaring target Exported to consumers
Private Yes No
Public Yes Yes
Interface No Yes
core.include_directory("include", Void::Build::Visibility::Public)
    .define("CORE_EXPORTS", Void::Build::Visibility::Private)
    .compile_option("-Wall")
    .link_option("-pthread", Void::Build::Visibility::Public);
  • Include directories, defines and compile options follow the table exactly.
  • A Private static-library dependency still contributes its static archives and transitive link inputs to the final linker; this preserves the link closure even when the dependency is not part of the public API. Consumers do not inherit its compile requirements.
  • Link order is preserved: a dependency's own libraries come before its transitive libraries. The engine never sorts the link line.
  • Imported targets from a dependency are linked with target.link(dep.target("Exported::Name")); a missing imported target is a hard error, never silently dropped.
  • depends_on(other) adds action ordering without linking. Use it for generated headers and code generators.

Compilation features

Method Effect
c_standard(CStandard) Default, C11, C17, C23
cxx_standard(CxxStandard) Default, Cxx17, Cxx20, Cxx23, Cxx26
precompiled_header(path) Builds and uses a PCH for compatible sources
unity_build(enabled, batch_size) Batches TUs deterministically; excludes .c, modules and per-file overrides
lto(LtoMode) None, Full, Thin
sanitizer(Sanitizer) Address, Undefined, Thread, Memory, Leak
per_file_option(source, opt) Per-TU flag; excluded from unity batches
enabled(false) Keeps the target declared but does not lower it

Incompatible sanitizer combinations are rejected during description validation or graph lowering (for example Memory with Address, or Thread with Leak). Profile sanitizers and target sanitizers combine.

Custom actions and shaders

auto generate = project.custom_action("generate_table");
generate.command({"python3", "tools/gen.py", "--out", "$GEN/table.hpp"})
    .inputs({"tools/gen.py", "data/table.json"})
    .outputs({"table.hpp"})
    .working_directory(".")
    .env("GEN_MODE", "strict");

core.include_directory("$GEN", Void::Build::Visibility::Private)
    .depends_on(generate);

A custom action must declare command() and at least one output. Relative outputs are placed under the profile's generated root; relative inputs are resolved against the project root. The command line expands $GEN, $PROJECT_ROOT and $BUILD_DIR. Deterministic actions receive SOURCE_DATE_EPOCH, TZ=UTC and LC_ALL=C; declaring nondeterministic() disables cache and incremental reuse.

Shader bundles compile each declared source to SPIR-V:

auto shaders = project.shader_bundle("shaders");
shaders.shader("shaders/tri.vert")
       .shader("shaders/tri.frag", Void::Build::ShaderLanguage::Glsl)
       .shader("shaders/particles.comp", Void::Build::ShaderLanguage::Slang,
               Void::Build::ShaderStage::Compute);

The toolchain is discovered from PATH: glslangValidator for GLSL/HLSL, slangc for Slang, and dxc for HLSL. A missing compiler for a declared shader is an explicit error.

Installation rules

app.install("bin");
core.install("lib");
project.install_directory("include", "include");
project.install_file("LICENSE", "share/doc/core/LICENSE", "docs");

install(destination, component) uses the target's primary artifact and default destination when omitted (executables to bin, libraries to lib). install_file and install_directory declare non-target artifacts. Components are selected with vbs install --component NAME.

Tests, labels, resources and fixtures

auto db_test = project.test("db_integration");
db_test.sources({"tests/db.cpp"})
       .link(core)
       .label("integration")
       .resource("database")
       .fixture_setup("database")
       .fixture_required("database");

auto db_cleanup = project.test("db_cleanup");
db_cleanup.label("fixture").fixture_cleanup("database");
  • label(...) lets vbs test --label NAME select tests; labels are repeatable and ORed.
  • resource(...) serializes tests that share a resource, even under higher --jobs.
  • Fixtures follow the CTest model: a setup test runs before its users, a required fixture pulls the setup in automatically, and cleanup runs after every user. If setup fails, dependents are skipped.

Validation and deterministic output

Before any action runs, the engine rejects:

  • duplicate target names, unknown prerequisite/link targets and target cycles;
  • output path collisions and outputs that overlap editable source files outside the build directory;
  • invalid standards, incompatible sanitizers, empty names and contradictory declarations;
  • Windows case-insensitive output collisions (Tool.exe vs tool.exe) and reserved device names (CON, NUL, COM1, …).

The description serializer validates every emitted string as UTF-8 and emits deterministic JSON, so identical declarations produce identical description bytes.

Next steps