Skip to content

Commit ee14d04

Browse files
Merge pull request #20 from yamashitax/push-trzuklsnupqt
build: use translate_c in favor of deprecated @cImport
2 parents 4601a73 + c8aa2d8 commit ee14d04

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ const libgit2_dep = b.dependency("libgit2", .{
2020
.@"enable-ssh" = true, // optional ssh support via libssh2
2121
.@"tls-backend" = .openssl, // use openssl instead of mbedtls
2222
});
23+
your_compile_step.root_module.addImport("git2", libgit_dep.module("git2"));
24+
// or if you only need the artifact:
2325
your_compile_step.linkLibrary(libgit_dep.artifact("git2"));
2426
```
25-
26-
Don't forget to import headers too:
27-
```zig
28-
const c = @cImport({
29-
@cInclude("git2.h");
30-
});
31-
```

build.zig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,17 @@ pub fn build(b: *std.Build) !void {
366366
lib.installHeadersDirectory(libgit_src.path("include"), "", .{});
367367
b.installArtifact(lib);
368368

369+
const translate_c = b.addTranslateC(.{
370+
.root_source_file = libgit_src.path("include/git2.h"),
371+
.target = target,
372+
.optimize = optimize,
373+
});
374+
375+
translate_c.addIncludePath(libgit_src.path("include"));
376+
377+
const git2_module = translate_c.addModule("git2");
378+
git2_module.linkLibrary(lib);
379+
369380
const cli_step = b.step("run-cli", "Build and run the command-line interface");
370381
{
371382
const cli = b.createModule(.{

0 commit comments

Comments
 (0)