-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
190 lines (170 loc) · 7.47 KB
/
Copy pathbuild.zig
File metadata and controls
190 lines (170 loc) · 7.47 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const pow_from_right = b.option(bool, "pow-from-right", "TE_POW_FROM_RIGHT: right-assoc exponentiation") orelse false;
const nat_log = b.option(bool, "nat-log", "TE_NAT_LOG: log binds to natural log") orelse false;
const fix_fac_overflow = b.option(bool, "fix-fac-overflow", "Stricter fac/ncr overflow handling") orelse false;
const max_nesting = b.option(u32, "max-nesting", "Parse nesting depth limit") orelse 2048;
const opts = b.addOptions();
opts.addOption(bool, "pow_from_right", pow_from_right);
opts.addOption(bool, "nat_log", nat_log);
opts.addOption(bool, "fix_fac_overflow", fix_fac_overflow);
opts.addOption(u32, "max_nesting", max_nesting);
const root_mod = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
root_mod.addOptions("config", opts);
// Package module for `zig fetch` / build.zig consumers (native API).
const pkg_mod = b.addModule("tinyexpr", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
pkg_mod.addOptions("config", opts);
const static_lib = b.addLibrary(.{
.name = "tinyexpr",
.linkage = .static,
.root_module = root_mod,
});
b.installArtifact(static_lib);
const is_wasm = target.result.cpu.arch.isWasm();
if (!is_wasm) {
const shared_mod = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
shared_mod.addOptions("config", opts);
const shared_lib = b.addLibrary(.{
.name = "tinyexpr",
.linkage = .dynamic,
.root_module = shared_mod,
});
b.installArtifact(shared_lib);
}
const tests = b.addTest(.{
.root_module = root_mod,
});
const run_tests = b.addRunArtifact(tests);
const test_step = b.step("test", "Run Zig unit tests (current -D flags)");
test_step.dependOn(&run_tests.step);
inline for (.{
.{ false, false, "default" },
.{ true, false, "pow" },
.{ false, true, "natlog" },
.{ true, true, "pow_natlog" },
}) |combo| {
const pr = combo[0];
const nl = combo[1];
const name = combo[2];
const o = b.addOptions();
o.addOption(bool, "pow_from_right", pr);
o.addOption(bool, "nat_log", nl);
o.addOption(bool, "fix_fac_overflow", fix_fac_overflow);
o.addOption(u32, "max_nesting", max_nesting);
const mod = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
mod.addOptions("config", o);
const t = b.addTest(.{
.name = "test-" ++ name,
.root_module = mod,
});
const run = b.addRunArtifact(t);
test_step.dependOn(&run.step);
}
const port_tests_mod = b.createModule(.{
.root_source_file = b.path("tests/port/root.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
port_tests_mod.addOptions("config", opts);
const support_mod = b.createModule(.{
.root_source_file = b.path("tests/port/support.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
support_mod.addImport("tinyexpr", root_mod);
port_tests_mod.addImport("tinyexpr", root_mod);
port_tests_mod.addImport("support", support_mod);
const port_tests = b.addTest(.{
.name = "port-tests",
.root_module = port_tests_mod,
});
const run_port = b.addRunArtifact(port_tests);
test_step.dependOn(&run_port.step);
const fmt = b.addFmt(.{
.paths = &.{ "src", "tests", "build.zig" },
.check = true,
});
const fmt_step = b.step("fmt-check", "Fail if zig fmt would change files");
fmt_step.dependOn(&fmt.step);
// Shell-driven steps (portable entry points for local verify / CI)
const original = b.addSystemCommand(&.{ "bash", "scripts/run-original-suite.sh", "default" });
original.setCwd(b.path("."));
const original_step = b.step("original-tests", "Link smoke.c against Zig ABI (default config; see scripts for all four)");
original_step.dependOn(&original.step);
const verify_cmd = b.addSystemCommand(&.{ "bash", "scripts/verify.sh" });
verify_cmd.setCwd(b.path("."));
const verify_step = b.step("verify", "Full verification scorecard");
verify_step.dependOn(&verify_cmd.step);
const cross_cmd = b.addSystemCommand(&.{ "bash", "scripts/cross-compile.sh" });
cross_cmd.setCwd(b.path("."));
const cross_step = b.step("cross", "Cross-compile matrix");
cross_step.dependOn(&cross_cmd.step);
const fuzz_cmd = b.addSystemCommand(&.{ "bash", "scripts/run-fuzz.sh", "5", "fuzz/logs/fuzz-verify.txt", "verify" });
fuzz_cmd.setCwd(b.path("."));
const fuzz_step = b.step("fuzz", "Short differential fuzz tier");
fuzz_step.dependOn(&fuzz_cmd.step);
const cover_cmd = b.addSystemCommand(&.{ "bash", "scripts/run-coverage-c.sh" });
cover_cmd.setCwd(b.path("."));
const cover_step = b.step("cover", "lcov coverage of original C + evidence fragment");
cover_step.dependOn(&cover_cmd.step);
const bench_cmd = b.addSystemCommand(&.{ "bash", "bench/run.sh" });
bench_cmd.setCwd(b.path("."));
const bench_step = b.step("bench", "Run C vs Zig latency/RSS/startup benches");
bench_step.dependOn(&bench_cmd.step);
const enumerate_cmd = b.addSystemCommand(&.{ "bash", "scripts/run-enumerate.sh" });
enumerate_cmd.setCwd(b.path("."));
const enumerate_step = b.step("enumerate", "Exhaustive C vs Zig differential enumeration");
enumerate_step.dependOn(&enumerate_cmd.step);
const enumerate_quick_cmd = b.addSystemCommand(&.{ "bash", "scripts/run-enumerate.sh", "--quick" });
enumerate_quick_cmd.setCwd(b.path("."));
const enumerate_quick_step = b.step("enumerate-quick", "Short differential-enumeration tier");
enumerate_quick_step.dependOn(&enumerate_quick_cmd.step);
const alloc_cmd = b.addSystemCommand(&.{ "bash", "tools/allocfault/run.sh" });
alloc_cmd.setCwd(b.path("."));
const alloc_step = b.step("alloc-fault", "Malloc ordinal failure injection");
alloc_step.dependOn(&alloc_cmd.step);
// Wire anatomy fuzz/harness.zig as a ReleaseSafe test module.
const harness_mod = b.createModule(.{
.root_source_file = b.path("fuzz/harness.zig"),
.target = target,
.optimize = .ReleaseSafe,
.link_libc = true,
});
harness_mod.addImport("tinyexpr", root_mod);
const harness_tests = b.addTest(.{
.name = "fuzz-harness",
.root_module = harness_mod,
});
const run_harness_tests = b.addRunArtifact(harness_tests);
fuzz_step.dependOn(&run_harness_tests.step);
// Also attach to the default test step so `zig build test --fuzz` sees Smith cases.
test_step.dependOn(&run_harness_tests.step);
const demo_cmd = b.addSystemCommand(&.{ "bash", "docs/demo/regen-svgs.sh" });
demo_cmd.setCwd(b.path("."));
const demo_step = b.step("demo", "Regenerate docs/demo/*.svg from segment transcripts");
demo_step.dependOn(&demo_cmd.step);
}