Module build

build
Stability: unstable — may still change; see below.

Declarative build API for Yo projects.

All functions are compile-time only — they register build artifacts and steps that the build runner uses to orchestrate compilation.

Example

build :: import("std/build");

mod :: build.module({ name : "default" }); // a [modules] entry of yo.toml
exe :: build.executable({ name : "my-app", root : "./src/main.yo" });
install :: build.step("install", "Build all artifacts");
install.depend_on(exe);

Stability

unstable — this is the API a project's build.yo is written against, so it is the one place where a breaking change costs every downstream project a manual edit, and two things still move. The step model is one: StepKind and Step expose the runner's DAG vocabulary directly, and the runner's scheduling is still being changed (levels, artifact caching), so a build file that reaches past Executable/TestSuite into Step is reaching at something not yet settled. The other is CompilationTarget, which gained the canonical Rust triples in plans/reference/TARGET_TRIPLES.md and may still gain fields as targets are added.

The declarative face — Executable, StaticLibrary, SharedLibrary, TestSuite, BuildModule, target_host, the Optimize/AllocatorKind/ Sanitize enums — is what yo init scaffolds and what is expected to keep its names and meanings. Write build files against that. CycleCollector is the exception: it lives only until the cycle collector is deleted (plans/backlog/WEAK_AND_UNCOLLECTED_RC.md §6), after which Off is the only behavior and the field goes.

Types

Optimize enum
Optimize

Optimization level for compiled artifacts.

Variants

VariantFieldsDescription
Debug

A tracking allocator over the system one, for finding memory bugs: a double free or a free of a pointer it never handed out aborts, a freed block is poisoned and quarantined, and the exit report lists every block still live. A run whose main returns with live blocks exits with status 23 (yo compile --allocator debug, plans/backlog/ZIG_ADOPTION_CANDIDATES.md Z11).

ReleaseSafe

Optimized with safety checks. Compiler Flags: -O2

ReleaseFast

Maximum speed optimizations. Compiler Flags: -O3

ReleaseSmall

Optimize for binary size. Compiler Flags: -Os

Methods
clone : (Optimize) fn(self : &Optimize) -> Optimize

Parameters

NameTypeNotes
selfOptimize

Returns: Optimize

AllocatorKind

Memory allocator to use in the compiled artifact.

Variants

VariantFieldsDescription
Mimalloc

High-performance allocator (mimalloc).

System

The platform's system allocator (macOS malloc zones, Windows CRT heap, glibc/musl malloc on Linux).

Fixed

A general-purpose TLSF allocator over ONE statically-sized region in .bss (heap_size, default 16 MiB). No libc heap; running out of that region is a panic with a diagnostic. The first building block of the embedded/freestanding story, and on desktop a deterministic OOM oracle (plans/reference/FIXED_REGION_ALLOCATOR.md).

Debug

A tracking allocator over the system one, for finding memory bugs: a double free or a free of a pointer it never handed out aborts, a freed block is poisoned and quarantined, and the exit report lists every block still live. A run whose main returns with live blocks exits with status 23 (yo compile --allocator debug, plans/backlog/ZIG_ADOPTION_CANDIDATES.md Z11).

Methods
clone : (AllocatorKind) fn(self : &AllocatorKind) -> AllocatorKind

Parameters

NameTypeNotes
selfAllocatorKind

Returns: AllocatorKind

CycleCollector

Whether the compiled artifact carries the reference-cycle collector (yo compile --cycle-collector auto|off, plans/backlog/WEAK_AND_UNCOLLECTED_RC.md §1).

Variants

VariantFieldsDescription
Auto

The collector runs whenever some type of the program can form a reference cycle (the default).

Off

No collector: every reference cell uses the lightweight RC runtime, Gc.collect() does nothing and Gc.tracked_count() is 0. A reference cycle leaks, as in Rust; --debug-heap reports it at exit.

Methods
clone : (CycleCollector) fn(self : &CycleCollector) -> CycleCollector

Parameters

NameTypeNotes
selfCycleCollector

Returns: CycleCollector

Sanitize enum
Sanitize

Runtime sanitizer to enable.

Variants

VariantFieldsDescription
None

No sanitizer.

Address

AddressSanitizer — detects memory errors and leaks.

Leak

LeakSanitizer — detects memory leaks only.

Thread

ThreadSanitizer — detects data races in multi-threaded code.

Methods
clone : (Sanitize) fn(self : &Sanitize) -> Sanitize

Parameters

NameTypeNotes
selfSanitize

Returns: Sanitize

StepKind enum
StepKind

Kind of build step.

Variants

VariantFieldsDescription
Executable

Configuration for building an executable.

StaticLibrary

Configuration for building a static library.

SharedLibrary

Configuration for building a shared/dynamic library.

SystemLibrary

System C library discovered via pkg-config.

TestSuite

Configuration for a test suite.

Run
Custom
Documentation
Verification
Methods
clone : (StepKind) fn(self : &StepKind) -> StepKind

Parameters

NameTypeNotes
selfStepKind

Returns: StepKind

Executable struct
Executable

Configuration for building an executable.

Fields

NameTypeDescription
namecomptime_str

Step name (e.g., "verify").

rootcomptime_str

Root source file or directory to verify (every .yo file under it).

targetcomptime_str

Compilation target triple (defaults to host).

optimizeOptimize

Optimization level.

allocatorAllocatorKind

Memory allocator.

heap_sizeusize

Fixed-region heap size in bytes (allocator : AllocatorKind.Fixed only; 64 KiB..4 GiB, rounded down to a 16-byte granule). Ignored by the other allocators.

cycle_collectorCycleCollector

Reference-cycle collector (CycleCollector.Off = Rust's model: a cycle leaks).

sanitizeSanitize

Runtime sanitizer.

emit_c_tocomptime_str

Write the single generated C file to this path instead of the default <output>.c sidecar. Empty = default. Redirects rather than duplicates, so exactly one C file exists and the C compiler consumes it.

emit_chunkscomptime_int

Split the emitted C into this many translation units, compiled in PARALLEL behind a content-addressed object cache and then linked (plans/reference/CHUNKED_C_EMISSION.md). 0 = off, one C file as before — which is the default because the single-file emission is what the bootstrap gates and the portable-C distribution compare. At -O1 and above a chunked build also gets -flto=thin, without which it would lose the cross-module inlining that a single translation unit gives for free.

StaticLibrary struct
StaticLibrary

Configuration for building a static library.

Fields

NameTypeDescription
namecomptime_str

Step name (e.g., "verify").

rootcomptime_str

Root source file or directory to verify (every .yo file under it).

targetcomptime_str

Compilation target triple (defaults to host).

optimizeOptimize

Optimization level.

SharedLibrary struct
SharedLibrary

Configuration for building a shared/dynamic library.

Fields

NameTypeDescription
namecomptime_str

Step name (e.g., "verify").

rootcomptime_str

Root source file or directory to verify (every .yo file under it).

targetcomptime_str

Compilation target triple (defaults to host).

optimizeOptimize

Optimization level.

TestSuite struct
TestSuite

Configuration for a test suite.

Fields

NameTypeDescription
namecomptime_str

Step name (e.g., "verify").

rootcomptime_str

Root source file or directory to verify (every .yo file under it).

targetcomptime_str

Compilation target triple (defaults to host).

excludecomptime_str

Comma-separated paths (files or directories, relative to the project root) excluded from the test walk — a path is excluded if it equals an entry or lives under one, e.g. "tests/internal,tests/cli-cases".

verbosebool

Print each test as it runs (yo test --verbose). yo build --verbose turns it on for every suite regardless.

bailbool

Stop at the first failing test (yo test --bail).

parallelusize

Test files to compile at once (yo test --parallel N). Forwarded to the child run, which ACCEPTS it and runs sequentially anyway — yo test's v1 takes the flag for CLI compatibility only (src/main.yo). Surfaced so the build file is not the thing that loses it.

BuildModule struct
BuildModule

A named module of this package or of a dependency, as a handle for linking system libraries (mod.link(sys)). Which FILE the module is — and what import("name") resolves to — is the manifest's business (yo.toml [modules], plans/archive/BUILD_AND_DEPENDENCY_SYSTEM_REDESIGN.md §4.1).

Fields

NameTypeDescription
namecomptime_str

Step name (e.g., "verify").

_depcomptime_str

The dependency the module belongs to ("" = this package).

impl(BuildModule, ...)
Step struct
Step

A build step returned by all registration functions. Use step.depend_on(dep) to wire dependencies between steps.

Fields

NameTypeDescription
namecomptime_str

Step name (e.g., "verify").

kindStepKind

Kind of step.

impl(Step, ...)
depend_on : (Step) fn(self : Step, dep : Step) -> unit

Add a dependency — dep must complete before this step runs.

Parameters

NameTypeNotes
selfStepcomptime
depStepcomptime

Returns: unit

add_c_flags : (Step) fn(self : Step, flags : comptime_str) -> unit

Add extra C compiler flags to this step.

Parameters

NameTypeNotes
selfStepcomptime
flagscomptime_strcomptime

Returns: unit

BuildOption struct
BuildOption

User-configurable build option (declared in build.yo, set via yo build -Dname=value).

Fields

NameTypeDescription
namecomptime_str

Step name (e.g., "verify").

descriptioncomptime_str

Human-readable description.

defaultcomptime_str

Default value if not provided.

SystemLibrary struct
SystemLibrary

System C library discovered via pkg-config.

Fields

NameTypeDescription
namecomptime_str

Step name (e.g., "verify").

fallback_includecomptime_str

Fallback include path if pkg-config fails.

fallback_libcomptime_str

Fallback library path.

fallback_linkcomptime_str

Fallback link flags.

definescomptime_str

Extra C preprocessor defines.

Dependency struct
Dependency

Handle to a manifest dependency. Use .artifact() or .module() to access its exports.

Fields

NameTypeDescription
namecomptime_str

Step name (e.g., "verify").

impl(Dependency, ...)
artifact : (Dependency) fn(self : Dependency, artifact_name : comptime_str) -> Step

Access a named artifact from the dependency's build.yo. Returns a Step that can be linked to the consumer's artifacts.

Parameters

NameTypeNotes
selfDependencycomptime
artifact_namecomptime_strcomptime

Returns: Step

module : (Dependency) fn(self : Dependency, module_name : comptime_str) -> BuildModule

Get a module from the dependency's build.yo. Empty module_name defaults to the sole module if exactly one exists.

Parameters

NameTypeNotes
selfDependencycomptime
module_namecomptime_strcomptime, default: ""

Returns: BuildModule

ModuleConfig struct
ModuleConfig

Module configuration. The module's root file is declared in yo.toml's [modules] table (default = "src/lib.yo", board = "src/board.yo"); build.module names one of those to attach system libraries to it.

Fields

NameTypeDescription
namecomptime_str

Step name (e.g., "verify").

Manifest struct
Manifest

The [package] table of the yo.toml beside the build file being evaluated. A field the manifest does not set, and every field outside a build, reads as "".

Fields

NameTypeDescription
namecomptime_str

Step name (e.g., "verify").

versioncomptime_str

Release version to display (e.g., "v1.0.0"). When empty, auto-detects from git tag or commit hash.

DocFormat enum
DocFormat

Output format for documentation generation.

Variants

VariantFieldsDescription
Html
Markdown
Json
Methods
clone : (DocFormat) fn(self : &DocFormat) -> DocFormat

Parameters

NameTypeNotes
selfDocFormat

Returns: DocFormat

DocConfig struct
DocConfig

Configuration for documentation generation.

Fields

NameTypeDescription
namecomptime_str

Step name (e.g., "verify").

rootcomptime_str

Root source file or directory to verify (every .yo file under it).

outputcomptime_str

Output directory (default: "yo-out/doc").

formatDocFormat

Output format (default: Html).

include_privatebool

Document non-exported (private) items.

titlecomptime_str

Custom site title (default: project name).

versioncomptime_str

Release version to display (e.g., "v1.0.0"). When empty, auto-detects from git tag or commit hash.

logocomptime_str

Path to logo image.

faviconcomptime_str

Path to favicon.

VerifyMode enum
VerifyMode

The mode a build.verify step runs its target files in (the same two modes Pragma.Verify / Pragma.VerifyOrAssert select per file, see docs/en-US/FORMAL_VERIFICATION.md §Modes).

Variants

VariantFieldsDescription
Verify

verify: every obligation must be proved; a refuted, unproven or outside-subset contracted function fails the step.

VerifyOrAssert

verify+: a refutation fails the step; an unproven obligation keeps its runtime assert and warns.

Methods
clone : (VerifyMode) fn(self : &VerifyMode) -> VerifyMode

Parameters

NameTypeNotes
selfVerifyMode

Returns: VerifyMode

VerifyConfig struct
VerifyConfig

Configuration for a verification step.

Fields

NameTypeDescription
namecomptime_str

Step name (e.g., "verify").

rootcomptime_str

Root source file or directory to verify (every .yo file under it).

modeVerifyMode

Verification mode (default: Verify).

strictbool

Pass --strict (a vacuous ok with zero obligations fails, see docs/en-US/FORMAL_VERIFICATION.md §Strict mode).

Functions

executable function
fn(comptime(config) : Executable) -> comptime(Step)

Register an executable artifact. Returns a Step for dependency wiring.

Parameters

NameTypeNotes
configExecutablecomptime

Returns: comptime(Step)

static_library function
fn(comptime(config) : StaticLibrary) -> comptime(Step)

Register a static library artifact. Returns a Step for dependency wiring.

Parameters

NameTypeNotes
configStaticLibrarycomptime

Returns: comptime(Step)

shared_library function
fn(comptime(config) : SharedLibrary) -> comptime(Step)

Register a shared/dynamic library artifact. Returns a Step for dependency wiring.

Parameters

NameTypeNotes
configSharedLibrarycomptime

Returns: comptime(Step)

test function
fn(comptime(config) : TestSuite) -> comptime(Step)

Register a test-suite artifact. Returns a Step for dependency wiring.

Parameters

NameTypeNotes
configTestSuitecomptime

Returns: comptime(Step)

run function
fn(comptime(artifact) : Step) -> comptime(Step)

Create a run step (compile + execute an artifact). Returns a Step.

Parameters

NameTypeNotesDescription
artifactStepcomptime

Access a named artifact from the dependency's build.yo. Returns a Step that can be linked to the consumer's artifacts.

Returns: comptime(Step)

step function
fn(comptime(name) : comptime_str, comptime(description) : comptime_str) -> comptime(Step)

Register a named build step. Use step.depend_on(dep) to add dependencies.

Parameters

NameTypeNotesDescription
namecomptime_strcomptime

Step name (e.g., "verify").

descriptioncomptime_strcomptime

Human-readable description.

Returns: comptime(Step)

dependency function
fn(comptime(name) : comptime_str) -> comptime(Dependency)

The handle of a dependency declared in yo.toml's [dependencies] (or [dev-dependencies]) — Zig's b.dependency(name, .{}). Where the dependency comes from (git, version, path) is the manifest's; the build file only names it. The runner rejects a name the manifest lacks.

Parameters

NameTypeNotesDescription
namecomptime_strcomptime

Step name (e.g., "verify").

Returns: comptime(Dependency)

system_library function
fn(comptime(config) : SystemLibrary) -> comptime(Step)

Register a system C library discovered via pkg-config. Returns a Step for linking.

Parameters

NameTypeNotes
configSystemLibrarycomptime

Returns: comptime(Step)

module function
fn(config : ModuleConfig) -> BuildModule

Get a module from the dependency's build.yo. Empty module_name defaults to the sole module if exactly one exists.

Parameters

NameTypeNotes
configModuleConfigcomptime

Returns: BuildModule

option function
fn(comptime(config) : BuildOption) -> comptime(str)

Declare a user-configurable build option. Returns the option value (from CLI -Dname=value, or the default).

Example

strip :: build.option({
  name : "strip",
  description : "Strip debug symbols",
  default : "false"
});

Parameters

NameTypeNotes
configBuildOptioncomptime

Returns: comptime(str)

env function
fn(comptime(name) : comptime_str, comptime(fallback) : comptime_str) -> comptime(str)

The environment variable name, or fallback when it is unset.

Readable ONLY from a build file. An ordinary module that read the environment would mean something different under yo build, yo check, yo test and the editor, so the builtin is a compile error everywhere else.

Every read is folded into the artifact input stamp, so changing a variable the build file branches on rebuilds rather than serving a stale artifact.

PREFER build.option and -Dname=value: an option is declared, listed by yo build --list-options, and visible in the command that produced a build. Reach for env for what genuinely belongs to the environment — CI detection, PKG_CONFIG_PATH, a default that depends on the machine.

Parameters

NameTypeNotesDescription
namecomptime_strcomptime

Step name (e.g., "verify").

fallbackcomptime_strcomptime

Returns: comptime(str)

env_is_set function
fn(comptime(name) : comptime_str) -> comptime(bool)

Whether name is set at all, which env alone cannot tell you: a variable set to the same text as the fallback is indistinguishable from an unset one.

Parameters

NameTypeNotesDescription
namecomptime_strcomptime

Step name (e.g., "verify").

Returns: comptime(bool)

manifest function
fn() -> comptime(Manifest)

The manifest of the package whose build file is being evaluated, so an artifact or step can be named by yo.toml instead of repeating it.

A function, not a module-level value: std/build.yo is evaluated once per yo build, and a dependency's build.yo runs after the project's against that same evaluation. A value would keep the project's fields there; each call reads the manifest of the build file it is evaluated in.

Examples

build :: import("std/build");

exe :: build.executable({ name : build.manifest().name, root : "./src/main.yo" });

install :: build.step("install", build.manifest().version);
install.depend_on(exe);

Returns: comptime(Manifest)

Examples
build :: import("std/build");

exe :: build.executable({ name : build.manifest().name, root : "./src/main.yo" });

install :: build.step("install", build.manifest().version);
install.depend_on(exe);
doc function
fn(comptime(config) : DocConfig) -> comptime(Step)

Register a documentation generation step. Returns a Step for dependency wiring.

Examples

build :: import("std/build");

// Minimal — just works with defaults
doc_step :: build.doc({ name : "doc", root : "./src/lib.yo" });

// Full customization
doc_step :: build.doc({
  name : "doc",
  root : "./src",
  output : "docs/api",
  format : DocFormat.Markdown,
  title : "My Library API",
  version : "v1.0.0"
});

install :: build.step("install", "Build all artifacts");
install.depend_on(doc_step);

Parameters

NameTypeNotes
configDocConfigcomptime

Returns: comptime(Step)

Examples
build :: import("std/build");

// Minimal — just works with defaults
doc_step :: build.doc({ name : "doc", root : "./src/lib.yo" });

// Full customization
doc_step :: build.doc({
  name : "doc",
  root : "./src",
  output : "docs/api",
  format : DocFormat.Markdown,
  title : "My Library API",
  version : "v1.0.0"
});

install :: build.step("install", "Build all artifacts");
install.depend_on(doc_step);
verify function
fn(comptime(config) : VerifyConfig) -> comptime(Step)

Register a verification step: yo build <name> runs yo verify <root> with the pinned Z3. Returns a Step for dependency wiring. This is the project-level "every build proves my contracts" switch; yo check stays solver-free by design.

Examples

build :: import("std/build");

proofs :: build.verify({ name : "verify", root : "./src" });

install :: build.step("install", "Build all artifacts");
install.depend_on(proofs);

Parameters

NameTypeNotes
configVerifyConfigcomptime

Returns: comptime(Step)

Examples
build :: import("std/build");

proofs :: build.verify({ name : "verify", root : "./src" });

install :: build.step("install", "Build all artifacts");
install.depend_on(proofs);

Constants

CompilationTarget constant <struct:struct_std__build_CompilationTarget_r0c21_n0>

The supported compilation targets, named by their canonical Rust-style triple (<arch>-<vendor>-<os>[-<env>], plus wasm32-wasip1) — the same strings yo compile --target takes and the release assets are named by. There are no aliases: an unrecognised spelling is rejected with this list.

Value: struct_std__build_CompilationTarget_r0c21_n0(X86_64_Unknown_Linux_Gnu: "x86_64-unknown-linux-gnu", X86_64_Unknown_Linux_Musl: "x86_64-unknown-linux-musl", Aarch64_Unknown_Linux_Gnu: "aarch64-unknown-linux-gnu", Aarch64_Unknown_Linux_Musl: "aarch64-unknown-linux-musl", Aarch64_Apple_Darwin: "aarch64-apple-darwin", X86_64_Apple_Darwin: "x86_64-apple-darwin", X86_64_Pc_Windows_Msvc: "x86_64-pc-windows-msvc", Aarch64_Pc_Windows_Msvc: "aarch64-pc-windows-msvc", Wasm32_Unknown_Emscripten: "wasm32-unknown-emscripten", Wasm32_Wasip1: "wasm32-wasip1")

target_host constant comptime_str

Host compilation target string.

Value: "x86_64-unknown-linux-gnu"