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
|
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Dependencies
const ziglyph = b.dependency("ziglyph", .{});
// Code generation
// Grapheme break
const gbp_gen_exe = b.addExecutable(.{
.name = "gbp",
.root_source_file = .{ .path = "codegen/gbp.zig" },
.target = b.host,
.optimize = .Debug,
});
const run_gbp_gen_exe = b.addRunArtifact(gbp_gen_exe);
const gbp_gen_out = run_gbp_gen_exe.addOutputFileArg("gbp.bin.z");
// Display width
const cjk = b.option(bool, "cjk", "Ambiguouse code points are wide (display width: 2).") orelse false;
const options = b.addOptions();
options.addOption(bool, "cjk", cjk);
const dwp_gen_exe = b.addExecutable(.{
.name = "dwp",
.root_source_file = .{ .path = "codegen/dwp.zig" },
.target = b.host,
.optimize = .Debug,
});
dwp_gen_exe.root_module.addOptions("options", options);
const run_dwp_gen_exe = b.addRunArtifact(dwp_gen_exe);
const dwp_gen_out = run_dwp_gen_exe.addOutputFileArg("dwp.bin.z");
// Normalization properties
const canon_gen_exe = b.addExecutable(.{
.name = "canon",
.root_source_file = .{ .path = "codegen/canon.zig" },
.target = b.host,
.optimize = .Debug,
});
const run_canon_gen_exe = b.addRunArtifact(canon_gen_exe);
const canon_gen_out = run_canon_gen_exe.addOutputFileArg("canon.bin.z");
const compat_gen_exe = b.addExecutable(.{
.name = "compat",
.root_source_file = .{ .path = "codegen/compat.zig" },
.target = b.host,
.optimize = .Debug,
});
const run_compat_gen_exe = b.addRunArtifact(compat_gen_exe);
const compat_gen_out = run_compat_gen_exe.addOutputFileArg("compat.bin.z");
const hangul_gen_exe = b.addExecutable(.{
.name = "hangul",
.root_source_file = .{ .path = "codegen/hangul.zig" },
.target = b.host,
.optimize = .Debug,
});
const run_hangul_gen_exe = b.addRunArtifact(hangul_gen_exe);
const hangul_gen_out = run_hangul_gen_exe.addOutputFileArg("hangul.bin.z");
const normp_gen_exe = b.addExecutable(.{
.name = "normp",
.root_source_file = .{ .path = "codegen/normp.zig" },
.target = b.host,
.optimize = .Debug,
});
const run_normp_gen_exe = b.addRunArtifact(normp_gen_exe);
const normp_gen_out = run_normp_gen_exe.addOutputFileArg("normp.bin.z");
const ccc_gen_exe = b.addExecutable(.{
.name = "ccc",
.root_source_file = .{ .path = "codegen/ccc.zig" },
.target = b.host,
.optimize = .Debug,
});
const run_ccc_gen_exe = b.addRunArtifact(ccc_gen_exe);
const ccc_gen_out = run_ccc_gen_exe.addOutputFileArg("ccc.bin.z");
const gencat_gen_exe = b.addExecutable(.{
.name = "gencat",
.root_source_file = .{ .path = "codegen/gencat.zig" },
.target = b.host,
.optimize = .Debug,
});
const run_gencat_gen_exe = b.addRunArtifact(gencat_gen_exe);
const gencat_gen_out = run_gencat_gen_exe.addOutputFileArg("gencat.bin.z");
// Modules we provide
// Code points
const code_point = b.addModule("code_point", .{
.root_source_file = .{ .path = "src/code_point.zig" },
.target = target,
.optimize = optimize,
});
// Grapheme clusters
const grapheme_data = b.createModule(.{
.root_source_file = .{ .path = "src/GraphemeData.zig" },
.target = target,
.optimize = optimize,
});
grapheme_data.addAnonymousImport("gbp", .{ .root_source_file = gbp_gen_out });
const grapheme = b.addModule("grapheme", .{
.root_source_file = .{ .path = "src/grapheme.zig" },
.target = target,
.optimize = optimize,
});
grapheme.addImport("code_point", code_point);
grapheme.addImport("GraphemeData", grapheme_data);
// ASCII utilities
const ascii = b.addModule("ascii", .{
.root_source_file = .{ .path = "src/ascii.zig" },
.target = target,
.optimize = optimize,
});
// Fixed pitch font display width
const dw_data = b.createModule(.{
.root_source_file = .{ .path = "src/WidthData.zig" },
.target = target,
.optimize = optimize,
});
dw_data.addAnonymousImport("dwp", .{ .root_source_file = dwp_gen_out });
dw_data.addImport("GraphemeData", grapheme_data);
const display_width = b.addModule("DisplayWidth", .{
.root_source_file = .{ .path = "src/DisplayWidth.zig" },
.target = target,
.optimize = optimize,
});
display_width.addImport("ascii", ascii);
display_width.addImport("code_point", code_point);
display_width.addImport("grapheme", grapheme);
display_width.addImport("DisplayWidthData", dw_data);
// Normalization
const ccc_data = b.createModule(.{
.root_source_file = .{ .path = "src/CombiningData.zig" },
.target = target,
.optimize = optimize,
});
ccc_data.addAnonymousImport("ccc", .{ .root_source_file = ccc_gen_out });
const canon_data = b.createModule(.{
.root_source_file = .{ .path = "src/CanonData.zig" },
.target = target,
.optimize = optimize,
});
canon_data.addAnonymousImport("canon", .{ .root_source_file = canon_gen_out });
const compat_data = b.createModule(.{
.root_source_file = .{ .path = "src/CompatData.zig" },
.target = target,
.optimize = optimize,
});
compat_data.addAnonymousImport("compat", .{ .root_source_file = compat_gen_out });
const hangul_data = b.createModule(.{
.root_source_file = .{ .path = "src/HangulData.zig" },
.target = target,
.optimize = optimize,
});
hangul_data.addAnonymousImport("hangul", .{ .root_source_file = hangul_gen_out });
const normp_data = b.createModule(.{
.root_source_file = .{ .path = "src/NormPropsData.zig" },
.target = target,
.optimize = optimize,
});
normp_data.addAnonymousImport("normp", .{ .root_source_file = normp_gen_out });
const norm_data = b.createModule(.{
.root_source_file = .{ .path = "src/NormData.zig" },
.target = target,
.optimize = optimize,
});
norm_data.addImport("CanonData", canon_data);
norm_data.addImport("CombiningData", ccc_data);
norm_data.addImport("CompatData", compat_data);
norm_data.addImport("HangulData", hangul_data);
norm_data.addImport("NormPropsData", normp_data);
const norm = b.addModule("Normalizer", .{
.root_source_file = .{ .path = "src/Normalizer.zig" },
.target = target,
.optimize = optimize,
});
norm.addImport("code_point", code_point);
norm.addImport("ziglyph", ziglyph.module("ziglyph"));
norm.addImport("NormData", norm_data);
// General Category
const gencat_data = b.createModule(.{
.root_source_file = .{ .path = "src/GenCatData.zig" },
.target = target,
.optimize = optimize,
});
gencat_data.addAnonymousImport("gencat", .{ .root_source_file = gencat_gen_out });
// Benchmark rig
const exe = b.addExecutable(.{
.name = "zg",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
// exe.root_module.addImport("ziglyph", ziglyph.module("ziglyph"));
// exe.root_module.addImport("ascii", ascii);
exe.root_module.addImport("code_point", code_point);
// exe.root_module.addImport("grapheme", grapheme);
// exe.root_module.addImport("DisplayWidth", display_width);
// exe.root_module.addImport("Normalizer", norm);
exe.root_module.addImport("GenCatData", gencat_data);
b.installArtifact(exe);
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 the app");
run_step.dependOn(&run_cmd.step);
// Tests
const exe_unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/Normalizer.zig" },
.target = target,
.optimize = optimize,
});
// exe_unit_tests.root_module.addImport("ascii", ascii);
exe_unit_tests.root_module.addImport("code_point", code_point);
// exe_unit_tests.root_module.addImport("GraphemeData", grapheme_data);
// exe_unit_tests.root_module.addImport("grapheme", grapheme);
// exe_unit_tests.root_module.addImport("ziglyph", ziglyph.module("ziglyph"));
// exe_unit_tests.root_module.addAnonymousImport("normp", .{ .root_source_file = normp_gen_out });
// exe_unit_tests.root_module.addImport("DisplayWidthData", dw_data);
exe_unit_tests.root_module.addImport("NormData", norm_data);
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_exe_unit_tests.step);
}
|