-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
182 lines (164 loc) · 6.54 KB
/
build.zig
File metadata and controls
182 lines (164 loc) · 6.54 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
const std = @import("std");
inline fn fileExists(path: []const u8) bool {
// statFile() succeeds (returns a Stat) or throws; we map that to bool.
_ = std.fs.cwd().statFile(path) catch return false;
return true;
}
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// ------------------------------------------------------------------------
// Public module: expose src/root.zig as "ZCoreMath"
// ------------------------------------------------------------------------
const zcore_module = b.addModule("ZCoreMath", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
// ------------------------------------------------------------------------
// Tests (unit + integration + e2e)
// ------------------------------------------------------------------------
const step_test = b.step("test", "Run unit + e2e + integration tests");
const step_test_all = b.step("test-all", "Alias for test");
step_test_all.dependOn(step_test);
// Root inline tests across src/*
{
const root_tests = b.addTest(.{ .root_module = zcore_module });
const run_root = b.addRunArtifact(root_tests);
step_test.dependOn(&run_root.step);
}
// Dedicated per-file unit tests for modules that contain inline tests
const unit_step = b.step("test-unit", "Run inline unit tests from module files");
// cast.zig
if (fileExists("src/lib/cast.zig")) {
const m = b.createModule(.{
.root_source_file = b.path("src/lib/cast.zig"),
.target = target,
.optimize = optimize,
});
const t = b.addTest(.{ .root_module = m });
const r = b.addRunArtifact(t);
unit_step.dependOn(&r.step);
}
// util.zig
if (fileExists("src/lib/util.zig")) {
const m = b.createModule(.{
.root_source_file = b.path("src/lib/util.zig"),
.target = target,
.optimize = optimize,
});
const t = b.addTest(.{ .root_module = m });
const r = b.addRunArtifact(t);
unit_step.dependOn(&r.step);
}
// fmt/format.zig
if (fileExists("src/fmt/format.zig")) {
const m = b.createModule(.{
.root_source_file = b.path("src/fmt/format.zig"),
.target = target,
.optimize = optimize,
});
const t = b.addTest(.{ .root_module = m });
const r = b.addRunArtifact(t);
unit_step.dependOn(&r.step);
}
// Aggregate unit tests into main test step
step_test.dependOn(unit_step);
// e2e
if (fileExists("tests/e2e/stability.zig")) {
const e2e_mod = b.createModule(.{
.root_source_file = b.path("tests/e2e/stability.zig"),
.target = target,
.optimize = optimize,
});
e2e_mod.addImport("ZCoreMath", zcore_module);
const e2e = b.addTest(.{ .root_module = e2e_mod });
const e2e_run = b.addRunArtifact(e2e);
step_test.dependOn(&e2e_run.step);
}
// integration
if (fileExists("tests/integration/consumers.zig")) {
const integ_mod = b.createModule(.{
.root_source_file = b.path("tests/integration/consumers.zig"),
.target = target,
.optimize = optimize,
});
integ_mod.addImport("ZCoreMath", zcore_module);
const integ = b.addTest(.{ .root_module = integ_mod });
const integ_run = b.addRunArtifact(integ);
step_test.dependOn(&integ_run.step);
}
// ------------------------------------------------------------------------
// Examples — set .target / .optimize on the module itself (0.16-dev)
// ------------------------------------------------------------------------
const step_examples = b.step("examples", "Build examples/* executables");
if (fileExists("examples/constants.zig")) {
const exe = b.addExecutable(.{
.name = "constants",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/constants.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "ZCoreMath", .module = zcore_module },
},
}),
});
const inst = b.addInstallArtifact(exe, .{});
step_examples.dependOn(&inst.step);
}
if (fileExists("examples/cast_demo.zig")) {
const exe = b.addExecutable(.{
.name = "cast_demo",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/cast_demo.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "ZCoreMath", .module = zcore_module },
},
}),
});
const inst = b.addInstallArtifact(exe, .{});
step_examples.dependOn(&inst.step);
}
if (fileExists("examples/ulp_demo.zig")) {
const exe = b.addExecutable(.{
.name = "ulp_demo",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/ulp_demo.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "ZCoreMath", .module = zcore_module },
},
}),
});
const inst = b.addInstallArtifact(exe, .{});
step_examples.dependOn(&inst.step);
}
// ------------------------------------------------------------------------
// Optional wasm demo — resolve the WASM target first
// ------------------------------------------------------------------------
const step_wasm = b.step("wasm", "Build wasm32-freestanding demo (exports.zig) if present");
if (fileExists("src/exports.zig")) {
const wasm_target = b.resolveTargetQuery(.{
.cpu_arch = .wasm32,
.os_tag = .freestanding,
.abi = .none,
});
const wasm_exe = b.addExecutable(.{
.name = "zcoremath_wasm",
.root_module = b.createModule(.{
.root_source_file = b.path("src/exports.zig"),
.target = wasm_target,
.optimize = .ReleaseSmall,
.imports = &.{
.{ .name = "ZCoreMath", .module = zcore_module },
},
}),
});
const wasm_inst = b.addInstallArtifact(wasm_exe, .{});
step_wasm.dependOn(&wasm_inst.step);
}
}