17 Jul 2024 , tagged: zig
Zig Fetch
Zig’s package manager is still a bit rough. It only supports fetching tarballs, but many github projects don’t have them unless they have a release. There’s a trick to fetch any commit as a tarball though:
https://api.github.com/repos/<repo-owner>/<repo>/tarball/<ref>
zig fetch
can than download the code:
zig fetch --save https://api.github.com/repos/<repo-owner>/<repo>/tarball/<ref>
Once the code is downloaded, it still has to be added to your exe or libray in build.zig
:
const exe = b.addExecutable(.{
.name = "zlox",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const my_dep = b.dependency("<name of dependency>", .{ .target = target, .optimize = optimize });
exe.root_module.addImport("regex", regex_dep.module("regex"));