-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
87 lines (73 loc) · 2.48 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const name = "findup";
// Compile
const compile_step = b.step("findup", "Install findup executable");
const cross_step = b.step("cross", "Generate cross-compiled executables");
const source = std.Build.FileSource.relative("src/main.zig");
const exe = b.addExecutable(.{
.name = name,
.root_source_file = source,
.optimize = optimize,
.target = target,
});
const install_exe = b.addInstallArtifact(exe, .{});
compile_step.dependOn(&install_exe.step);
b.default_step.dependOn(compile_step);
// Cross-compile
inline for (TRIPLES) |TRIPLE| {
const cross = b.addExecutable(.{
.name = name,
.root_source_file = source,
.optimize = optimize,
.target = try std.zig.CrossTarget.parse(.{ .arch_os_abi = TRIPLE }),
});
const cross_install = b.addInstallArtifact(cross, .{
.dest_dir = .{ .override = .{ .custom = "cross/" ++ TRIPLE } },
});
const cross_tar = b.addSystemCommand(&.{ "sh", "-c", "tar -czvf findup-" ++ TRIPLE ++ ".tgz findup" });
cross_tar.cwd = "./zig-out/cross/" ++ TRIPLE;
cross_tar.step.dependOn(&cross_install.step);
cross_step.dependOn(&cross_tar.step);
}
// Tests
const testSource = std.Build.FileSource.relative("src/test.zig");
const test_exe = b.addTest(.{
.root_source_file = testSource,
.optimize = optimize,
.target = target,
});
const test_run = b.addRunArtifact(test_exe);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(compile_step);
test_step.dependOn(&test_run.step);
b.default_step.dependOn(test_step);
}
const TRIPLES = .{
"aarch64-linux-gnu",
"aarch64-linux-musleabi",
"aarch64-macos-none",
"arm-linux-musleabi",
"arm-linux-musleabihf",
"mips-linux-gnu",
"mips-linux-musl",
"mips64-linux-gnuabi64",
"mips64-linux-musl",
"mips64el-linux-gnuabi64",
"mips64el-linux-musl",
"mipsel-linux-gnu",
"mipsel-linux-musl",
"powerpc-linux-gnu",
"powerpc-linux-musl",
"powerpc64le-linux-gnu",
"powerpc64le-linux-musl",
"riscv64-linux-gnu",
"riscv64-linux-musl",
"x86_64-linux-gnu",
"x86_64-linux-musl",
"x86_64-macos-none",
"x86-linux-gnu",
"x86-linux-musl",
};