diff --git a/README.md b/README.md index 60d588a..08ea63a 100644 --- a/README.md +++ b/README.md @@ -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"); ``` diff --git a/build.zig b/build.zig index fc229f4..3db7ab7 100644 --- a/build.zig +++ b/build.zig @@ -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(.{