Vendoring zig dependencies

Hi. Is there a straightforward way to vendor dependencies of a project? something akin to go mod vendor ?

I’m in a situation where I have to patch a dependency (and some of its deps) to fix some “local variable is never mutated” errors so it can compile on zig 0.12.x

I guess I could just fork everything, but then I would also have to fix the dependency graph so it pulls my versions - not the most straightforward approach if you ask me.


I am not sure, however I just had a look at the output of zig fetch --help:

Usage: zig fetch [options] <url>
Usage: zig fetch [options] <path>

    Copy a package into the global cache and print its hash.

  -h, --help                    Print this help and exit
  --global-cache-dir [path]     Override path to global Zig cache directory
  --debug-hash                  Print verbose hash information to stdout
  --save                        Add the fetched package to build.zig.zon
  --save=[name]                 Add the fetched package to build.zig.zon as name

So here is my totally untested crazy idea, try if you can combine --global-cache-dir path-to-my-vendor with --save. I haven’t really used fetch directly but my guess is you would have to build the list of external dependencies (deps of deps) and then invoke fetch for each one. Probably there is some easy way to get all the dependencies, but I haven’t looked into it more deeply yet. I don’t know whether the result will work for vendoring, but it may be worth a try until there is a dedicated command.

I haven’t found an explicit vendoring issue, but these 2 mention vendoring:

In zig 0.12.x, it could deal with a local path as dependency.
In case of existing build.zig file in vendor/foo folder.

    .dependencies = .{
        .foo = .{
            .path = "./vendor/foo"

see also: zig/doc/ at master · ziglang/zig · GitHub

1 Like

@Sze cool idea, worth testing!

@ktz_alias that’s interesting - but what if foo depends on bar, and I also have to fix bar ? In that case, I would have to manually edit foo/build.zig to alter the path to bar