This is libgit2 packaged using Zig's build system. Currently only supports Windows and Linux targets.
While libgit2 supports many different options for system dependencies, I've opted to use MbedTLS by default on Linux for TLS, crypto, and certificate support. You can replace MbedTLS with OpenSSL if you prefer. SSH support is optional, and is provided by libssh2. All other dependencies are bundled in the source tree and compiled statically.
Update your build.zig.zon
:
zig fetch --save git+https://github.com/allyourcodebase/libgit2
# or if you want a tagged release
zig fetch --save https://github.com/allyourcodebase/libgit2/archive/refs/tags/${tag}.tar.gz
Then, in your build.zig
, you can access the library as a dependency:
const libgit2_dep = b.dependency("libgit2", .{
.target = target,
.optimize = optimize,
.@"enable-ssh" = true, // optional ssh support via libssh2
.@"tls-backend" = .openssl, // use openssl instead of mbedtls
});
your_compile_step.linkLibrary(libgit_dep.artifact("git2"));
Don't forget to import headers too:
const c = @cImport({
@cInclude("git2.h");
});