-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
117 lines (106 loc) · 4.72 KB
/
build.zig
File metadata and controls
117 lines (106 loc) · 4.72 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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Homegrown regex engine, used to back JS RegExp.
const regex_dep = b.dependency("zig_regex", .{ .target = target, .optimize = optimize });
const regex_mod = regex_dep.module("regex");
// The importable module: `@import("js")` once a consumer adds this package.
const mod = b.addModule("js", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.imports = &.{.{ .name = "regex", .module = regex_mod }},
});
// A static library exposing the JavaScriptCore C-API drop-in symbols
// (JSGlobalContextCreate, JSEvaluateScript, ...). Linking this in place of
// the system `JavaScriptCore` framework makes the engine a drop-in.
const lib = b.addLibrary(.{
.linkage = .static,
.name = "zig-js",
.root_module = b.createModule(.{
.root_source_file = b.path("src/c_api.zig"),
.target = target,
.optimize = optimize,
.imports = &.{.{ .name = "regex", .module = regex_mod }},
}),
});
b.installArtifact(lib);
// Unit tests over the root module (engine core + C-API).
const tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.imports = &.{.{ .name = "regex", .module = regex_mod }},
}),
});
const run_tests = b.addRunArtifact(tests);
const test_step = b.step("test", "Run zig-js unit tests");
test_step.dependOn(&run_tests.step);
// Conformance runner: `zig build conformance` reports the pass percentage
// over the curated (test262-style) suite.
const conformance = b.addExecutable(.{
.name = "conformance",
.root_module = b.createModule(.{
.root_source_file = b.path("conformance/runner.zig"),
.target = target,
.optimize = optimize,
.imports = &.{.{ .name = "js", .module = mod }},
}),
});
const run_conformance = b.addRunArtifact(conformance);
const conformance_step = b.step("conformance", "Run the JS conformance suite");
conformance_step.dependOn(&run_conformance.step);
// test262 ingestion: `zig build test262 [-Dtest262=<root>]` runs the real
// tc39/test262 corpus through the engine and reports the (partial) pass
// rate. The default root is the pinned `test262` git submodule, so we always
// measure against upstream's latest (run `git submodule update --remote` to
// bump it).
const t262_root = b.option([]const u8, "test262", "Path to the test262 corpus root") orelse
"test262";
const t262_options = b.addOptions();
t262_options.addOption([]const u8, "root", t262_root);
const test262 = b.addExecutable(.{
.name = "test262",
.root_module = b.createModule(.{
.root_source_file = b.path("conformance/test262.zig"),
.target = target,
.optimize = optimize,
.imports = &.{.{ .name = "js", .module = mod }},
}),
});
test262.root_module.addOptions("build_options", t262_options);
const run_test262 = b.addRunArtifact(test262);
if (b.args) |args| run_test262.addArgs(args);
const test262_step = b.step("test262", "Run the real test262 corpus and report pass rate");
test262_step.dependOn(&run_test262.step);
// THROWAWAY parse-failure diagnostic.
const diag = b.addExecutable(.{
.name = "diag",
.root_module = b.createModule(.{
.root_source_file = b.path("conformance/diag.zig"),
.target = target,
.optimize = optimize,
.imports = &.{.{ .name = "js", .module = mod }},
}),
});
diag.root_module.addOptions("build_options", t262_options);
const run_diag = b.addRunArtifact(diag);
if (b.args) |args| run_diag.addArgs(args);
const diag_step = b.step("diag", "Throwaway parse-failure diagnostic");
diag_step.dependOn(&run_diag.step);
// Benchmarks: `zig build bench` times the VM against the tree-walker.
// ReleaseFast so the numbers reflect real performance, not Debug overhead.
const bench = b.addExecutable(.{
.name = "bench",
.root_module = b.createModule(.{
.root_source_file = b.path("bench/main.zig"),
.target = target,
.optimize = .ReleaseFast,
.imports = &.{.{ .name = "js", .module = mod }},
}),
});
const run_bench = b.addRunArtifact(bench);
const bench_step = b.step("bench", "Benchmark the bytecode VM against the tree-walker");
bench_step.dependOn(&run_bench.step);
}