-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.zig
258 lines (211 loc) · 8.35 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
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
const std = @import("std");
pub fn build(b: *std.Build) !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
defer _ = gpa.deinit();
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// dependencies
const Dep = struct {
name: []const u8,
module: *std.Build.Module,
};
var deps = std.ArrayList(Dep).init(allocator);
defer deps.deinit();
const unicode_id = b.dependency("unicode_id", .{});
const unicode_id_dep = Dep{
.name = "unicode-id",
.module = unicode_id.module("unicode-id"),
};
try deps.appendSlice(&.{unicode_id_dep});
const util_module = b.addModule("util", .{
.root_source_file = b.path("src/util/root.zig"),
.target = target,
.optimize = optimize,
});
const jam_syntax_module = b.addModule("jam_syntax", .{
.root_source_file = b.path("src/syntax/root.zig"),
.target = target,
.optimize = optimize,
});
jam_syntax_module.addImport("util", util_module);
const jam_js_module = b.addModule("js", .{
.root_source_file = b.path("src/js/root.zig"),
.target = target,
.optimize = optimize,
});
jam_js_module.addImport("util", util_module);
jam_js_module.addImport("syntax", jam_syntax_module);
{
// wasm
const wasm_target = b.resolveTargetQuery(.{
.cpu_arch = .wasm32,
.os_tag = .freestanding,
.cpu_features_add = std.Target.wasm.featureSet(&.{
.atomics,
.bulk_memory,
// .extended_const, not supported by Safari
.multivalue,
.mutable_globals,
.nontrapping_fptoint,
.reference_types,
//.relaxed_simd, not supported by Firefox or Safari
.sign_ext,
// observed to cause Error occured during wast conversion :
// Unknown operator: 0xfd058 in Firefox 117
.simd128,
// .tail_call, not supported by Safari
}),
});
const js_wasm = b.addExecutable(.{
.name = "jam_js",
.root_source_file = b.path("src/js/lib_js_wasm.zig"),
.target = wasm_target,
.optimize = .ReleaseSmall,
});
js_wasm.entry = .disabled;
js_wasm.rdynamic = true;
js_wasm.root_module.addImport("util", util_module);
js_wasm.root_module.addImport("syntax", jam_syntax_module);
js_wasm.root_module.addImport(unicode_id_dep.name, unicode_id_dep.module);
b.installArtifact(js_wasm);
const js_wasm_file = b.addInstallFile(js_wasm.getEmittedBin(), js_wasm.out_filename);
b.getInstallStep().dependOn(&js_wasm_file.step);
}
const jam_css_module = b.addModule("jam-css", .{
.root_source_file = b.path("src/css/root.zig"),
.target = target,
.optimize = optimize,
});
jam_css_module.addImport("util", util_module);
jam_css_module.addImport("syntax", jam_syntax_module);
const jam_fmt_module = b.addModule("jam-fmt", .{
.root_source_file = b.path("src/fmt/root.zig"),
.target = target,
.optimize = optimize,
});
jam_fmt_module.addImport("util", util_module);
jam_fmt_module.addImport("js", jam_js_module);
const lib = b.addStaticLibrary(.{
.name = "jam",
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
b.installArtifact(lib);
const exe = b.addExecutable(.{
.name = "jam",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const exe_check = b.addExecutable(.{
.name = "jam_check",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe_check.root_module.addImport("js", jam_js_module);
exe_check.root_module.addImport("css", jam_css_module);
exe_check.root_module.addImport("syntax", jam_syntax_module);
const check = b.step("check", "Check if foo compiles");
check.dependOn(&exe_check.step);
b.installArtifact(exe);
// Command to run the tc39/test-262-parser-tests test suite
{
const test262 = b.addExecutable(.{
.name = "test262",
.root_source_file = b.path("tools/ec262-tests.zig"),
.target = target,
.optimize = optimize,
});
test262.root_module.addImport("js", jam_js_module);
const tests_262_cmd = b.addRunArtifact(test262);
const test_runner_step = b.step("test-262", "Run the tc39/test-262-parser-tests test suite");
test_runner_step.dependOn(&tests_262_cmd.step);
// forward all CLI arguments from build.zig to the test runner.
if (b.args) |args| {
tests_262_cmd.addArgs(args);
}
}
// Command to run the @babel/parser test suite
{
const test_babel = b.addExecutable(.{
.name = "test-babel",
.root_source_file = b.path("tools/babel-tests.zig"),
.target = target,
.optimize = optimize,
});
test_babel.root_module.addImport("js", jam_js_module);
const test_babel_cmd = b.addRunArtifact(test_babel);
const test_runner_step = b.step("test-babel", "Run the @babel/parser test suite");
test_runner_step.dependOn(&test_babel_cmd.step);
// forward all CLI arguments from build.zig to the test runner.
if (b.args) |args| {
test_babel_cmd.addArgs(args);
}
}
// Command to generate traversal code from the js AST definition
{
const ast_gen = b.addExecutable(.{
.name = "astgen",
.root_source_file = b.path("tools/gen/main.zig"),
.target = target,
.optimize = optimize,
});
const ast_gen_cmd = b.addRunArtifact(ast_gen);
const ast_gen_step = b.step("astgen", "Generate traversal code from the js AST definition");
ast_gen_step.dependOn(&ast_gen_cmd.step);
// forward all CLI arguments from build.zig to the test runner.
if (b.args) |args| {
ast_gen_cmd.addArgs(args);
}
}
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);
const lib_unit_tests = b.addTest(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
lib_unit_tests.root_module.addImport("util", util_module);
lib_unit_tests.root_module.addImport("syntax", jam_syntax_module);
lib_unit_tests.root_module.addImport("js", jam_js_module);
const js_unit_tests = b.addTest(.{
.root_source_file = b.path("./src/js/root.zig"),
.target = target,
.optimize = optimize,
});
js_unit_tests.root_module.addImport("util", util_module);
js_unit_tests.root_module.addImport("syntax", jam_syntax_module);
const util_unit_tests = b.addTest(.{
.root_source_file = b.path("src/util/root.zig"),
.target = target,
.optimize = optimize,
});
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
const run_js_unit_tests = b.addRunArtifact(js_unit_tests);
const run_util_unit_tests = b.addRunArtifact(util_unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
test_step.dependOn(&run_js_unit_tests.step);
test_step.dependOn(&run_util_unit_tests.step);
exe.root_module.addImport("fmt", jam_fmt_module);
exe.root_module.addImport("js", jam_js_module);
exe.root_module.addImport("css", jam_css_module);
exe.root_module.addImport("syntax", jam_syntax_module);
for (deps.items) |dep| {
jam_js_module.addImport(dep.name, dep.module);
jam_css_module.addImport(dep.name, dep.module);
lib.root_module.addImport(dep.name, dep.module);
lib_unit_tests.root_module.addImport(dep.name, dep.module);
js_unit_tests.root_module.addImport(dep.name, dep.module);
exe.root_module.addImport(dep.name, dep.module);
exe_check.root_module.addImport(dep.name, dep.module);
}
}