-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
119 lines (103 loc) · 3.79 KB
/
Copy pathbuild.zig
File metadata and controls
119 lines (103 loc) · 3.79 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
const std = @import("std");
const Generator = @import("src/build/Generator.zig");
const AnonItem = @import("src/build/AnonItem.zig");
const DependItem = @import("src/build/DependItem.zig");
const test_targets = [_]std.Target.Query{
.{}, // native
};
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
var anon_imports: std.ArrayList(AnonItem) = .empty;
var depends: std.ArrayList(DependItem) = .empty;
const test_step = b.step("test", "Run all tests");
const bench_step = b.step("bench", "Benchmark the HTML and CSS parsers");
// config
const debug = b.option(bool, "debug", "show debug information") orelse false;
const options = b.addOptions();
options.addOption(bool, "debug", debug);
// dependencies
const strale = b.dependency("strale", .{
.target = target,
.optimize = optimize,
});
try depends.append(b.allocator, .{ .name = "strale", .dep = strale, .module = "strale" });
// generate
const named_ref_module = Generator.generate(
b,
"gen_named_ref",
"./src/gen/named_ref.zig",
&.{"./res/json/named_char_refs.json"},
"gen_named_ref.zig",
depends,
);
const local_name_module = Generator.generate(
b,
"gen_local_name",
"./src/gen/local_name.zig",
&.{"./res/json/local_names.json"},
"gen_local_name.zig",
depends,
);
const encoding_indexes_module = Generator.generate(
b,
"gen_encoding_indexes",
"./src/gen/encoding_indexes.zig",
&.{"./res/json/encoding_indexes.json"},
"gen_encoding_indexes.zig",
depends,
);
try anon_imports.append(b.allocator, .{ .name = "named_ref", .module = named_ref_module });
try anon_imports.append(b.allocator, .{ .name = "local_name", .module = local_name_module });
try anon_imports.append(b.allocator, .{ .name = "encoding_indexes", .module = encoding_indexes_module });
// executable
const exe_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
moduleAddCommon(exe_module, anon_imports, depends, options);
const exe = b.addExecutable(.{ .name = "main", .root_module = exe_module });
const bench_module = b.createModule(.{
.root_source_file = b.path("src/bench.zig"),
.target = target,
.optimize = .ReleaseFast,
});
moduleAddCommon(bench_module, anon_imports, depends, options);
const bench_exe = b.addExecutable(.{
.name = "parser-benchmark",
.root_module = bench_module,
});
const run_bench = b.addRunArtifact(bench_exe);
if (b.args) |args| run_bench.addArgs(args);
bench_step.dependOn(&run_bench.step);
// test
for (test_targets) |t| {
const test_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = b.resolveTargetQuery(t),
});
moduleAddCommon(test_module, anon_imports, depends, options);
const unit_tests = b.addTest(.{ .name = "tests", .root_module = test_module });
if (b.args) |args| {
if (args.len > 0) unit_tests.filters = args;
}
const run_unit_tests = b.addRunArtifact(unit_tests);
test_step.dependOn(&run_unit_tests.step);
}
b.installArtifact(exe);
}
fn moduleAddCommon(
m: *std.Build.Module,
anon_imports: std.ArrayList(AnonItem),
depends: std.ArrayList(DependItem),
options: *std.Build.Step.Options,
) void {
for (anon_imports.items) |an| {
m.addImport(an.name, an.module);
}
for (depends.items) |depend| {
m.addImport(depend.name, depend.dep.module(depend.module));
}
m.addOptions("config", options);
}