11const std = @import ("std" );
22
3- pub fn build (b : * std.Build ) void {
4- const target = b .standardTargetOptions (.{});
3+ pub fn build (b : * std.Build ) ! void {
4+ const default_target = b .standardTargetOptions (.{});
55 const optimize = b .standardOptimizeOption (.{
66 .preferred_optimize_mode = .ReleaseSafe ,
77 });
88
99 const exe = b .addExecutable (.{
10- .name = "github_stats " ,
10+ .name = "github-stats " ,
1111 .root_module = b .createModule (.{
1212 .root_source_file = b .path ("src/main.zig" ),
13- .target = target ,
13+ .target = default_target ,
1414 .optimize = optimize ,
1515 }),
1616 });
@@ -28,4 +28,55 @@ pub fn build(b: *std.Build) void {
2828 const run_tests = b .addRunArtifact (tests );
2929 const test_step = b .step ("test" , "Run the tests" );
3030 test_step .dependOn (& run_tests .step );
31+
32+ const release_step = b .step ("release" , "Cross-compile release binaries" );
33+ const release_targets : []const std.Target.Query = &.{
34+ // Zig tier 1 supported compiler targets (manually tested)
35+ .{ .cpu_arch = .x86_64 , .os_tag = .linux },
36+ .{ .cpu_arch = .x86_64 , .os_tag = .macos },
37+ // Zig tier 2 supported compiler targets (manually tested)
38+ .{ .cpu_arch = .aarch64 , .os_tag = .macos },
39+ .{ .cpu_arch = .x86_64 , .os_tag = .windows },
40+ // Zig tier 2 supported compiler targets (untested)
41+ .{ .cpu_arch = .aarch64 , .os_tag = .freebsd },
42+ .{ .cpu_arch = .aarch64 , .os_tag = .linux },
43+ .{ .cpu_arch = .aarch64 , .os_tag = .netbsd },
44+ .{ .cpu_arch = .aarch64 , .os_tag = .windows },
45+ .{ .cpu_arch = .arm , .os_tag = .freebsd },
46+ .{ .cpu_arch = .arm , .os_tag = .linux },
47+ .{ .cpu_arch = .arm , .os_tag = .netbsd },
48+ .{ .cpu_arch = .loongarch64 , .os_tag = .linux },
49+ .{ .cpu_arch = .powerpc , .os_tag = .linux },
50+ .{ .cpu_arch = .powerpc , .os_tag = .netbsd },
51+ .{ .cpu_arch = .powerpc64 , .os_tag = .freebsd },
52+ .{ .cpu_arch = .powerpc64 , .os_tag = .linux },
53+ .{ .cpu_arch = .powerpc64le , .os_tag = .freebsd },
54+ .{ .cpu_arch = .powerpc64le , .os_tag = .linux },
55+ .{ .cpu_arch = .riscv32 , .os_tag = .linux },
56+ .{ .cpu_arch = .riscv64 , .os_tag = .freebsd },
57+ .{ .cpu_arch = .riscv64 , .os_tag = .linux },
58+ .{ .cpu_arch = .thumb , .os_tag = .windows },
59+ .{ .cpu_arch = .thumb , .os_tag = .linux },
60+ // Fails with error due to networking
61+ // .{ .cpu_arch = .wasm32, .os_tag = .wasi },
62+ .{ .cpu_arch = .x86 , .os_tag = .linux },
63+ .{ .cpu_arch = .x86 , .os_tag = .windows },
64+ .{ .cpu_arch = .x86_64 , .os_tag = .freebsd },
65+ .{ .cpu_arch = .x86_64 , .os_tag = .netbsd },
66+ };
67+ for (release_targets ) | t | {
68+ const cross_exe = b .addExecutable (.{
69+ .name = try std .fmt .allocPrint (
70+ b .allocator ,
71+ "github-stats_{s}" ,
72+ .{try t .zigTriple (b .allocator )},
73+ ),
74+ .root_module = b .createModule (.{
75+ .root_source_file = b .path ("src/main.zig" ),
76+ .target = b .resolveTargetQuery (t ),
77+ .optimize = .ReleaseFast ,
78+ }),
79+ });
80+ release_step .dependOn (& b .addInstallArtifact (cross_exe , .{}).step );
81+ }
3182}
0 commit comments