rules_zig icon indicating copy to clipboard operation
rules_zig copied to clipboard

Support `zig build` for third-party dependencies

Open aherrmann opened this issue 1 year ago • 3 comments

aherrmann avatar Feb 18 '24 14:02 aherrmann

Hi,

I've just started integration of rules_zig into our repo. Does this issue refer to replicating the behaviour of zon?

I am not actually doing zig development (yet), only trying to plug in zine-sso which requires a dependency on that lib.

Is there some way to manage these kinds of dependencies right now?

Thanks & Best Wishes, Shri

drone-ah avatar Mar 11 '25 17:03 drone-ah

This issue was created before the ZON package format was introduced. At the time the idea was to perhaps have a rule called zig_build that could be invoked on a third-party dependency Zig project, i.e. something with a build.zig file, to build the entire project. Or, more advanced, some mechanism to understand the build.zig file and generate equivalent rules_zig targets. https://github.com/aherrmann/rules_zig/issues/232 was opened later when the notion of a Zig package was introduced.

Given that build.zig could fetch and build dependency Zig packages likely means that these two issues cannot be viewed in isolation. Both these issues have not yet seen much thought go into them. I saw that the latest Zig release 0.14.0 changed the package fingerprint format to enable offline dependency resolution. That should help with https://github.com/aherrmann/rules_zig/issues/232.

For the time being, you can manage Zig dependencies manually by pulling in the dependency's release tarball, e.g. as an http archive, and passing a BUILD file template that creates a zig_module target or other for that package. An old example (that still uses WORKSPACE and zig_package before it was renamed to zig_module can be found here). You can use http_archive in your MODULE.bazel file like so:

http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(name = "foo", urls = [...], ...)

aherrmann avatar Mar 14 '25 05:03 aherrmann

I got it working, and wrote up some notes in case it's helpful to others

drone-ah avatar Jun 23 '25 12:06 drone-ah