-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
375 lines (320 loc) · 14.2 KB
/
Copy pathbuild.zig
File metadata and controls
375 lines (320 loc) · 14.2 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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const unicode_check = b.addExecutable(.{
.name = "unicode-check",
.root_module = b.createModule(.{
.root_source_file = b.path("tools/unicode/check.zig"),
.target = target,
.optimize = optimize,
}),
});
const unicode_check_run = b.addRunArtifact(unicode_check);
unicode_check_run.setCwd(b.path("."));
const unicode_cache_dir = b.cache_root.join(b.allocator, &.{"unicode-17-generated"}) catch @panic("out of memory");
unicode_check_run.addArg(unicode_cache_dir);
const unicode_check_step = b.step("unicode-check", "Offline regenerate and byte-compare Unicode 17 tables");
unicode_check_step.dependOn(&unicode_check_run.step);
if (onlyStepRequested(b, "unicode-check")) return;
const options = b.addOptions();
const calibration_inputs = b.option([]const u8, "calibration-inputs", "Directory containing optional score-calibration inputs");
options.addOption(?[]const u8, "calibration_inputs", calibration_inputs);
const maybe_koino_dep = b.lazyDependency("koino", .{ .target = target, .optimize = optimize });
const maybe_vaxis_dep = b.lazyDependency("vaxis", .{ .target = target, .optimize = optimize });
if (maybe_koino_dep == null or maybe_vaxis_dep == null) return;
const koino_dep = maybe_koino_dep.?;
const vaxis_dep = maybe_vaxis_dep.?;
options.addOption([]const u8, "version", "0.2.1");
const text_mod = b.createModule(.{
.root_source_file = b.path("src/lib/text.zig"),
.target = target,
.optimize = optimize,
});
const unicode_mod = b.createModule(.{
.root_source_file = b.path("src/lib/unicode.zig"),
.target = target,
.optimize = optimize,
});
const prim_mod = b.createModule(.{
.root_source_file = b.path("src/core/mermaid_v2/base/types.zig"),
.target = target,
.optimize = optimize,
});
prim_mod.addImport("unicode", unicode_mod);
const mermaid_v2_mod = b.createModule(.{
.root_source_file = b.path("src/core/mermaid_v2/entry.zig"),
.target = target,
.optimize = optimize,
});
mermaid_v2_mod.addImport("prim", prim_mod);
mermaid_v2_mod.addImport("unicode", unicode_mod);
const root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
root_module.addOptions("build_options", options);
root_module.addImport("koino", koino_dep.module("koino"));
root_module.addImport("vaxis", vaxis_dep.module("vaxis"));
root_module.addImport("prim", prim_mod);
root_module.addImport("text", text_mod);
root_module.addImport("unicode", unicode_mod);
linkExportFont(b, root_module);
const exe = b.addExecutable(.{
.name = "mercat",
.root_module = root_module,
});
b.installArtifact(exe);
options.addOption([]const u8, "mercat_exe_path", b.getInstallPath(.bin, "mercat"));
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 mercat");
run_step.dependOn(&run_cmd.step);
const test_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
test_module.addOptions("build_options", options);
test_module.addImport("koino", koino_dep.module("koino"));
test_module.addImport("vaxis", vaxis_dep.module("vaxis"));
test_module.addImport("prim", prim_mod);
test_module.addImport("text", text_mod);
test_module.addImport("unicode", unicode_mod);
linkExportFont(b, test_module);
const unit_tests = b.addTest(.{
.root_module = test_module,
});
const test_run = b.addRunArtifact(unit_tests);
test_run.step.dependOn(b.getInstallStep());
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&test_run.step);
const legacy_mermaid_test_module = b.createModule(.{
.root_source_file = b.path("src/core/mermaid/legacy_test.zig"),
.target = target,
.optimize = optimize,
});
legacy_mermaid_test_module.addImport("prim", prim_mod);
legacy_mermaid_test_module.addImport("text", text_mod);
legacy_mermaid_test_module.addImport("unicode", unicode_mod);
const legacy_mermaid_tests = b.addTest(.{ .root_module = legacy_mermaid_test_module });
const legacy_mermaid_test_run = b.addRunArtifact(legacy_mermaid_tests);
const legacy_mermaid_test_step = b.step("test-mermaid-legacy", "Run legacy Mermaid renderer tests");
legacy_mermaid_test_step.dependOn(&legacy_mermaid_test_run.step);
test_step.dependOn(&legacy_mermaid_test_run.step);
const font_test_module = b.createModule(.{
.root_source_file = b.path("src/export/font.zig"),
.target = target,
.optimize = optimize,
});
linkExportFont(b, font_test_module);
const font_tests = b.addTest(.{ .root_module = font_test_module });
const font_test_run = b.addRunArtifact(font_tests);
const font_test_step = b.step("test-export-font", "Run export font-service tests");
font_test_step.dependOn(&font_test_run.step);
test_step.dependOn(&font_test_run.step);
const sem_graph_mod = b.createModule(.{
.root_source_file = b.path("src/core/mermaid_v2/sem_graph.zig"),
.target = target,
.optimize = optimize,
});
sem_graph_mod.addImport("prim", prim_mod);
const parser_mod = b.createModule(.{
.root_source_file = b.path("src/core/mermaid_v2/parse.zig"),
.target = target,
.optimize = optimize,
});
parser_mod.addImport("prim", prim_mod);
const prop_test_module = b.createModule(.{
.root_source_file = b.path("tests/property/all.zig"),
.target = target,
.optimize = optimize,
});
prop_test_module.addImport("sem_graph", sem_graph_mod);
prop_test_module.addImport("parser", parser_mod);
prop_test_module.addImport("mermaid_v2", mermaid_v2_mod);
const prop_tests = b.addTest(.{
.root_module = prop_test_module,
});
const prop_test_run = b.addRunArtifact(prop_tests);
const prop_test_step = b.step("test-property", "Run property-based tests");
prop_test_step.dependOn(&prop_test_run.step);
test_step.dependOn(&prop_test_run.step);
const v2_test_module = b.createModule(.{
.root_source_file = b.path("src/core/mermaid_v2/entry.zig"),
.target = target,
.optimize = optimize,
});
v2_test_module.addOptions("build_options", options);
v2_test_module.addImport("prim", prim_mod);
v2_test_module.addImport("unicode", unicode_mod);
const v2_tests = b.addTest(.{ .root_module = v2_test_module });
const v2_test_run = b.addRunArtifact(v2_tests);
const v2_test_step = b.step("test-mermaid-v2", "Run mermaid_v2 unit tests");
v2_test_step.dependOn(&v2_test_run.step);
test_step.dependOn(&v2_test_run.step);
const lint_module = b.createModule(.{
.root_source_file = b.path("tools/lint_imports.zig"),
.target = target,
.optimize = optimize,
});
const lint_exe = b.addExecutable(.{
.name = "lint-imports",
.root_module = lint_module,
});
const lint_cmd = b.addRunArtifact(lint_exe);
lint_cmd.setCwd(b.path("."));
const lint_step = b.step("lint", "Run mermaid_v2 import boundary lint");
lint_step.dependOn(&lint_cmd.step);
test_step.dependOn(&lint_cmd.step);
const lint_test_module = b.createModule(.{
.root_source_file = b.path("tools/lint_imports.zig"),
.target = target,
.optimize = optimize,
});
const lint_tests = b.addTest(.{ .root_module = lint_test_module });
const lint_tests_run = b.addRunArtifact(lint_tests);
lint_tests_run.setCwd(b.path("."));
test_step.dependOn(&lint_tests_run.step);
const unicode_test_module = b.createModule(.{
.root_source_file = b.path("src/lib/unicode.zig"),
.target = target,
.optimize = optimize,
});
const unicode_tests = b.addTest(.{ .root_module = unicode_test_module });
const unicode_test_run = b.addRunArtifact(unicode_tests);
unicode_test_run.setCwd(b.path("."));
const unicode_test_step = b.step("test-unicode", "Run Unicode authority tests");
unicode_test_step.dependOn(&unicode_test_run.step);
test_step.dependOn(&unicode_test_run.step);
const visual_samples_module = b.createModule(.{
.root_source_file = b.path("tools/visual_samples.zig"),
.target = target,
.optimize = optimize,
});
visual_samples_module.addImport("mermaid_v2", mermaid_v2_mod);
const visual_samples_exe = b.addExecutable(.{
.name = "visual-samples",
.root_module = visual_samples_module,
});
const visual_samples_cmd = b.addRunArtifact(visual_samples_exe);
visual_samples_cmd.setCwd(b.path("."));
visual_samples_cmd.expectExitCode(0);
const visual_samples_step = b.step("visual-samples", "Render curated mermaid samples to docs/visual-samples.html");
visual_samples_step.dependOn(&visual_samples_cmd.step);
const has_eval = blk: {
std.fs.cwd().access("eval", .{}) catch break :blk false;
break :blk true;
};
if (has_eval) {
const internals_mod = b.createModule(.{
.root_source_file = b.path("src/core/internals_api.zig"),
.target = target,
.optimize = optimize,
});
internals_mod.addImport("prim", prim_mod);
internals_mod.addImport("text", text_mod);
internals_mod.addImport("unicode", unicode_mod);
const reconstruction_mod = b.createModule(.{
.root_source_file = b.path("eval/reconstruction_api.zig"),
.target = target,
.optimize = optimize,
});
reconstruction_mod.addImport("internals", internals_mod);
const decoder_score_module = b.createModule(.{
.root_source_file = b.path("eval/decoder_score.zig"),
.target = target,
.optimize = optimize,
});
decoder_score_module.addImport("reconstruction", reconstruction_mod);
const decoder_score_exe = b.addExecutable(.{
.name = "decoder-score",
.root_module = decoder_score_module,
});
const decoder_score_install = b.addInstallArtifact(decoder_score_exe, .{});
const decoder_score_cmd = b.addRunArtifact(decoder_score_exe);
decoder_score_cmd.step.dependOn(&decoder_score_install.step);
decoder_score_cmd.setCwd(b.path("."));
if (b.args) |args| decoder_score_cmd.addArgs(args);
const decoder_score_step = b.step("decoder-score", "Score one decoded/source mermaid pair");
decoder_score_step.dependOn(&decoder_score_install.step);
decoder_score_step.dependOn(&decoder_score_cmd.step);
const reconstruction_tests = b.addTest(.{ .root_module = reconstruction_mod });
const reconstruction_test_run = b.addRunArtifact(reconstruction_tests);
const decoder_score_tests = b.addTest(.{ .root_module = decoder_score_module });
const decoder_score_test_run = b.addRunArtifact(decoder_score_tests);
const test_eval_step = b.step("test-eval", "Run private eval scorer tests (reconstruction + decoder-score)");
test_eval_step.dependOn(&reconstruction_test_run.step);
test_eval_step.dependOn(&decoder_score_test_run.step);
const update_regressions = b.option(
bool,
"update-regressions",
"Rewrite regression goldens (owner-approved changes only)",
) orelse false;
const regression_dir = b.option(
[]const u8,
"regression-dir",
"Directory containing private byte-exact regression pins",
);
const regress_exe = b.addExecutable(.{
.name = "regress",
.root_module = b.createModule(.{
.root_source_file = b.path("eval/regress.zig"),
.target = target,
.optimize = optimize,
}),
});
const regress_cmd = b.addRunArtifact(regress_exe);
regress_cmd.step.dependOn(b.getInstallStep());
regress_cmd.setCwd(b.path("."));
regress_cmd.addArg(b.getInstallPath(.bin, "mercat"));
if (regression_dir) |path| regress_cmd.addArg(path);
if (update_regressions) regress_cmd.addArg("--update");
const regress_step = b.step("regress", "Run byte-exact rendering regression pins");
if (regression_dir != null) {
regress_step.dependOn(®ress_cmd.step);
test_step.dependOn(®ress_cmd.step);
}
}
}
fn onlyStepRequested(b: *std.Build, wanted: []const u8) bool {
const args = std.process.argsAlloc(b.allocator) catch return false;
if (args.len < 6) return false;
var found: ?[]const u8 = null;
var index: usize = 6;
while (index < args.len) : (index += 1) {
const arg = args[index];
if (std.mem.eql(u8, arg, "--")) break;
if (buildOptionTakesValue(arg)) {
index += 1;
continue;
}
if (std.mem.startsWith(u8, arg, "-")) continue;
if (found != null) return false;
found = arg;
}
return found != null and std.mem.eql(u8, found.?, wanted);
}
fn buildOptionTakesValue(arg: []const u8) bool {
const options = [_][]const u8{
"-p", "--prefix", "--prefix-lib-dir", "--prefix-exe-dir",
"--prefix-include-dir", "--sysroot", "--maxrss", "--search-prefix",
"--libc", "--color", "--summary", "--seed",
"--debounce", "--debug-log", "--libc-runtimes", "--glibc-runtimes",
};
for (options) |option| if (std.mem.eql(u8, arg, option)) return true;
return false;
}
fn linkExportFont(b: *std.Build, module: *std.Build.Module) void {
module.addIncludePath(b.path("vendor/stb"));
module.addCSourceFile(.{
.file = b.path("src/export/font_stb.c"),
.flags = &.{"-std=c11"},
});
module.link_libc = true;
module.addAnonymousImport("jetbrains_mono_ttf", .{
.root_source_file = b.path("assets/fonts/JetBrainsMono-Regular.ttf"),
});
}