-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
298 lines (272 loc) · 12.2 KB
/
build.zig
File metadata and controls
298 lines (272 loc) · 12.2 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
const std = @import("std");
fn eql(a: []const u8, b: []const u8) bool {
return std.mem.eql(u8, a, b);
}
fn makeNoOp(step: *std.Build.Step, options: std.Build.Step.MakeOptions) anyerror!void {
_ = step;
_ = options;
}
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const example_choice = b.option([]const u8, "example", "Select one example: echo-server, frame-echo-server, client");
const interop_choice = b.option([]const u8, "interop", "Select one interop target: run, client, repeated-offer-client");
const mod = b.addModule("zws", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
const support_common = b.createModule(.{
.root_source_file = b.path("support/common.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zws", .module = mod },
},
});
const mod_tests = b.addTest(.{
.root_module = mod,
.test_runner = .{ .path = b.path("test_runner.zig"), .mode = .simple },
});
mod_tests.root_module.link_libc = true;
const run_mod_tests = b.addRunArtifact(mod_tests);
if (b.args) |args| run_mod_tests.addArgs(args);
const support_tests = b.addTest(.{
.root_module = support_common,
.test_runner = .{ .path = b.path("test_runner.zig"), .mode = .simple },
});
support_tests.root_module.link_libc = true;
const run_support_tests = b.addRunArtifact(support_tests);
if (b.args) |args| run_support_tests.addArgs(args);
const test_flake_exe = b.addExecutable(.{
.name = "zws-test-flake",
.root_module = b.createModule(.{
.root_source_file = b.path("benchmark/run_test_flake.zig"),
.target = target,
.optimize = optimize,
}),
});
const test_flake_run = b.addRunArtifact(test_flake_exe);
test_flake_run.addPrefixedArtifactArg("--test-bin=", mod_tests);
if (b.args) |args| test_flake_run.addArgs(args);
const bench_exe = b.addExecutable(.{
.name = "zws-bench",
.root_module = b.createModule(.{
.root_source_file = b.path("benchmark/bench.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zws", .module = mod },
.{ .name = "zws_support_common", .module = support_common },
},
}),
});
const install_bench = b.addInstallArtifact(bench_exe, .{});
const bench_runner_exe = b.addExecutable(.{
.name = "zws-bench-runner",
.root_module = b.createModule(.{
.root_source_file = b.path("benchmark/run_bench.zig"),
.target = target,
.optimize = optimize,
}),
});
const bench_server_exe = b.addExecutable(.{
.name = "zws-bench-server",
.root_module = b.createModule(.{
.root_source_file = b.path("benchmark/zws_server.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zws", .module = mod },
.{ .name = "zws_support_common", .module = support_common },
},
}),
});
const install_bench_server = b.addInstallArtifact(bench_server_exe, .{});
const compare_exe = b.addExecutable(.{
.name = "zws-bench-compare",
.root_module = b.createModule(.{
.root_source_file = b.path("benchmark/run_ab.zig"),
.target = target,
.optimize = optimize,
}),
});
const install_compare = b.addInstallArtifact(compare_exe, .{});
const echo_server_exe = b.addExecutable(.{
.name = "zws-echo-server",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/echo_server.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zws", .module = mod },
.{ .name = "zws_support_common", .module = support_common },
},
}),
});
const install_echo_server = b.addInstallArtifact(echo_server_exe, .{});
const frame_echo_server_exe = b.addExecutable(.{
.name = "zws-frame-echo-server",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/frame_echo_server.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zws", .module = mod },
.{ .name = "zws_support_common", .module = support_common },
},
}),
});
const install_frame_echo_server = b.addInstallArtifact(frame_echo_server_exe, .{});
const client_exe = b.addExecutable(.{
.name = "zws-client",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/ws_client.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zws", .module = mod },
.{ .name = "zws_support_common", .module = support_common },
},
}),
});
const install_client = b.addInstallArtifact(client_exe, .{});
const interop_client_exe = b.addExecutable(.{
.name = "zws-interop-client",
.root_module = b.createModule(.{
.root_source_file = b.path("validation/zws_client.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zws", .module = mod },
.{ .name = "zws_support_common", .module = support_common },
},
}),
});
const install_interop_client = b.addInstallArtifact(interop_client_exe, .{});
const repeated_offer_client_exe = b.addExecutable(.{
.name = "zws-repeated-pmd-offer-client",
.root_module = b.createModule(.{
.root_source_file = b.path("validation/repeated_pmd_offer_client.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zws", .module = mod },
.{ .name = "zws_support_common", .module = support_common },
},
}),
});
const install_repeated_offer_client = b.addInstallArtifact(repeated_offer_client_exe, .{});
const interop_runner_exe = b.addExecutable(.{
.name = "zws-interop-runner",
.root_module = b.createModule(.{
.root_source_file = b.path("validation/run_interop.zig"),
.target = target,
.optimize = optimize,
}),
});
const soak_runner_exe = b.addExecutable(.{
.name = "zws-soak-runner",
.root_module = b.createModule(.{
.root_source_file = b.path("validation/soak.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zws", .module = mod },
.{ .name = "zws_support_common", .module = support_common },
},
}),
});
const install_step = b.getInstallStep();
install_step.dependOn(&install_bench.step);
install_step.dependOn(&install_bench_server.step);
install_step.dependOn(&install_compare.step);
install_step.dependOn(&install_echo_server.step);
install_step.dependOn(&install_frame_echo_server.step);
install_step.dependOn(&install_client.step);
install_step.dependOn(&install_interop_client.step);
install_step.dependOn(&install_repeated_offer_client.step);
b.getUninstallStep().makeFn = makeNoOp;
const test_step = b.step("test", "Run zws tests");
test_step.dependOn(&run_mod_tests.step);
test_step.dependOn(&run_support_tests.step);
const test_flake_step = b.step("test-flake", "Hunt flaky tests deterministically with seeded runs");
test_flake_step.dependOn(&test_flake_run.step);
const bench_run = b.addRunArtifact(bench_runner_exe);
bench_run.step.dependOn(&install_bench.step);
bench_run.step.dependOn(&install_bench_server.step);
if (b.args) |args| bench_run.addArgs(args);
const bench_step = b.step("bench", "Run the websocket benchmark client");
bench_step.dependOn(&bench_run.step);
const compare_run = b.addRunArtifact(compare_exe);
compare_run.step.dependOn(&install_bench.step);
compare_run.step.dependOn(&install_bench_server.step);
compare_run.step.dependOn(&install_compare.step);
if (b.args) |args| compare_run.addArgs(args);
const compare_step = b.step("bench-compare", "Run interleaved zws vs uWebSockets benchmark rounds");
compare_step.dependOn(&compare_run.step);
const examples_step = b.step("examples", "Build zws examples; use -Dexample=echo-server|frame-echo-server|client to select one");
const examples_check_step = b.step("examples-check", "Run all zws examples with --help");
const echo_server_help = b.addRunArtifact(echo_server_exe);
echo_server_help.addArg("--help");
const frame_echo_server_help = b.addRunArtifact(frame_echo_server_exe);
frame_echo_server_help.addArg("--help");
const client_help = b.addRunArtifact(client_exe);
client_help.addArg("--help");
examples_check_step.dependOn(&echo_server_help.step);
examples_check_step.dependOn(&frame_echo_server_help.step);
examples_check_step.dependOn(&client_help.step);
if (example_choice) |choice| {
if (eql(choice, "echo-server")) {
examples_step.dependOn(&install_echo_server.step);
} else if (eql(choice, "frame-echo-server")) {
examples_step.dependOn(&install_frame_echo_server.step);
} else if (eql(choice, "client")) {
examples_step.dependOn(&install_client.step);
} else {
@panic("invalid -Dexample value; expected echo-server, frame-echo-server, or client");
}
} else {
examples_step.dependOn(&install_echo_server.step);
examples_step.dependOn(&install_frame_echo_server.step);
examples_step.dependOn(&install_client.step);
}
const interop_run = b.addRunArtifact(interop_runner_exe);
interop_run.step.dependOn(&install_echo_server.step);
interop_run.step.dependOn(&install_interop_client.step);
interop_run.step.dependOn(&install_repeated_offer_client.step);
interop_run.addArg(b.fmt("--server-bin={s}", .{b.getInstallPath(.bin, "zws-echo-server")}));
interop_run.addArg(b.fmt("--client-bin={s}", .{b.getInstallPath(.bin, "zws-interop-client")}));
interop_run.addArg(b.fmt("--repeated-client-bin={s}", .{b.getInstallPath(.bin, "zws-repeated-pmd-offer-client")}));
const interop_step = b.step("interop", "Run interop or build an interop helper with -Dinterop=run|client|repeated-offer-client");
if (interop_choice) |choice| {
if (eql(choice, "run")) {
interop_step.dependOn(&interop_run.step);
} else if (eql(choice, "client")) {
interop_step.dependOn(&install_interop_client.step);
} else if (eql(choice, "repeated-offer-client")) {
interop_step.dependOn(&install_repeated_offer_client.step);
} else {
@panic("invalid -Dinterop value; expected run, client, or repeated-offer-client");
}
} else {
interop_step.dependOn(&interop_run.step);
}
const soak_run = b.addRunArtifact(soak_runner_exe);
soak_run.step.dependOn(&install_echo_server.step);
soak_run.addArg(b.fmt("--server-bin={s}", .{b.getInstallPath(.bin, "zws-echo-server")}));
const soak_compressed = b.addRunArtifact(soak_runner_exe);
soak_compressed.step.dependOn(&install_echo_server.step);
soak_compressed.addArg(b.fmt("--server-bin={s}", .{b.getInstallPath(.bin, "zws-echo-server")}));
soak_compressed.addArg("--compression");
const soak_step = b.step("soak", "Run websocket soak tests against the example server");
soak_step.dependOn(&soak_run.step);
soak_step.dependOn(&soak_compressed.step);
const validate_step = b.step("validate", "Run tests, interop, and soak validation");
validate_step.dependOn(&run_mod_tests.step);
validate_step.dependOn(&run_support_tests.step);
validate_step.dependOn(examples_step);
validate_step.dependOn(&interop_run.step);
validate_step.dependOn(&soak_run.step);
validate_step.dependOn(&soak_compressed.step);
}