words on sand

from shri at drone-ah.com

11 Jun 2025

Add zig dependency in bazel

[rules-zig][https://github.com/aherrmann/rules_zig] doesn’t use zon files(yet) and addind dependencies involves adding it into MODULES.bazel. If you’re still using workspaces on bazel, this code sample mentioned in the related issue might help . I started with that code sample.

I was adding in a dependency to zig-toml and this is the rule that I used :

zig_toml_archive(
    name = "zig_toml",
    urls = ["https://github.com/sam701/zig-toml/archive/refs/heads/main.zip"],
    sha256 = "b1f0846c3b5e9696892b0d96f8add4878c057c728623b03d6bfbd508e4af48d5",
    strip_prefix = "zig-toml-main",
    build_file_content = """
load("@rules_zig//zig:defs.bzl", "zig_module")
zig_module(
    name = "toml",
    main = "src/root.zig",
    srcs = glob(["src/**/*.zig"]),
    visibility = ["//visibility:public"],
)
""",
)

Let’s break it down:

1
echo '<hash>' | base64 -d | xxd -p -c 256