Skip to content

Commit 4cc6dfc

Browse files
committed
fix(build): support zig 0.15+ test and doc generation
- update build script to handle zig 0.15+ changes for addTest and addObject - use conditional logic to set root_module for newer zig versions - maintain compatibility with zig 0.14
1 parent fedd9e6 commit 4cc6dfc

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

build.zig

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,35 @@ pub fn build(b: *std.Build) void {
1717

1818
const test_step = b.step("test", "Run unit tests");
1919

20-
const msgpack_unit_tests = b.addTest(.{
20+
const msgpack_unit_tests = if (builtin.zig_version.minor == 14) b.addTest(.{
2121
.root_source_file = b.path(b.pathJoin(&.{ "src", "test.zig" })),
2222
.target = target,
2323
.optimize = optimize,
24+
}) else b.addTest(.{
25+
.root_module = b.addModule("test", .{
26+
.root_source_file = b.path(b.pathJoin(&.{ "src", "test.zig" })),
27+
.target = target,
28+
.optimize = optimize,
29+
}),
2430
});
2531
msgpack_unit_tests.root_module.addImport("msgpack", msgpack);
2632
const run_msgpack_tests = b.addRunArtifact(msgpack_unit_tests);
2733
test_step.dependOn(&run_msgpack_tests.step);
2834
}
2935

3036
fn generateDocs(b: *Build, optimize: OptimizeMode, target: Build.ResolvedTarget) void {
31-
const lib = b.addObject(.{
37+
const lib = if (builtin.zig_version.minor == 14) b.addObject(.{
3238
.name = "zig-msgpack",
3339
.root_source_file = b.path(b.pathJoin(&.{ "src", "msgpack.zig" })),
3440
.target = target,
3541
.optimize = optimize,
42+
}) else b.addObject(.{
43+
.name = "zig-msgpack",
44+
.root_module = b.addModule("msgpack", .{
45+
.root_source_file = b.path(b.pathJoin(&.{ "src", "msgpack.zig" })),
46+
.target = target,
47+
.optimize = optimize,
48+
}),
3649
});
3750

3851
const docs_step = b.step("docs", "Emit docs");

0 commit comments

Comments
 (0)