-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
132 lines (110 loc) · 4.54 KB
/
build.zig
File metadata and controls
132 lines (110 loc) · 4.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
const std = @import("std");
const version = std.SemanticVersion{ .major = 0, .minor = 3, .patch = 0 };
// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
pub fn build(b: *std.Build) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});
// This is shamelessly taken from the `zbench` library's `build.zig` file. see [here](https://github.com/hendriknielaender/zBench/blob/b69a438f5a1a96d4dd0ea69e1dbcb73a209f76cd/build.zig)
setupLibrary(b, target, optimize);
setupTests(b, target, optimize);
setupBenchmarks(b, target, optimize);
setupExamples(b, target, optimize);
}
fn setupLibrary(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) void {
const lib = b.addLibrary(.{
.name = "stdx",
.root_module = b.createModule(.{
.root_source_file = b.path("src/stdx.zig"),
.target = target,
.optimize = optimize,
}),
.version = version,
});
// Explicitly export the `stdx` module so it can be imported by others
_ = b.addModule("stdx", .{
.root_source_file = b.path("src/stdx.zig"),
.target = target,
.optimize = optimize,
});
b.installArtifact(lib);
}
fn setupTests(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) void {
const lib_unit_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/test.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
}
fn setupExamples(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) void {
const example_step = b.step("examples", "Build examples");
const example_names = [_][]const u8{
"buffered_channel",
"event_emitter",
"managed_queue",
"memory_pool",
"mpmc_bus",
"mpmc_queue",
"ring_buffer",
"signal",
"unbuffered_channel",
"unmanaged_queue",
};
for (example_names) |example_name| {
const example_exe = b.addExecutable(.{
.name = example_name,
.root_module = b.createModule(.{
.root_source_file = b.path(b.fmt("examples/{s}.zig", .{example_name})),
.target = target,
.optimize = optimize,
}),
});
const install_example = b.addInstallArtifact(example_exe, .{});
const stdx_mod = b.addModule("stdx", .{
.root_source_file = b.path("src/stdx.zig"),
.target = target,
.optimize = optimize,
});
example_exe.root_module.addImport("stdx", stdx_mod);
example_step.dependOn(&example_exe.step);
example_step.dependOn(&install_example.step);
}
}
fn setupBenchmarks(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) void {
const bench_lib = b.addTest(.{
.name = "bench",
.root_module = b.createModule(.{
.root_source_file = b.path("benchmarks/bench.zig"),
.target = target,
.optimize = optimize,
}),
});
const stdx_mod = b.addModule("stdx", .{
.root_source_file = b.path("src/stdx.zig"),
.target = target,
.optimize = optimize,
});
const zbench_dep = b.dependency("zbench", .{
.target = target,
.optimize = optimize,
});
const zbench_mod = zbench_dep.module("zbench");
bench_lib.root_module.addImport("stdx", stdx_mod);
bench_lib.root_module.addImport("zbench", zbench_mod);
const run_bench_tests = b.addRunArtifact(bench_lib);
const bench_test_step = b.step("bench", "Run benchmark tests");
bench_test_step.dependOn(&run_bench_tests.step);
}