ziglang/zig
build-runner
Active contributors: andrewrk, mlugg, alexrp
Purpose
lib/compiler/build_runner.zig (~78 KB) is the program that zig build actually runs. The zig binary compiles the user's build.zig together with this runner and then executes the result. The runner parses the CLI, constructs a std.Build, calls the user's build(b), walks the resulting step graph, and invokes zig recursively to do the work.
How zig build invokes it
src/main.zigseesargv[1] == "build".- The compiler builds an executable by:
- Treating
lib/compiler/build_runner.zigas the root. - Treating the project's
build.zigas a module imported by the runner. - Resolving
build.zig.zondependencies viasrc/Package/Fetch.zig.
- Treating
- The runner is launched with the user's CLI arguments (everything after
zig build).
Responsibilities
- Parse CLI flags: target options, optimize mode, install prefix,
--watch,--listen,--summary,-D...user options. - Construct
std.Build: with the resolved host, target, cache directory, and prefix. - Call
build(b)in the user'sbuild.zig. This registersSteps. - Resolve the requested step.
zig build fooruns the step namedfoo(orinstall, the default). - Run the step graph. Walk dependencies, hash inputs through
std.Build.Cache, and execute cache misses in parallel viastd.Thread.Pool. - Stream progress via
std.Progressandstd.Build.WebServerwhen--listenis set. - Watch mode delegates to
std.Build.Watchand re-runs affected steps on file events.
Integration points
std.Build(lib/std/Build.zig) — the API the runner exposes tobuild.zig.std.Build.Cache(lib/std/Build/Cache.zig) — content-addressed caching.std.Build.Watch(lib/std/Build/Watch.zig) —--watchplumbing.std.Build.WebServer(lib/std/Build/WebServer.zig) —--listenHTTP UI.std.Build.Fuzz(lib/std/Build/Fuzz.zig) — fuzz-step plumbing.src/Package/— dependency fetching.
Companion: lib/compiler/test_runner.zig
The same pattern applies to zig test: lib/compiler/test_runner.zig (~16 KB) is the program embedded in test executables. Step.Compile for a test artifact links the user's code together with the test runner; running the resulting binary discovers and executes test "..." blocks and reports results.
Key source files
| File | Purpose |
|---|---|
lib/compiler/build_runner.zig |
The runner itself. |
lib/compiler/test_runner.zig |
The test runner. |
lib/compiler/util.zig |
Shared utilities for compiler-bundled tools. |
lib/compiler/std-docs.zig |
Used by zig std (similar pattern). |
lib/std/Build.zig and lib/std/Build/* |
What the runner orchestrates. |
See Build system for the user-facing API and Package manager for how dependencies feed the runner.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.