How to add a dependency to build.zig.zon

I am trying to add GitHub - Hejsil/zig-bench: Simple benchmarking library to my dependency

I am doing this following the instructions I see in the comments in build.zig.zon by running this command

zig fetch --save https://github.com/Hejsil/zig-bench\#bf749bad2ccaee2430e14c5fea7aba3197610723

But kept getting this error:

error: unrecognized 'Content-Type' header: 'text/html; charset=utf-8'

I am not sure what I am doing wrong.

An easy way for me to grab packages is to go to the github “release” section and then right click on the one I want. Say for example I want to get a .tar file… I’d navigate to the release, right click, and copy the link to that file:

Then, from your build directory, do the following:

zig fetch --save={NAME} {PATH_THAT_YOU_COPIED}
1 Like

The easiest way to depend on git repos is to use the git+https scheme, with the name of the branch or commit you want as the # fragment.

zig fetch --save git+https://github.com/Hejsil/zig-bench#bf749bad2ccaee2430e14c5fea7aba3197610723

This particular repo, unfortunately does not have releases Releases · Hejsil/zig-bench · GitHub

Tried that

 zig fetch --save git+https://github.com/Hejsil/zig-bench#bf749bad2ccaee2430e14c5fea7aba3197610723
error: unable to determine name; fetched package has no build.zig.zon file

Noticed the error mentions that it does not have a build.zig.zon file, so would probably need to add it manually somehow.

Use

zig fetch --save=my_name url

To depend on a package without a build.zig.zon.

This adds the dependency as just a “pristine tarball”

If the package does not have a build.zig.zon, the name cannot be inferred and must be provided. The name will show up in your build.zig.zon

3 Likes