-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
190 lines (164 loc) · 6.44 KB
/
build.zig
File metadata and controls
190 lines (164 loc) · 6.44 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
const std = @import("std");
const Backend = @import("rio").Backend;
const Tool = struct {
fn addModules(b: *std.Build, mod: *std.Build.Module, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) void {
mod.addImport("typetool", b.dependency("typetool", .{
.target = target,
.optimize = optimize,
}).module("typetool"));
mod.addImport("parkinglot", b.dependency("parkinglot", .{
.target = target,
.optimize = optimize,
}).module("parkinglot"));
mod.addImport("xev", b.dependency("xev", .{
.target = target,
.optimize = optimize,
}).module("xev"));
}
};
// 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(.{});
const backend = b.option(
Backend,
"backend",
"IO backend (default: IoUring)",
) orelse .IoUring;
const testFilters = b.option(
[]const []const u8,
"test-filter",
"Skip tests that do not match any filter",
) orelse &[0][]const u8{};
const examples = b.step("examples", "Build examples");
const checkStep = b.step("check", "Compile but won't install files");
const test_step = b.step("test", "Run unit tests");
const behaviourTests = b.step("test-behaviour", "Run behaviour tests");
const rio = rioMod: {
const dep = b.dependency("rio", .{
.optimize = optimize,
.target = target,
.backend = backend,
// TODO: zig build user option does not support optional values
// Here: https://github.com/ziglang/zig/blob/03457755590c73893bce21f551d5664333baf267/lib/std/Build.zig#L412
});
break :rioMod dep.module("rio");
};
b.modules.put("rio", rio) catch @panic("OOM");
{
const mod = b.addModule("haiya", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
Tool.addModules(b, mod, target, optimize);
mod.addImport("rio", rio);
const checkBuild = b.addStaticLibrary(.{
.optimize = optimize,
.target = target,
.name = "haiya",
.root_source_file = b.path("src/root.zig"),
});
Tool.addModules(b, &checkBuild.root_module, target, optimize);
checkBuild.root_module.addImport("rio", rio);
checkStep.dependOn(&checkBuild.step);
const docBuild = b.addStaticLibrary(.{
.optimize = optimize,
.target = target,
.name = "haiya",
.root_source_file = b.path("src/root.zig"),
});
Tool.addModules(b, &docBuild.root_module, target, optimize);
docBuild.root_module.addImport("rio", rio);
const docsPath = docBuild.getEmittedDocs();
const instDocs = b.addInstallDirectory(
.{
.install_subdir = "docs",
.install_dir = .prefix,
.source_dir = docsPath,
},
);
b.default_step.dependOn(&instDocs.step);
}
{
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const lib_unit_tests = b.addTest(.{
.target = target,
.optimize = optimize,
.root_source_file = b.path("src/root.zig"),
.filters = testFilters,
});
Tool.addModules(b, &lib_unit_tests.root_module, target, optimize);
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
test_step.dependOn(&run_lib_unit_tests.step);
}
{
const helloWorld = b.addExecutable(.{
.target = target,
.optimize = optimize,
.root_source_file = b.path("src/examples/hello.zig"),
.name = "hello",
});
helloWorld.root_module.addImport(
"haiya",
b.modules.get("haiya") orelse @panic("NO MOD"),
);
helloWorld.root_module.addImport(
"rio",
b.modules.get("rio") orelse @panic("NO MOD"),
);
const installHelloWorld = b.addInstallArtifact(
helloWorld,
.{},
);
examples.dependOn(&installHelloWorld.step);
checkStep.dependOn(&helloWorld.step);
}
{
const modHaiya = b.modules.get("haiya") orelse @panic("Module not found");
const modRio = b.modules.get("rio") orelse @panic("Module not found");
inline for (BEHAVIOUR_TEST_FILES) |dfilename| {
const filename = b.path("tests/" ++ dfilename);
const exe = b.addTest(.{
.root_source_file = filename,
.optimize = optimize,
.target = target,
.filters = testFilters,
.error_tracing = true,
.strip = false,
.name = std.mem.replaceOwned(
u8,
b.allocator,
filename.src_path.sub_path[0 .. dfilename.len - 4], // remove the ".zig"
"/",
"_",
) catch @panic("OOM"),
});
exe.root_module.addImport("haiya", modHaiya);
exe.root_module.addImport("rio", modRio);
if (b.lazyDependency("curl", .{})) |curlPkg| {
exe.root_module.addImport("curl", curlPkg.module("curl"));
}
checkStep.dependOn(&exe.step);
const run = b.addRunArtifact(exe);
behaviourTests.dependOn(&run.step);
}
}
}
const BEHAVIOUR_TEST_FILES: []const []const u8 = &.{
"compat/headers.zig",
"compat/request-body.zig",
"compat/cookies.zig",
"compat/h1/keep-alive.zig",
"compat/h1/encodings.zig",
};