-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.zig
72 lines (59 loc) · 2.17 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
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{
.preferred_optimize_mode = .ReleaseSafe
});
const root_source_file = .{ .path = "src/main.zig" };
const exe = b.addExecutable(.{
.name = "habu",
.root_source_file = root_source_file,
.target = target,
.optimize = optimize,
.link_libc = true,
});
b.installArtifact(exe);
const build_opts = b.addOptions();
exe.addOptions("build_options", build_opts);
const version = "dev";
build_opts.addOption([]const u8, "version", version);
const git_commit_hash = b.exec(&.{"git", "rev-parse", "HEAD"});
build_opts.addOption([]const u8, "git_commit_hash", git_commit_hash[0..git_commit_hash.len - 1]); // Skip ending newline
const cross_step = b.step("cross", "Install cross-compiled executables");
inline for (triples) |triple| {
const cross = b.addExecutable(.{
.name = "habu-" ++ triple,
.root_source_file = root_source_file,
.optimize = optimize,
.target = try std.zig.CrossTarget.parse(.{ .arch_os_abi = triple }),
.link_libc = true,
});
cross.addOptions("build_options", build_opts);
cross.strip = true;
const cross_install = b.addInstallArtifact(cross, .{});
cross_step.dependOn(&cross_install.step);
}
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const test_step = b.step("test", "Run tests");
const tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.optimize = optimize,
.target = target,
.link_libc = true,
});
const run_tests = b.addRunArtifact(tests);
run_tests.step.dependOn(b.getInstallStep());
test_step.dependOn(&run_tests.step);
}
const triples = .{
"x86_64-linux-gnu",
"aarch64-macos-none",
"x86_64-macos-none",
"x86_64-windows-gnu",
};