This repository has been archived by the owner on Jan 2, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.zig
73 lines (60 loc) · 2.2 KB
/
build.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const module = b.addModule("git", .{
.source_file = .{ .path = "src/git.zig" },
});
// Tests
{
const lib_test = b.addTest(.{
.root_source_file = .{ .path = "src/tests.zig" },
.target = target,
.optimize = optimize,
});
addLibGit(lib_test, module);
const run_lib_test = b.addRunArtifact(lib_test);
const lib_test_step = b.step("test_lib", "Run the lib tests");
lib_test_step.dependOn(&run_lib_test.step);
const sample_test = b.addTest(.{
.root_source_file = .{ .path = "sample.zig" },
.target = target,
.optimize = optimize,
});
addLibGit(sample_test, module);
const run_sample_test = b.addRunArtifact(sample_test);
const sample_test_step = b.step("test_sample", "Run the sample tests");
sample_test_step.dependOn(&run_sample_test.step);
const test_step = b.step("test", "Run all the tests");
test_step.dependOn(lib_test_step);
test_step.dependOn(sample_test_step);
b.default_step = test_step;
}
// Sample
{
const sample_exe = b.addExecutable(.{
.name = "sample",
.root_source_file = .{ .path = "sample.zig" },
.target = target,
.optimize = optimize,
});
addLibGit(sample_exe, module);
b.installArtifact(sample_exe);
const run_cmd = b.addRunArtifact(sample_exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the sample");
run_step.dependOn(&run_cmd.step);
}
}
// TODO: Support optionally adding libgit2 source directly
pub fn addLibGit(exe: *std.Build.CompileStep, module: *std.Build.Module) void {
exe.addModule("git", module);
exe.linkLibC();
// TODO: Don't hard code this...
exe.addIncludePath("../libgit2/include");
exe.addLibraryPath("../libgit2/build");
exe.linkSystemLibraryName("git2");
}