-
Notifications
You must be signed in to change notification settings - Fork 24
/
build.zig
94 lines (82 loc) · 3.11 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
88
89
90
91
92
93
94
const std = @import("std");
// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
pub fn build(b: *std.Build) !void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
if (!(target.getOsTag() == .linux)) {
@panic("sorry, this can just compile for linux");
}
if (!(target.getCpuArch() == .x86_64)) {
@panic("sorry, this can just compile for x86_64");
}
const linux_arm_cmd = &[_][]const u8{
"/bin/sh",
"-c",
try std.mem.concat(b.allocator, u8, &[_][]const u8{
"CGO_ENABLED=1 ",
"CC='zig cc -target aarch64-linux-musl' ",
"CXX='zig cc -target aarch64-linux-musl' ",
"CGO_CFLAGS='-D_LARGEFILE64_SOURCE' ",
"GOOS=linux ",
"GOARCH=arm64 ",
"go ",
"build ",
"-ldflags='-linkmode=external -extldflags -static -s -w' ",
"-o movie-getter_linux-arm64-musl ",
}),
};
const linux_arm_build_cmd = b.addSystemCommand(linux_arm_cmd);
const linux_cmd = &[_][]const u8{
"/bin/sh",
"-c",
try std.mem.concat(b.allocator, u8, &[_][]const u8{
"CGO_ENABLED=1 ",
"CC='zig cc -target x86_64-linux-musl' ",
"CXX='zig cc -target x86_64-linux-musl' ",
"CGO_CFLAGS='-D_LARGEFILE64_SOURCE' ",
"GOOS=linux ",
"GOARCH=amd64 ",
"go ",
"build ",
"-ldflags='-linkmode=external -extldflags -static -s -w' ",
"-o movie-getter_linux_x86-64_musl ",
}),
};
const linux_build_cmd = b.addSystemCommand(linux_cmd);
const windows_cmd = &[_][]const u8{
"/bin/sh",
"-c",
try std.mem.concat(b.allocator, u8, &[_][]const u8{
"CGO_ENABLED=1 ",
"CC='zig cc -target x86_64-windows' ",
"CXX='zig cc -target x86_64-windows' ",
"CGO_CFLAGS='-D_LARGEFILE64_SOURCE' ",
"GOOS=windows ",
"GOARCH=amd64 ",
"go ",
"build ",
"-ldflags='-s -w' ",
"-o movie-getter_windows_x86-64",
}),
};
const windows_build_cmd = b.addSystemCommand(windows_cmd);
const build_step = b.step("build", "build movie");
build_step.dependOn(&windows_build_cmd.step);
build_step.dependOn(&linux_build_cmd.step);
b.getInstallStep().dependOn(&linux_arm_build_cmd.step);
b.getInstallStep().dependOn(&windows_build_cmd.step);
b.getInstallStep().dependOn(&linux_build_cmd.step);
const clean = &[_][]const u8{
"/bin/sh",
"-c",
"rm movie",
};
const clean_cmd = b.addSystemCommand(clean);
const clean_step = b.step("clean", "clean all");
clean_step.dependOn(&clean_cmd.step);
}