Zig rules

The Zig family compiles Zig programs and runs their tests on the farm with a pinned Zig. buildrules uses it for its own command line and tools.

Load from @buildrules//rules/zig:zig.bzl.

RuleKey argumentsWhat it does
zig_exesrc, imports, deps, target, optimize, strip, unit_testsbuilds an executable; the default is a static musl executable in ReleaseSafe, stripped
zig_testsrc, imports, deps, target, optimize, data, env_toolsruns zig test as a build action; the result exists only if the tests passed
zig_modulesrc, imports, deps, unit_testsa module other targets import by its target name
zig_distarchive, strip_prefix, sha256, size_bytes, max_outputunpacks a pinned Zig release with the pinned unpack, which checks the archive's sha256 and size first and refuses one that decompresses to more than max_output bytes

Tests are welded #

Pass zig_test targets to unit_tests. Their results are inputs of the executable or module, so the executable is not built unless its tests passed.

BUCK
load("@buildrules//rules/zig:zig.bzl", "zig_exe", "zig_test")

zig_test(name = "tool_test", src = "tool_test.zig", imports = ["tool.zig"])
zig_exe(name = "tool", src = "main.zig", imports = ["tool.zig"], unit_tests = [":tool_test"])

Modules #

A zig_module's import name is its target name. Two different modules reached under one name fail the build, and root, std and builtin are reserved.

Note. Every action runs under a pinned busybox and a pinned Zig. There is no PATH, and the compiler cache directories live in the action's scratch space.
Limit. Linux x86_64 execution only.