-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathbuild.zig
More file actions
66 lines (60 loc) · 2.06 KB
/
build.zig
File metadata and controls
66 lines (60 loc) · 2.06 KB
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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const root_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const exe = b.addExecutable(.{
.name = "ztk",
.root_module = root_mod,
});
b.installArtifact(exe);
// Run step: `zig build run -- <args>`
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 ztk");
run_step.dependOn(&run_cmd.step);
// Test step: `zig build test`
const unit_tests = b.addTest(.{
.root_module = root_mod,
});
const run_tests = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_tests.step);
// Cross-compile step: `zig build cross`
// Builds ReleaseSmall binaries for multiple targets into zig-out/cross/<triple>/ztk
const cross_step = b.step("cross", "Cross-compile ReleaseSmall for all targets");
const cross_targets = [_][]const u8{
"aarch64-macos",
"x86_64-macos",
"aarch64-linux-musl",
"x86_64-linux-musl",
"x86_64-windows",
};
for (cross_targets) |triple| {
const resolved = b.resolveTargetQuery(
std.Target.Query.parse(.{ .arch_os_abi = triple }) catch unreachable,
);
const cross_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = resolved,
.optimize = .ReleaseSmall,
});
const cross_exe = b.addExecutable(.{
.name = "ztk",
.root_module = cross_mod,
});
const install = b.addInstallArtifact(cross_exe, .{
.dest_dir = .{
.override = .{ .custom = b.fmt("cross/{s}", .{triple}) },
},
});
cross_step.dependOn(&install.step);
}
}