6.2 KiB
Bootstrap declaration SDK
Status: implemented declaration subset, schema version 1. This documents the public header and the compiled example, not a completed native build engine. The SDK is experimental; future incompatible protocol changes must change its schema version.
Entry points and context
void build(vbs::Project&) declares one concrete graph for one effective profile.
void profiles(vbs::Profiles&) declares available profiles. The current example
defines both and links them into vbs_describe; automatic loading of arbitrary
projects and optional-profile fallback belong to the future frontend.
vbs::default_profiles() contains debug (-O0, -g) and release (-O3, -DNDEBUG).
Profiles::add(name, options) adds a distinct profile. Profiles::resolve(name, compiler, os, architecture) returns a ProfileContext with those target facts and
the profile's options. Unknown names and invalid contexts throw
std::invalid_argument.
Project::context() exposes name, compiler family, OS, architecture and effective
compile options. The bootstrap harness accepts --profile debug|release and
--compiler gcc|clang. OS and architecture come from its CMake configuration.
Selecting Clang here does not prove a Clang build or probe a target toolchain.
Targets and source membership
Project::executable(name) and static_library(name) return handles to new target
records. Names must be nonempty and unique in the target namespace. Other target
kinds, cycle detection, usage propagation and command lowering are planned.
| Operation | Recorded data |
|---|---|
target.sources({"src/main.cpp"}) |
Explicit source files |
target.sources(project.glob("src/*.cpp")) |
A symbolic glob |
target.include_directory("include", visibility) |
Include path and visibility |
target.compile_option("-Wall") |
An ordered compile option |
target.link(other, visibility) |
A local target reference |
target.link(dependency.target("Name::Target"), visibility) |
An imported target reference |
Visibility values are private_, public_, interface_; the default is private.
Source paths/patterns are retained without filesystem access. SourceSet::file
and SourceSet::glob are also available. Repeated operations append records;
semantic graph validation beyond the declaration invariants is future work.
Dependencies and options
Project::dependency(alias) creates a unique dependency handle. It records one of:
.git(url, vbs::Commit{sha}): a nonempty URL and an exact 40-hex-digit revision..package(id, range): a nonempty package identity and version constraint string.
.cmake(options) selects the CMake builder for a source dependency. Options retain
string, boolean or signed 64-bit integer types through vbs::OptionValue. Out-of-range
integers, empty option names and contradictory source/builder declarations fail.
Package range syntax is recorded but is not parsed or solved in this milestone.
Imported target names are symbolic; the future provider validates that they exist. An unset dependency source is permitted during declaration construction but fails when serializing a complete project. Source downloads, CMake execution, TOML and other providers are outside the implemented SDK.
Ownership and failures
Project cannot be copied or moved. Target/dependency handles store a weak owner
identity and index, so adding more records does not invalidate handles. Cross-project
links and operations after owner destruction throw. An imported target also carries
its dependency's owner identity.
record(), targets(), dependencies() and Profiles::records() expose borrowed
const views. Do not retain element references across container growth or after owner
destruction. Stable handles do not imply stable references into vectors.
Declaration errors are exceptions; the example harness catches them, prints a diagnostic and exits 2. Successful output is only JSON on stdout. The SDK is intended for one configuration evaluation at a time; it does not promise concurrent mutation. Ordinary user C++ executes as trusted code without a sandbox.
JSON protocol
Project::to_json() emits a deterministic object with these fields:
| Field | Shape |
|---|---|
schema_version |
Integer 1 |
profile |
name, compiler, os, architecture, ordered compile_options |
targets |
Ordered target records |
dependencies |
Ordered dependency records |
Each target has name, kind (executable or static_library), sources
(kind: file/glob, path), include_directories (path, visibility),
compile_options and links. A link has kind (local/imported), target,
dependency (empty for local links) and visibility (private/public/interface).
Each dependency has name, source, builder and options. A Git source has
kind: "git", location and revision; a package source has kind: "package",
package and version. Options are a key-sorted JSON object with their native
string/bool/integer types. An unspecified builder is the empty string.
Declaration order is preserved; string escaping covers quotes, backslashes and
control characters. All strings, including keys, must be valid UTF-8 at serialization.
to_json() preserves valid Unicode and throws std::invalid_argument on malformed
UTF-8, including overlong sequences, surrogate encodings and values above U+10FFFF.
Declaration methods may record raw bytes, but they cannot cross the JSON boundary
without this validation. Non-UTF-8 filesystem names therefore require an explicit
future path-encoding policy; they are not silently replaced or reinterpreted.
This protocol currently describes inputs; it contains no resolved
packages, expanded files, actions, build results or capability claims.
Tests
vbs_sdk_tests uses Void::Testing. CTest checks the complete suite, named registration,
CLI exit/output behavior and the four runtime contexts. The JSON test roundtrips
through Void::Json::Strict; CMake independently parses example output. Registration
checks ensure the aggregate test cannot pass merely because no SDK cases were found.
See verification for actual commands and results, and plan 01 for milestone acceptance.