Bazel rules for building Zig projects.
zig_binary— compile Zig source files into an executablezig_library— compile Zig source files into a static library (.a)- Bazel toolchain integration with platform-aware compiler resolution
- Zig: 0.13.0
- Bazel: 9.0+
Since rules_zig is not yet published to the Bazel Central Registry, use git_override to depend on it directly from GitHub.
Add the following to your MODULE.bazel:
bazel_dep(name = "rules_zig", version = "0.1.0")
git_override(
module_name = "rules_zig",
remote = "https://github.com/darthfork/rules_zig.git",
commit = "<commit_sha>", # pin to a specific commit
)
zig = use_extension("@rules_zig//zig:extensions.bzl", "zig")
zig.toolchain(zig_version = "0.13.0")
use_repo(zig, "zig_toolchains")
register_toolchains("@zig_toolchains//:all")Replace <commit_sha> with the commit you want to pin to.
WORKSPACE is not supported. Bazel 9+ requires Bzlmod.
Compiles Zig source files into an executable.
load("@rules_zig//zig:defs.bzl", "zig_binary")
zig_binary(
name = "hello_world",
srcs = ["main.zig"],
)| Attribute | Description | Required |
|---|---|---|
srcs |
List of .zig source files |
Yes |
main |
Root source file to compile. Defaults to the first file in srcs. |
No |
Compiles Zig source files into a static library.
load("@rules_zig//zig:defs.bzl", "zig_library")
zig_library(
name = "math",
srcs = ["math.zig"],
)| Attribute | Description | Required |
|---|---|---|
srcs |
List of .zig source files |
Yes |
main |
Root source file for the library. Defaults to the first file in srcs. |
No |