Quickstart

Quickstart (5 minutes)

1. Build what is already there

$ ./gen_build_spec.sh
Generated build_spec.zig

$ zig build

$ ./zig-out/bin/app
azazel

2. See what CUE resolved

$ cue export -e build
{
    "modules": {
        "core": {
            "kind": "static",
            "root": "src/core.zig",
            "deps": [],
            "optimize": "Debug"
        },
        "app": {
            "kind": "exe",
            "root": "src/main.zig",
            "deps": [
                "core"
            ],
            "optimize": "ReleaseFast"
        },
        ...
    }
}

project.cue never mentions deps for core, and never mentions optimize at all. CUE supplies deps: [] from the schema default and turns profile: "release" into optimize: "ReleaseFast".

3. Add a module

Append to project.cue:

utils: #Module & {
	kind: "static"
	root: "src/utils.zig"
}

Add it to _modules in export.cue:

_modules: {
	"core":        core
	"app":         app
	"utils":       utils
	"danzig":      danzig
	"danzig_gain": danzig_gain
	"danzig_test": danzig_test
}

Regenerate and build:

./gen_build_spec.sh && zig build

zig-out/lib/libutils.a appears.

Forgetting the export.cue half is the most common mistake. Nothing errors. The module is simply not built.

4. Depend on it

app: #Module & {
	kind:    "exe"
	root:    "src/main.zig"
	deps:    ["core", "utils"]
	profile: "release"
}

deps is a linker edge. Symbols cross it as C-ABI symbols. See deps below.

5. Run the tests

$ zig build test --summary all

Build Summary: 7/7 steps succeeded; 56/56 tests passed
test success
+- run test 12 passed 1ms MaxRSS:1M
|  +- compile test Debug native cached 40ms MaxRSS:34M
+- run test 9 passed 1ms MaxRSS:2M
|  +- compile test Debug native cached 40ms MaxRSS:34M
+- run test 35 passed 1ms MaxRSS:1M
   +- compile test Debug native cached 40ms MaxRSS:34M

Available steps:

$ zig build --help
Steps:
  install (default)            Copy build artifacts to prefix path
  uninstall                    Remove build artifacts from prefix path
  test                         Run all tests