Project setup
Everything around the rendered code that makes a working, buildable Zig project.
Contents
How a Program becomes Zig, in parts. Start with the introduction, then follow each part into the rendered output and the runtime it links against.
- Introduction — what the Zig target is, and how to read the rest of this section.
- Capabilities — which high-level features are possible, built in or through a library.
- Example — a full program using every keyword, and the Zig it renders to.
- Naming considerations — how Program's dotted names are carried into Zig.
- Entry point — starting a program from
mainwith its drivers. - Drivers — the native drivers that provide the interface, console and network.
- Runtime — the Reactive and Context machinery the rendered code links against.
- Native modules — the hand-written Zig behind
NATIVEfunctions. - Keywords — how each of Program's keywords renders to Zig.
- Project setup — the files and commands to build and run the rendered program.
- Reserved words — the words Zig keeps for itself, and how a colliding name is escaped.
The files
A rendered Zig program is an ordinary Zig project: a build.zig script and a
src/ tree, with each top module its own file.
my-app/
build.zig # the build script
build.zig.zon # dependencies (if any)
src/
main.zig # pub fn main() !void { Program.application(...) }
reactive.zig # the runtime (Reactive + Context + drivers)
ui.zig maths.zig ... # one file per top module
// build.zig
const std = @import("std");
pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{
.name = "my-app",
.root_source_file = b.path("src/main.zig"),
.target = b.standardTargetOptions(.{}),
});
b.installArtifact(exe);
}
Build and run
The Zig toolchain builds and runs it — no extra tooling.
zig build # compile to zig-out/bin
zig build run # build and run
zig build -Doptimize=ReleaseFast # an optimised binary
The output is a single native binary with no runtime dependency, which is what makes Zig a good fit for small, self-contained tools built from a Program.