-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild.zig
More file actions
245 lines (204 loc) · 7.83 KB
/
build.zig
File metadata and controls
245 lines (204 loc) · 7.83 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
const std = @import("std");
const builtin = @import("builtin");
const Builder = if (builtin.zig_version.minor <= 10) std.build.Builder else std.Build;
const Mode = if (builtin.zig_version.minor <= 10) std.builtin.Mode else std.builtin.OptimizeMode;
const Target = std.Target;
const CrossTarget = std.zig.CrossTarget;
const Arch = Target.Cpu.Arch;
const Os = Target.Os.Tag;
pub fn build(b: *Builder) void {
if (comptime builtin.zig_version.minor <= 10) {
build_v10(b);
} else if (comptime builtin.zig_version.minor <= 11) {
build_v11(b);
} else if (comptime builtin.zig_version.minor < 15) {
build_v12(b);
} else {
build_v15(b);
}
}
fn build_v10(b: *std.build.Builder) void {
// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();
const coverage = b.option(bool, "coverage", "Generate test coverage") orelse false;
// Docs
const docs = b.addStaticLibrary("zig-rc", "src/root.zig");
docs.emit_docs = .emit;
docs.setBuildMode(mode);
docs.install();
// Tests
const main_tests = b.addTest("src/tests.zig");
main_tests.setBuildMode(mode);
if (coverage) {
main_tests.setExecCmd(&[_]?[]const u8{
"kcov",
"--include-pattern=src/root.zig,src/tests.zig",
"kcov-out",
null, // to get zig to use the --test-cmd-bin flag
});
}
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&main_tests.step);
// Examples
const example = b.addTest("src/example.zig");
example.setBuildMode(mode);
const example_step = b.step("example", "Run library example");
example_step.dependOn(&example.step);
}
fn build_v11(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(.{});
const coverage = b.option(bool, "coverage", "Generate test coverage") orelse false;
// Docs
const docs = b.addStaticLibrary(.{
.name = "zig-rc",
.root_source_file = std.build.LazyPath.relative("src/root.zig"),
.target = target,
.optimize = optimize,
});
const docsget = b.addInstallDirectory(.{
.source_dir = docs.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});
b.default_step.dependOn(&docsget.step);
b.installArtifact(docs);
// Tests
const main_tests = b.addTest(.{
.root_source_file = std.build.LazyPath.relative("src/tests.zig"),
});
const run_main_tests = b.addRunArtifact(main_tests);
if (coverage) {
main_tests.setExecCmd(&[_]?[]const u8{
"kcov",
"--include-pattern=src/root.zig,src/tests.zig",
"kcov-out",
null, // to get zig to use the --test-cmd-bin flag
});
}
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&run_main_tests.step);
// Examples
const example = b.addTest(.{
.root_source_file = std.build.LazyPath.relative("src/example.zig"),
});
const run_example = b.addRunArtifact(example);
const example_step = b.step("example", "Run library example");
example_step.dependOn(&run_example.step);
}
fn build_v12(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(.{});
const coverage = b.option(bool, "coverage", "Generate test coverage") orelse false;
// Docs
const docs = b.addStaticLibrary(.{
.name = "zig-rc",
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
const docsget = b.addInstallDirectory(.{
.source_dir = docs.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});
b.default_step.dependOn(&docsget.step);
b.installArtifact(docs);
// Tests
const main_tests = b.addTest(.{
.root_source_file = b.path("src/tests.zig"),
});
const run_main_tests = b.addRunArtifact(main_tests);
if (coverage) {
main_tests.setExecCmd(&[_]?[]const u8{
"kcov",
"--include-pattern=src/root.zig,src/tests.zig",
"kcov-out",
null, // to get zig to use the --test-cmd-bin flag
});
}
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&run_main_tests.step);
// Examples
const example = b.addTest(.{
.root_source_file = b.path("src/example.zig"),
});
const run_example = b.addRunArtifact(example);
const example_step = b.step("example", "Run library example");
example_step.dependOn(&run_example.step);
}
fn build_v15(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const coverage = b.option(bool, "coverage", "Generate test coverage") orelse false;
// Docs
const docs = b.addObject(.{
.name = "zigrc",
.root_module = b.addModule("zigrc", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
}),
});
const docsget = b.addInstallDirectory(.{
.source_dir = docs.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});
b.default_step.dependOn(&docsget.step);
// b.installArtifact(docs);
// Tests
const main_tests = b.addTest(.{
.root_module = b.addModule("zigrc-tests", .{
.root_source_file = b.path("src/tests.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_main_tests = b.addRunArtifact(main_tests);
if (coverage) {
main_tests.setExecCmd(&[_]?[]const u8{
"kcov",
"--include-pattern=src/root.zig,src/tests.zig",
"kcov-out",
null, // to get zig to use the --test-cmd-bin flag
});
}
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&run_main_tests.step);
// Examples
const example = b.addTest(.{
.root_module = b.addModule("zigrc-example", .{
.root_source_file = b.path("src/example.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_example = b.addRunArtifact(example);
const example_step = b.step("example", "Run library example");
example_step.dependOn(&run_example.step);
}
fn default_target(arch: Target.Cpu.Arch, os_tag: Target.Os.Tag) Target {
const os = os_tag.defaultVersionRange(arch);
return Target{
.cpu = Target.Cpu.baseline(arch),
.abi = Target.Abi.default(arch, os),
.os = os,
.ofmt = Target.ObjectFormat.default(os_tag, arch),
};
}