liveBook · Manning

Build system

As explained in Systems Programming with Zig

A build system is software that automates source compilation, linking, dependency handling, and related artifact-generation steps.

A Zig build system uses build.zig to organize compilation, linking, dependencies, and other build steps. Separating modules lets a project build only the parts it needs. section 1.2.3 section 6.3.1

A build script can:

  • Separate a virtual machine, runtime, and tests into modules with distinct dependencies. section 6.3.1
  • Create build steps that compile and run tests. section 6.3.1
Listing 6.2 A more modular build script
const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{}); #1
    const optimize = b.standardOptimizeOption(.{}); #1

    const vm_mod = b.createModule(.{ #2
        .root_source_file = b.path("src/vm.zig"),
        .target = target,
        .optimize = optimize,
    });

    const test_mod = b.createModule(.{
        .root_source_file = b.path("src/tests.zig"),
        .target = target,
        .optimize = optimize,
    });
    test_mod.addImport("vm", vm_mod); #3
}

A modular build script creates VM and test modules, setting target and optimization options and importing the VM into the tests. section 6.3.1

Listing 6.3 Making new steps
pub fn build(b: *std.Build) void {
    // ... module code ...

    const tests = b.addTest(.{ #1
        .root_module = test_mod,
    });
    const run_tests = b.addRunArtifact(tests); #2

    const test_cmd = b.step("test", "Run the vm tests"); #3
    test_cmd.dependOn(&run_tests.step); #4
}

This snippet adds a test artifact and a named test step that runs it. section 6.3.1

How Systems Programming with Zig covers it

How deep it goes
Explains module boundaries, dependencies, and test-step wiring without descending into compiler internals.
Examples
Uses VM, runtime, and test modules, plus a build step that runs VM tests.
What you can do after
Build modular Zig targets and expose a test-running step through build.zig.
How it connects
Connects Zig modules with dependency linking, test execution, cross-platform builds, and plugin development.

Also explained in

Compare how 5 books explain build system →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Systems Programming with Zig. The section links point to the parts of the book it draws on.