-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
175 lines (161 loc) · 8.69 KB
/
Copy pathbuild.zig
File metadata and controls
175 lines (161 loc) · 8.69 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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// ── Parser library module ─────────────────────────────
const lib_mod = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
// Expose as a named module so external projects can depend on it.
_ = b.addModule("es-parser", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
// ── Unit tests (embedded in src/) ────────────────────
const unit_tests = b.addTest(.{ .root_module = lib_mod });
const run_unit_tests = b.addRunArtifact(unit_tests);
// ── Parser tests ─────────────────────────────────────
const parser_test_mod = b.createModule(.{
.root_source_file = b.path("tests/parser_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
parser_test_mod.addImport("es_parser", lib_mod);
const parser_tests = b.addTest(.{ .root_module = parser_test_mod });
const run_parser_tests = b.addRunArtifact(parser_tests);
// ── Lexer tests ───────────────────────────────────────
const lexer_test_mod = b.createModule(.{
.root_source_file = b.path("tests/lexer_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
lexer_test_mod.addImport("es_parser", lib_mod);
const lexer_tests = b.addTest(.{ .root_module = lexer_test_mod });
const run_lexer_tests = b.addRunArtifact(lexer_tests);
// ── Semantic tests ────────────────────────────────────
const semantic_test_mod = b.createModule(.{
.root_source_file = b.path("tests/semantic_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
semantic_test_mod.addImport("es_parser", lib_mod);
const semantic_tests = b.addTest(.{ .root_module = semantic_test_mod });
const run_semantic_tests = b.addRunArtifact(semantic_tests);
// ── Fuzz tests ────────────────────────────────────────
// Run normally: each corpus entry is fed once (regression mode).
// Run with `zig build test --fuzz` to engage the coverage-directed
// mutation engine for continuous bug-finding.
const fuzz_test_mod = b.createModule(.{
.root_source_file = b.path("tests/fuzz_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
fuzz_test_mod.addImport("es_parser", lib_mod);
const fuzz_tests = b.addTest(.{ .root_module = fuzz_test_mod });
const run_fuzz_tests = b.addRunArtifact(fuzz_tests);
// ── Conformance: test262-parser-tests (always run, submodule included) ──
// Shared ReleaseFast build of the parser, reused by the bundled test-step
// runner below and every standalone conformance runner.
const conf_releaseFast = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = .ReleaseFast,
.link_libc = true,
});
const ptr_mod = b.createModule(.{
.root_source_file = b.path("tests/conformance/parser_tests_runner.zig"),
.target = target,
.optimize = .ReleaseFast,
.link_libc = true,
});
ptr_mod.addImport("es_parser", conf_releaseFast);
const ptr_exe = b.addExecutable(.{ .name = "parser_tests_runner", .root_module = ptr_mod });
const ptr_cmd = b.addRunArtifact(ptr_exe);
ptr_cmd.addArg("tests/conformance/test262-parser-tests");
ptr_cmd.addArg("--compact");
const test_step = b.step("test", "Run all tests");
test_step.dependOn(&run_unit_tests.step);
test_step.dependOn(&run_parser_tests.step);
test_step.dependOn(&run_lexer_tests.step);
test_step.dependOn(&run_semantic_tests.step);
test_step.dependOn(&run_fuzz_tests.step);
test_step.dependOn(&ptr_cmd.step);
// ── Static analysis: zbc ─────────────────────────────
const zbc_dep = b.dependency("zbc", .{ .target = target, .optimize = optimize });
const zbc_engine_mod = b.createModule(.{
.root_source_file = zbc_dep.path("src/type_engine/engine.zig"),
.target = target,
.optimize = optimize,
});
const zbc_exe_mod = b.createModule(.{
.root_source_file = zbc_dep.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
zbc_exe_mod.addImport("type_engine", zbc_engine_mod);
const zbc_exe = b.addExecutable(.{ .name = "zbc", .root_module = zbc_exe_mod });
const zbc_run = b.addRunArtifact(zbc_exe);
zbc_run.addDirectoryArg(b.path("src"));
b.default_step.dependOn(&zbc_run.step);
// ── Conformance runners ───────────────────────────────
// Executables that run against fixture directories. Each step runs its
// default fixture path so `zig build conformance-X` works with no arguments.
// (`-- <dir>` override only works on older Zig that still exposes `b.args`;
// the current build system drops trailing args, so the default is canonical.)
// NOTE: the TypeScript input set is `tests/cases` — the runner derives error
// baselines from a sibling `tests/baselines/reference`, so it must NOT be
// pointed at the whole tree.
addConformanceRunner(b, target, conf_releaseFast, "parser_tests_runner", "tests/conformance/parser_tests_runner.zig", "conformance-parser-tests", "Run tc39/test262-parser-tests conformance suite", "tests/conformance/test262-parser-tests");
addConformanceRunner(b, target, conf_releaseFast, "test262_runner", "tests/conformance/test262_runner.zig", "conformance-test262", "Run tc39/test262 conformance suite", "tests/conformance/test262");
addConformanceRunner(b, target, conf_releaseFast, "babel_runner", "tests/conformance/babel_runner.zig", "conformance-babel", "Run Babel parser conformance suite", "tests/conformance/babel/packages/babel-parser/test/fixtures");
addConformanceRunner(b, target, conf_releaseFast, "typescript_runner", "tests/conformance/typescript_runner.zig", "conformance-typescript", "Run TypeScript parser conformance suite", "tests/conformance/typescript/tests/cases");
// Robustness sweep: run the full parse + semantic pipeline over the large
// real-world TypeScript corpus (≈19k files) to catch analyzer crashes/OOM.
// It tallies scope/symbol/ref/diagnostic structure — it is NOT a correctness
// gate (no expected-output comparison). Needs the `typescript` submodule.
addConformanceRunner(b, target, conf_releaseFast, "semantic_runner", "tests/conformance/semantic_runner.zig", "conformance-semantic", "Semantic-analysis robustness sweep over the TypeScript corpus", "tests/conformance/typescript/tests/cases");
}
/// Wire up one standalone conformance runner: a ReleaseFast executable built
/// from `src`, importing the shared parser module `dep`, exposed as build step
/// `step_name`. Runs against `default_fixture` unless `-- <args>` overrides it.
fn addConformanceRunner(
b: *std.Build,
target: std.Build.ResolvedTarget,
dep: *std.Build.Module,
name: []const u8,
src: []const u8,
step_name: []const u8,
desc: []const u8,
default_fixture: []const u8,
) void {
const mod = b.createModule(.{
.root_source_file = b.path(src),
.target = target,
.optimize = .ReleaseFast,
.link_libc = true,
});
mod.addImport("es_parser", dep);
const exe = b.addExecutable(.{ .name = name, .root_module = mod });
const cmd = b.addRunArtifact(exe);
cmd.step.dependOn(b.getInstallStep());
// `-- <args>` overrides the default fixture path; with no args, run the
// documented conformance input set so `zig build conformance-X` just works.
// `b.args` only exists on some Zig versions — guard with @hasField so this
// compiles across the supported range (the field was removed after dev.305).
if (@hasField(@TypeOf(b.*), "args")) {
if (b.args) |args| cmd.addArgs(args) else cmd.addArg(default_fixture);
} else {
cmd.addArg(default_fixture);
}
b.step(step_name, desc).dependOn(&cmd.step);
}