-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.zig
99 lines (80 loc) · 3 KB
/
build.zig
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
const std = @import("std");
const builtin = @import("builtin");
const min_zig_string = "0.11.0";
const current_zig = builtin.zig_version;
comptime {
const min_zig = std.SemanticVersion.parse(min_zig_string) catch unreachable;
if (current_zig.order(min_zig) == .lt) {
const err_msg = std.fmt.comptimePrint(
"Your Zig version v{} does not meet the minimum build requirement of v{}",
.{ current_zig, min_zig },
);
@compileError(err_msg);
}
}
pub fn build(b: *std.Build) void {
switch (current_zig.minor) {
11 => version_11.build(b),
12, 13, 14 => version_12.build(b),
else => @compileError("unknown version!"),
}
}
const version_11 = struct {
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const msgpack = b.addModule("msgpack", .{
.source_file = .{
.path = "src/msgpack.zig",
},
});
const test_step = b.step("test", "Run unit tests");
const msgpack_unit_tests = b.addTest(.{
.root_source_file = .{
.path = "src/test.zig",
},
.target = target,
.optimize = optimize,
});
msgpack_unit_tests.addModule("msgpack", msgpack);
const run_msgpack_tests = b.addRunArtifact(msgpack_unit_tests);
test_step.dependOn(&run_msgpack_tests.step);
}
};
const version_12 = struct {
const Build = std.Build;
const Module = Build.Module;
const OptimizeMode = std.builtin.OptimizeMode;
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const msgpack = b.addModule("msgpack", .{
.root_source_file = b.path(b.pathJoin(&.{ "src", "msgpack.zig" })),
});
generateDocs(b, optimize, target);
const test_step = b.step("test", "Run unit tests");
const msgpack_unit_tests = b.addTest(.{
.root_source_file = b.path(b.pathJoin(&.{ "src", "test.zig" })),
.target = target,
.optimize = optimize,
});
msgpack_unit_tests.root_module.addImport("msgpack", msgpack);
const run_msgpack_tests = b.addRunArtifact(msgpack_unit_tests);
test_step.dependOn(&run_msgpack_tests.step);
}
fn generateDocs(b: *Build, optimize: OptimizeMode, target: Build.ResolvedTarget) void {
const lib = b.addObject(.{
.name = "zig-msgpack",
.root_source_file = b.path(b.pathJoin(&.{ "src", "msgpack.zig" })),
.target = target,
.optimize = optimize,
});
const docs_step = b.step("docs", "Emit docs");
const docs_install = b.addInstallDirectory(.{
.source_dir = lib.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});
docs_step.dependOn(&docs_install.step);
}
};