Files
faumaray 3cac890ce9 bootstrap
Signed-off-by: faumaray <faumaray@gmail.com>
2026-11-25 01:32:43 +03:00

181 lines
11 KiB
Markdown

# Architecture and cross-subsystem contracts
Status: approved design; the initial implementation is the bootstrap only.
See [requirements](REQUIREMENTS.md), [delivery graph](README.md), and the
[preflight record](../agent-workflow/PREFLIGHT.md). Proposed types and commands below
are future contracts unless README explicitly lists them as implemented.
## Layers and control flow
1. The CLI selects a project/build root, requested profiles and targets.
2. A seed recipe captures configuration sources and builds a host executable from
build.cpp, optional build.profiles.cpp and build-support helpers.
3. Profile discovery returns declared profiles; the engine resolves inheritance,
installed toolchains and capabilities.
4. The same host executable evaluates build.cpp separately for each effective
ProfileContext. It emits a versioned declarative graph, not engine callbacks.
5. The resolver validates or creates the lock and imports dependency interfaces.
6. The engine captures the relevant source/include namespace, then lowers targets
into actions, scans module dependencies and orders generated prerequisites.
7. The scheduler executes only required actions against immutable inputs. Outputs
become immutable artifacts after validation; successful state references them.
8. Editor projection derives a per-profile compilation database from the configured
graph. Selection/publication does not wait for every target to compile.
9. Watch drivers request new reconciliations. They do not introduce another
invalidation algorithm or silently bypass dependency restrictions.
The configuration executable is compiled using the fixed installed SDK and local
helpers. A project dependency cannot be required just to compile its declaration.
The host compiler, target compiler and build-machine tools are separate identities.
## Core records
| Record | Meaning and owner |
| --- | --- |
| ProfileDefinition / ProfileContext | User declarations versus resolved compiler/platform/options facts; frontend/toolchain |
| ProjectDescription | Targets, source selections, symbolic dependencies and context; configuration frontend |
| Target / UsageRequirements | Product kind, compile/link visibility, ordered requirements; graph layer |
| SourceSet / NamespaceObservation | Explicit paths or selector membership, symlinks and absence/lookup guards; input layer |
| InputSnapshot | Immutable manifest and materialized captured bytes with deterministic metadata; snapshot layer |
| ToolchainIdentity | Driver/helper/sysroot identities, capabilities and relevant environment; toolchain layer |
| Action / Artifact | Typed argv/env/cwd, inputs, outputs, prerequisites and success identity; execution layer |
| ImportedTarget | Consumer requirements, artifacts, configuration mapping and freshness obligations; provider |
| ResolvedGraph / LockRevision | Exact package graph per profile/build-target context and immutable lock payload; packages |
| GraphGeneration / EditorGeneration | Validated immutable descriptions and editor projections; metadata layer |
| SelectionTicket | Project-wide ordering of explicit/implicit editor selection; editor coordinator |
Shared schemas and public headers have one owner per wave. Freeze their versions
before parallel dependent implementation; changes invalidate affected task contracts.
## Profiles and paths
One build root contains profiles/<profile-id>/ with independent mutable outputs and
generation directories. Internal state and immutable CAS live below .vbs/ in that
build root. Project-local .vbs/ coordinates the selected editor build root/profile.
Source, build and package paths have distinct logical namespaces.
Serialize execution within a profile initially. Different profiles may execute
concurrently under one job budget. Never share mutable object files, BMIs, PCHs,
response files, provider build trees or generated headers between incompatible contexts.
Configuration helpers are discovered by filesystem selection, not git ls-files.
Their content and membership enter the seed compilation identity; package source
manifests retain them. Optional profile sources are discovered before the seed build,
so no package-resolution cycle is needed to find profile definitions.
## Snapshots and freshness
Capture declared source/include/search roots, source membership, relevant metadata
and symlink resolution. Track absent candidates that could change include/library
lookup. Depfiles alone are insufficient for a newly created shadowing header.
Compiler helpers, sysroots and immutable external roots require an explicit identity.
Private copies or isolated reflinks materialize inputs. Never hardlink mutable source
files. Revalidate the captured namespace/contents before sealing; bounded retries
report an unstable tree. This freezes admitted bytes; without a filesystem primitive
or cooperating writers it does not prove a single atomic instant across every file.
Generated output sets are staged, validated and sealed before dependents execute.
Opaque actions and undeclared I/O are outside the complete-input guarantee and cannot
reuse results as if their inputs were fully modeled. C++ descriptions are trusted
native code; process isolation and snapshots are not a sandbox.
A reproducibility epoch (default zero) is part of action identity. Canonicalize
snapshot timestamps, use SOURCE_DATE_EPOCH/TZ/locale policies and capability-tested
path maps. Include other supported observable metadata in identity. Explicit
wall-clock/nondeterministic modes disable both cache and incremental reuse for
affected actions. Test __DATE__, __TIME__, __TIMESTAMP__, __FILE__, __BASE_FILE__
and source-location behavior against uncached execution.
## Publication, persistence and cancellation
Successful process exit is necessary but not sufficient: validate required outputs,
dependency metadata and discovered ordering before recording reusable success.
No output may have multiple producers or overlap editable source paths.
Removed source objects must disappear from archive membership.
Use transactional state behind a Void::Sqlite adapter after its guarantees have
been verified. Publish complete artifact/generation objects before committing
references. Recover orphaned objects or stale filesystem pointers conservatively.
SQLite authority and filesystem projections must have a replayable recovery rule.
Never hold a global database transaction across a compiler or foreign tool.
Coordinate per-key build claims without recursive deadlocks; diagnose dependency
cycles and re-entry into the same active context. Cancellation stops scheduling,
terminates owned process groups, reaps children and withholds success publication.
The pinned Void process API needs additional handling when its group leader exits
before descendants; test that exact case instead of assuming group cleanup.
## Editor view
Retain exact physical execution records. EditorCommand is an explicit projection
onto editable source paths and compatible immutable generated views. Rewrite typed
path operands, including response-file projections; do not blindly replace strings
inside definitions or unknown flags. Path-sensitive binary artifacts cannot be
relocated on faith: include physical/toolchain identity unless proven safe.
Per-profile compile_commands.json covers configured enabled targets, even when a
build selects only one. Include host-description commands where tooling can represent
them. Standard JSON arguments are preferred to shell command strings.
Compilation-database validity is separate from clangd support for compiler extensions.
A single-profile build reserves a ticket and publishes selection after successful
configuration. Compilation failure does not undo it. Multi-profile requests require
--editor-profile from the selected profiles. Manual use creates a newer ticket.
Watchers update generations but never steal selection. Revision checks stop late
work from publishing over a newer request. Atomic pointers expose complete generations;
unrelated user-owned project-root files are never overwritten.
## Watch modes
Full build/watch may configure and build dependencies. compdb watch may rebuild and
evaluate trusted local descriptions and run known native probes/scanners, but reads
only validated cached foreign metadata and existing locked package data. It does not
fetch, update a lock, run CMake configure/Meson setup/Conan install or run generators.
User C++ can have its own side effects; no sandbox claim is made.
Invalid descriptions, stale provider metadata or missing generated inputs produce
explicit stale/readiness diagnostics. Keep a previous valid database identifiable as
previous, never fabricate current commands. Valid source-set changes can publish
before target compilation succeeds. Events are hints; periodic content/namespace
reconciliation and overflow recovery provide correctness.
## Package and foreign boundaries
C++ and TOML declarations normalize to one model. Compatible transitive constraints
solve together; conflicting identities/options have origin diagnostics. Resolution
contexts distinguish profile and build/target machine. Registry authority is part
of identity to prevent silent substitution across registries.
A first ordinary build may create a missing lock; --locked forbids changes. Existing
incompatible declarations require explicit resolution. Solve outside a short
publication lock, then compare revisions, revalidate declarations/contexts and atomically
replace. Retry/re-resolve competing updates rather than lose other profile contexts.
Every build pins one immutable lock payload/hash.
Foreign providers return complete typed usage requirements or require explicit
descriptions of gaps. CMake File API, Meson introspection and Conan CppInfo are
inputs, not automatic proof of complete public interfaces. Changed immutable source
identities must invalidate opaque provider results even when timestamps match.
No inference from a library filename alone; preserve order, static implementation
link dependencies, generated prerequisites and configuration mappings.
Registry binary packages are not the local action cache. Binary compatibility
includes toolchain/stdlib ABI, target/CPU, linkage, profile features, sanitizer/LTO
settings and dependency closure. Published release bytes are immutable; yanking
changes selection policy. Authentication + configured HTTPS + hashes define initial
trust; hashes alone do not authenticate publishers.
## VoidLibrary reuse and gaps
The pinned source provides Configuration, System, Testing, Data and other relevant
modules. Reuse verified APIs, not roadmap promises. The simple FileWatcher is a
polling hint, not sufficient recursive/content correctness. Explicit process APIs
preserve failures that legacy helpers can discard. Current test discovery is a CMake
generator and must be replaced for strict native self-host tests.
Candidates for later upstream work: robust descendant lifecycle, recursive rescan
signals, streaming cryptographic hashing, transactional file publication, TOML,
and a supported native test-registration interface. Local focused wrappers are
allowed; no cross-repository edits are implicit.