Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ zig fetch --save https://github.com/allyourcodebase/libgit2/archive/refs/tags/${

Then, in your `build.zig`, you can access the library as a dependency:
```zig
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
const exe = b.addExecutable(.{
.name = "git2test",
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{.{ // Add git2 as an import
.name = "git2",
.module = dep.module("git2"),
}},
}),
});
your_compile_step.linkLibrary(libgit_dep.artifact("git2"));
```

Don't forget to import headers too:
```zig
const c = @cImport({
@cInclude("git2.h");
});
const c = @import("git2");
```
11 changes: 11 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,17 @@ pub fn build(b: *std.Build) !void {
lib.installHeadersDirectory(libgit_src.path("include"), "", .{});
b.installArtifact(lib);

const translate_c = b.addTranslateC(.{
.root_source_file = libgit_src.path("include/git2.h"),
.target = target,
.optimize = optimize,
});

translate_c.addIncludePath(libgit_src.path("include"));

const git2_module = translate_c.addModule("git2");
git2_module.linkLibrary(lib);

const cli_step = b.step("run-cli", "Build and run the command-line interface");
{
const cli = b.createModule(.{
Expand Down