-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.zig
189 lines (170 loc) · 6.63 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
const std = @import("std");
pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});
const strip = b.option(bool, "strip", "") orelse false;
const clap_module = b.createModule(.{
.source_file = .{ .path = "lib/zig-clap/clap.zig" },
});
const crc_module = b.createModule(.{
.source_file = .{ .path = "lib/zig-crc/crc.zig" },
});
const folders_module = b.createModule(.{
.source_file = .{ .path = "lib/known-folders/known-folders.zig" },
});
const ston_module = b.createModule(.{
.source_file = .{ .path = "lib/ston/ston.zig" },
});
const ziter_module = b.createModule(.{
.source_file = .{ .path = "lib/ziter/ziter.zig" },
});
const util_module = b.createModule(.{
.source_file = .{ .path = "src/util.zig" },
.dependencies = &.{
.{ .name = "clap", .module = clap_module },
.{ .name = "folders", .module = folders_module },
},
});
const core_module = b.createModule(.{
.source_file = .{ .path = "src/core.zig" },
.dependencies = &.{
.{ .name = "ston", .module = ston_module },
.{ .name = "util", .module = util_module },
.{ .name = "crc", .module = crc_module },
},
});
const modules = [_]std.Build.ModuleDependency{
.{ .name = "clap", .module = clap_module },
.{ .name = "folders", .module = folders_module },
.{ .name = "ston", .module = ston_module },
.{ .name = "ziter", .module = ziter_module },
.{ .name = "core", .module = core_module },
.{ .name = "util", .module = util_module },
};
const exes = [_][]const u8{
"src/core/tm35-apply.zig",
"src/core/tm35-disassemble-scripts.zig",
"src/core/tm35-gen3-offsets.zig",
"src/core/tm35-identify.zig",
"src/core/tm35-load.zig",
"src/core/tm35-nds-extract.zig",
"src/randomizers/tm35-randomize-field-items.zig",
"src/randomizers/tm35-randomize-machines.zig",
"src/randomizers/tm35-randomize-names.zig",
"src/randomizers/tm35-randomize-pokemons.zig",
"src/randomizers/tm35-randomize-starters.zig",
"src/randomizers/tm35-randomize-static-encounters.zig",
"src/randomizers/tm35-randomize-trainers.zig",
"src/randomizers/tm35-randomize-wild-encounters.zig",
"src/randomizers/tm35-random-stones.zig",
"src/other/tm35-balance-pokemons.zig",
"src/other/tm35-generate-site.zig",
"src/other/tm35-misc.zig",
"src/other/tm35-noop.zig",
"src/other/tm35-no-trade-evolutions.zig",
"src/gui/tm35-randomizer.zig",
};
const test_step = b.step("test", "Run all tests");
for (exes) |path| {
const basename = std.fs.path.basename(path);
const name = basename[0 .. basename.len - 4]; // Remove `.zig`
const test_name = b.fmt("test-{s}", .{name});
const step = b.step(name, b.fmt("Build and install {s}", .{name}));
const exe_test_step = b.step(test_name, b.fmt("Test {s}", .{name}));
const exe = b.addExecutable(.{
.name = name,
.root_source_file = .{ .path = path },
.optimize = optimize,
.target = target,
});
const test_exe = b.addTest(.{
.name = test_name,
.root_source_file = .{ .path = path },
.optimize = optimize,
.target = target,
});
const run_test = b.addRunArtifact(test_exe);
step.dependOn(&b.addInstallArtifact(exe, .{}).step);
step.dependOn(&exe.step);
b.default_step.dependOn(step);
exe_test_step.dependOn(&run_test.step);
test_step.dependOn(exe_test_step);
if (std.mem.startsWith(u8, path, "src/gui/")) {
buildAndLinkMd4c(exe);
buildAndLinkNativeFileDialog(exe, target);
buildAndLinkWebview(exe, target);
exe.linkLibC();
exe.linkLibCpp();
exe.linkSystemLibrary("m");
}
for ([_]*std.Build.CompileStep{ exe, test_exe }) |comp| {
comp.strip = strip;
for (modules) |module|
comp.addModule(module.name, module.module);
}
}
const test_util = b.addTest(.{
.name = "test-util",
.root_source_file = .{ .path = "src/util.zig" },
.optimize = optimize,
.target = target,
});
const test_core = b.addTest(.{
.name = "test-core",
.root_source_file = .{ .path = "src/core.zig" },
.optimize = optimize,
.target = target,
});
for (modules) |module| {
test_util.addModule(module.name, module.module);
test_core.addModule(module.name, module.module);
}
const run_test_util = b.addRunArtifact(test_util);
const run_test_core = b.addRunArtifact(test_core);
test_step.dependOn(&run_test_util.step);
test_step.dependOn(&run_test_core.step);
}
fn buildAndLinkWebview(exe: *std.Build.CompileStep, target: std.zig.CrossTarget) void {
exe.addIncludePath(.{ .path = "lib/webview" });
exe.addCSourceFiles(.{
.files = &.{"lib/webview/webview.cc"},
.flags = &.{ "-std=c++17", "-DWEBVIEW_STATIC" },
});
switch (target.getOsTag()) {
.windows => {
exe.addIncludePath(.{ .path = "lib/webview-c/ms.webview2/include" });
exe.linkSystemLibrary("advapi32");
exe.linkSystemLibrary("shlwapi");
exe.linkSystemLibrary("version");
},
.linux => {
exe.linkSystemLibrary("webkit2gtk-4.0");
},
else => unreachable, // TODO: More os support
}
}
fn buildAndLinkMd4c(exe: *std.Build.CompileStep) void {
exe.addCSourceFiles(.{
.files = &.{
"lib/md4c/src/entity.c",
"lib/md4c/src/md4c.c",
"lib/md4c/src/md4c-html.c",
},
});
exe.addIncludePath(.{ .path = "lib/md4c/src" });
}
fn buildAndLinkNativeFileDialog(exe: *std.Build.CompileStep, target: std.zig.CrossTarget) void {
exe.addCSourceFiles(.{ .files = &.{"lib/nativefiledialog/src/nfd_common.c"} });
exe.addIncludePath(.{ .path = "lib/nativefiledialog/src/include" });
switch (target.getOsTag()) {
.windows => {
exe.addCSourceFiles(.{ .files = &.{"lib/nativefiledialog/src/nfd_win.cpp"} });
exe.linkSystemLibrary("uuid");
},
.linux => {
exe.addCSourceFiles(.{ .files = &.{"lib/nativefiledialog/src/nfd_zenity.c"} });
exe.linkSystemLibrary("webkit2gtk-4.0");
},
else => unreachable, // TODO: More os support
}
}