<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Howto on despatches</title><link>https://icle.es/tags/howto/</link><description>Recent content in Howto on despatches</description><generator>Hugo</generator><language>en</language><lastBuildDate>Mon, 23 Jun 2025 12:11:10 +0100</lastBuildDate><atom:link href="https://icle.es/tags/howto/index.xml" rel="self" type="application/rss+xml"/><item><title>Add zig dependency in bazel</title><link>https://icle.es/2025/06/11/add-zig-dependency-in-bazel/</link><pubDate>Wed, 11 Jun 2025 20:44:01 +0100</pubDate><guid>https://icle.es/2025/06/11/add-zig-dependency-in-bazel/</guid><description>&lt;p>&lt;code>[rules-zig][https://github.com/aherrmann/rules_zig]&lt;/code> doesn&amp;rsquo;t use &lt;code>zon&lt;/code>
files(yet) and addind dependencies involves adding it into &lt;code>MODULES.bazel&lt;/code>. If
you&amp;rsquo;re still using workspaces on bazel,
&lt;a href="https://github.com/aherrmann/rules_zig/issues/231#issuecomment-2723684385">this code sample mentioned in the related issue might help&lt;/a>.
I started with that code sample.&lt;/p>
&lt;p>I was adding in a dependency to &lt;a href="https://github.com/sam701/zig-toml">zig-toml&lt;/a>
and this is the
&lt;a href="https://github.com/drone-ah/wordsonsand/blob/9dd185e5f330403cad9afe2ad67cc511565e1325/MODULE.bazel#L43">rule that I used&lt;/a>:&lt;/p>
```starlark
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"],
)
""",
)
```
&lt;p>Let&amp;rsquo;s break it down:&lt;/p></description><content:encoded><![CDATA[<p><code>[rules-zig][https://github.com/aherrmann/rules_zig]</code> doesn&rsquo;t use <code>zon</code>
files(yet) and addind dependencies involves adding it into <code>MODULES.bazel</code>. If
you&rsquo;re still using workspaces on bazel,
<a href="https://github.com/aherrmann/rules_zig/issues/231#issuecomment-2723684385">this code sample mentioned in the related issue might help</a>.
I started with that code sample.</p>
<p>I was adding in a dependency to <a href="https://github.com/sam701/zig-toml">zig-toml</a>
and this is the
<a href="https://github.com/drone-ah/wordsonsand/blob/9dd185e5f330403cad9afe2ad67cc511565e1325/MODULE.bazel#L43">rule that I used</a>:</p>
```starlark
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"],
)
""",
)
```
<p>Let&rsquo;s break it down:</p>
<ul>
<li><code>name</code>: Pretty flexible, but you probably want to use the lib name, or the
name you would use in the zon file.</li>
<li><code>urls</code>: You need the url to the zip file. If you want main - you can click on
the button that says <code>Code</code> and at the use the link at the bottom that says
&ldquo;Download ZIP&rdquo;.
<a href="https://docs.github.com/en/repositories/working-with-files/using-files/downloading-source-code-archives">GitHub documentation on source code archives</a>
has more information as well as details on how to get he url for specific
commits etc.</li>
<li><code>sha256</code>: When running for the first time, bazel will tell you that
<code>a canonical reproducible form can be obtained by modifying arguments integrity = &quot;sha256-&lt;hash&gt;&quot;</code>.
However, for whatever reason, it uses a different format from what you need to
use in the <code>MODULES.bazel</code> file. To convert it, you can use:</li>
</ul>
```bash
echo '<hash>' | base64 -d | xxd -p -c 256
```
<ul>
<li><code>strip_prefix</code>: The zip file will extract the files out into a directory. This
parameter is that directory name. I just unzipped the zip file and put that
here. I&rsquo;m sure there are simpler ways to get at it (please let me know below
if you know of a way)</li>
<li><code>build_file_content</code>: This parameter lets you define what the contents of the
build file will be when building that library. It might be nice to be able to
reference a file rather than include it here - I think I&rsquo;ve done that before
but I can&rsquo;t remember how. Please let me know below if you know how it&rsquo;s done
and I&rsquo;ll update it here.</li>
</ul>
]]></content:encoded></item></channel></rss>