Module build

build
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`/`Allocator`/ `Sanitize` enums — is what `yo init` scaffolds and what is expected to keep its names and meanings. Write build files against that. — stable modules only change additively; this one may still change.

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/Allocator/ Sanitize enums — is what yo init scaffolds and what is expected to keep its names and meanings. Write build files against that.

Types

Optimize enum
Optimize

Optimization level for compiled artifacts.

Variants

VariantFieldsDescription
Debug

No optimizations, full debug info. Compiler Flags: -O0 -g

ReleaseSafe

Optimized with safety checks. Compiler Flags: -O2 -g

ReleaseFast

Maximum speed optimizations. Compiler Flags: -O3

ReleaseSmall

Optimize for binary size. Compiler Flags -O2

Allocator enum
Allocator

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).

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.

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
Executable struct
Executable

Configuration for building an executable.

Fields

NameTypeDescription
namecomptime_str

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

rootcomptime_str

Root source file or directory to document.

targetcomptime_str

Compilation target triple (defaults to host).

optimizeOptimize

Optimization level.

allocatorAllocator

Memory allocator.

heap_sizeusize

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

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., "doc").

rootcomptime_str

Root source file or directory to document.

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., "doc").

rootcomptime_str

Root source file or directory to document.

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., "doc").

rootcomptime_str

Root source file or directory to document.

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/BUILD_AND_DEPENDENCY_SYSTEM_REDESIGN.md §4.1).

Fields

NameTypeDescription
namecomptime_str

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

_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., "doc").

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., "doc").

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., "doc").

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., "doc").

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., "doc").

DocFormat enum
DocFormat

Output format for documentation generation.

Variants

VariantFieldsDescription
Html
Markdown
Json
DocConfig struct
DocConfig

Configuration for documentation generation.

Fields

NameTypeDescription
namecomptime_str

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

rootcomptime_str

Root source file or directory to document.

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.

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., "doc").

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., "doc").

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., "doc").

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., "doc").

Returns: comptime(bool)

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);

Constants

CompilationTarget constant <struct:struct_yo_id_20092>

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_yo_id_20092(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"