-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
62 lines (61 loc) · 2.01 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
const std = @import("std");
pub fn build(b: *std.build.Builder) !void {
// Add standard target options
const target = b.standardTargetOptions(.{});
// Add standard release options
const mode = b.standardReleaseOptions();
// Add the library
const girepository = b.addStaticLibrary("girepository", "src/lib.zig");
girepository.setBuildMode(mode);
girepository.install();
// Add the unit tests
const unit_tests_step = b.step("test", "Run the unit tests");
const unit_tests = b.addTest("src/lib.zig");
unit_tests.setBuildMode(mode);
unit_tests_step.dependOn(&unit_tests.step);
unit_tests.test_evented_io = true;
// Define the library package
const lib_pkg = std.build.Pkg{
.name = "gir",
.source = .{ .path = "src/lib.zig" },
.dependencies = &.{},
};
// Add the generate executable
const generate = b.addExecutable("generate", "generate/main.zig");
// For each executable
inline for (.{
.{ generate, "Generate the bindings" },
}) |tuple| {
// Unpack the tuple
const step = tuple[0];
const run_step_name = tuple[1];
// Make sure they can be built and installed
step.setTarget(target);
step.setBuildMode(mode);
step.install();
// Add the library package
step.addPackage(lib_pkg);
// Add a run step
if (step.install_step) |install_step| {
const run_step = b.step(step.name, run_step_name);
const run_cmd = step.run();
run_cmd.step.dependOn(&install_step.step);
if (b.args) |args| {
run_cmd.addArgs(args);
}
run_step.dependOn(&run_cmd.step);
}
}
// Add the dependencies
inline for (.{
generate,
girepository,
unit_tests,
}) |step| {
// Link the libraries
step.linkLibC();
step.linkSystemLibrary("gobject-introspection-1.0");
// Use the `stage1` compiler
step.use_stage1 = true;
}
}