summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorGravatar Sam Atman2025-07-08 12:15:32 -0400
committerGravatar Sam Atman2025-07-08 12:15:32 -0400
commit9427a9e53aaa29ee071f4dcb35b809a699d75aa9 (patch)
tree2607c185fd8053b84d60041fadc35c05a0225d34 /build.zig
parentMerge pull request 'Fix benchmarks' (#56) from jacobsandlund/zg:benchmarks in... (diff)
parentAdd Words.zig example to README (diff)
downloadzg-master.tar.gz
zg-master.tar.xz
zg-master.zip
Merge branch 'develop-next'HEADv0.14.1master
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig73
1 files changed, 56 insertions, 17 deletions
diff --git a/build.zig b/build.zig
index 58fd3e7..ca0eeef 100644
--- a/build.zig
+++ b/build.zig
@@ -11,21 +11,12 @@ pub fn build(b: *std.Build) void {
11 .optimize = optimize, 11 .optimize = optimize,
12 }); 12 });
13 13
14 // Code generation 14 //| Options
15 // Grapheme break
16 const gbp_gen_exe = b.addExecutable(.{
17 .name = "gbp",
18 .root_source_file = b.path("codegen/gbp.zig"),
19 .target = b.graph.host,
20 .optimize = .Debug,
21 });
22 const run_gbp_gen_exe = b.addRunArtifact(gbp_gen_exe);
23 const gbp_gen_out = run_gbp_gen_exe.addOutputFileArg("gbp.bin.z");
24 15
25 // Display width 16 // Display width
26 const cjk = b.option(bool, "cjk", "Ambiguous code points are wide (display width: 2).") orelse false; 17 const cjk = b.option(bool, "cjk", "Ambiguous code points are wide (display width: 2)") orelse false;
27 const options = b.addOptions(); 18 const dwp_options = b.addOptions();
28 options.addOption(bool, "cjk", cjk); 19 dwp_options.addOption(bool, "cjk", cjk);
29 20
30 // Visible Controls 21 // Visible Controls
31 const c0_width = b.option( 22 const c0_width = b.option(
@@ -33,13 +24,39 @@ pub fn build(b: *std.Build) void {
33 "c0_width", 24 "c0_width",
34 "C0 controls have this width (default: 0, <BS> <Del> default -1)", 25 "C0 controls have this width (default: 0, <BS> <Del> default -1)",
35 ); 26 );
36 options.addOption(?i4, "c0_width", c0_width); 27 dwp_options.addOption(?i4, "c0_width", c0_width);
37 const c1_width = b.option( 28 const c1_width = b.option(
38 i4, 29 i4,
39 "c1_width", 30 "c1_width",
40 "C1 controls have this width (default: 0)", 31 "C1 controls have this width (default: 0)",
41 ); 32 );
42 options.addOption(?i4, "c1_width", c1_width); 33 dwp_options.addOption(?i4, "c1_width", c1_width);
34
35 //| Offset size
36 const fat_offset = b.option(bool, "fat_offset", "Offsets in iterators and data structures will be u64") orelse false;
37 const size_config = b.addOptions();
38 size_config.addOption(bool, "fat_offset", fat_offset);
39
40 //| Code generation
41
42 // Grapheme break
43 const gbp_gen_exe = b.addExecutable(.{
44 .name = "gbp",
45 .root_source_file = b.path("codegen/gbp.zig"),
46 .target = b.graph.host,
47 .optimize = .Debug,
48 });
49 const run_gbp_gen_exe = b.addRunArtifact(gbp_gen_exe);
50 const gbp_gen_out = run_gbp_gen_exe.addOutputFileArg("gbp.bin.z");
51
52 const wbp_gen_exe = b.addExecutable(.{
53 .name = "wbp",
54 .root_source_file = b.path("codegen/wbp.zig"),
55 .target = b.graph.host,
56 .optimize = .Debug,
57 });
58 const run_wbp_gen_exe = b.addRunArtifact(wbp_gen_exe);
59 const wbp_gen_out = run_wbp_gen_exe.addOutputFileArg("wbp.bin.z");
43 60
44 const dwp_gen_exe = b.addExecutable(.{ 61 const dwp_gen_exe = b.addExecutable(.{
45 .name = "dwp", 62 .name = "dwp",
@@ -47,7 +64,7 @@ pub fn build(b: *std.Build) void {
47 .target = b.graph.host, 64 .target = b.graph.host,
48 .optimize = .Debug, 65 .optimize = .Debug,
49 }); 66 });
50 dwp_gen_exe.root_module.addOptions("options", options); 67 dwp_gen_exe.root_module.addOptions("options", dwp_options);
51 const run_dwp_gen_exe = b.addRunArtifact(dwp_gen_exe); 68 const run_dwp_gen_exe = b.addRunArtifact(dwp_gen_exe);
52 const dwp_gen_out = run_dwp_gen_exe.addOutputFileArg("dwp.bin.z"); 69 const dwp_gen_out = run_dwp_gen_exe.addOutputFileArg("dwp.bin.z");
53 70
@@ -183,12 +200,14 @@ pub fn build(b: *std.Build) void {
183 const props_gen_out = run_props_gen_exe.addOutputFileArg("props.bin.z"); 200 const props_gen_out = run_props_gen_exe.addOutputFileArg("props.bin.z");
184 201
185 // Modules we provide 202 // Modules we provide
203
186 // Code points 204 // Code points
187 const code_point = b.addModule("code_point", .{ 205 const code_point = b.addModule("code_point", .{
188 .root_source_file = b.path("src/code_point.zig"), 206 .root_source_file = b.path("src/code_point.zig"),
189 .target = target, 207 .target = target,
190 .optimize = optimize, 208 .optimize = optimize,
191 }); 209 });
210 code_point.addOptions("config", size_config);
192 211
193 const code_point_t = b.addTest(.{ 212 const code_point_t = b.addTest(.{
194 .name = "code_point", 213 .name = "code_point",
@@ -206,6 +225,7 @@ pub fn build(b: *std.Build) void {
206 }); 225 });
207 graphemes.addAnonymousImport("gbp", .{ .root_source_file = gbp_gen_out }); 226 graphemes.addAnonymousImport("gbp", .{ .root_source_file = gbp_gen_out });
208 graphemes.addImport("code_point", code_point); 227 graphemes.addImport("code_point", code_point);
228 graphemes.addOptions("config", size_config);
209 229
210 const grapheme_t = b.addTest(.{ 230 const grapheme_t = b.addTest(.{
211 .name = "Graphemes", 231 .name = "Graphemes",
@@ -215,6 +235,23 @@ pub fn build(b: *std.Build) void {
215 }); 235 });
216 const grapheme_tr = b.addRunArtifact(grapheme_t); 236 const grapheme_tr = b.addRunArtifact(grapheme_t);
217 237
238 // Word Breaking
239 const words = b.addModule("Words", .{
240 .root_source_file = b.path("src/Words.zig"),
241 .target = target,
242 .optimize = optimize,
243 });
244 words.addAnonymousImport("wbp", .{ .root_source_file = wbp_gen_out });
245 words.addImport("code_point", code_point);
246
247 const words_t = b.addTest(.{
248 .name = "WordBreak",
249 .root_module = words,
250 .target = target,
251 .optimize = optimize,
252 });
253 const words_tr = b.addRunArtifact(words_t);
254
218 // ASCII utilities 255 // ASCII utilities
219 const ascii = b.addModule("ascii", .{ 256 const ascii = b.addModule("ascii", .{
220 .root_source_file = b.path("src/ascii.zig"), 257 .root_source_file = b.path("src/ascii.zig"),
@@ -240,7 +277,7 @@ pub fn build(b: *std.Build) void {
240 display_width.addImport("ascii", ascii); 277 display_width.addImport("ascii", ascii);
241 display_width.addImport("code_point", code_point); 278 display_width.addImport("code_point", code_point);
242 display_width.addImport("Graphemes", graphemes); 279 display_width.addImport("Graphemes", graphemes);
243 display_width.addOptions("options", options); // For testing 280 display_width.addOptions("options", dwp_options); // For testing
244 281
245 const display_width_t = b.addTest(.{ 282 const display_width_t = b.addTest(.{
246 .name = "display_width", 283 .name = "display_width",
@@ -444,6 +481,7 @@ pub fn build(b: *std.Build) void {
444 }); 481 });
445 unicode_tests.root_module.addImport("Graphemes", graphemes); 482 unicode_tests.root_module.addImport("Graphemes", graphemes);
446 unicode_tests.root_module.addImport("Normalize", norm); 483 unicode_tests.root_module.addImport("Normalize", norm);
484 unicode_tests.root_module.addImport("Words", words);
447 485
448 const run_unicode_tests = b.addRunArtifact(unicode_tests); 486 const run_unicode_tests = b.addRunArtifact(unicode_tests);
449 487
@@ -452,6 +490,7 @@ pub fn build(b: *std.Build) void {
452 test_step.dependOn(&code_point_tr.step); 490 test_step.dependOn(&code_point_tr.step);
453 test_step.dependOn(&display_width_tr.step); 491 test_step.dependOn(&display_width_tr.step);
454 test_step.dependOn(&grapheme_tr.step); 492 test_step.dependOn(&grapheme_tr.step);
493 test_step.dependOn(&words_tr.step);
455 test_step.dependOn(&ascii_tr.step); 494 test_step.dependOn(&ascii_tr.step);
456 test_step.dependOn(&ccc_data_tr.step); 495 test_step.dependOn(&ccc_data_tr.step);
457 test_step.dependOn(&canon_data_tr.step); 496 test_step.dependOn(&canon_data_tr.step);