-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.zig
More file actions
195 lines (164 loc) · 7.06 KB
/
build.zig
File metadata and controls
195 lines (164 loc) · 7.06 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
const std = @import("std");
/// Build configuration for httpx.zig - Production-ready HTTP library for Zig
/// Supports HTTP/1.1, HTTP/2, HTTP/3 with TLS, connection pooling, and more.
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const httpx_module = b.createModule(.{
.root_source_file = b.path("src/httpx.zig"),
});
_ = b.addModule("httpx", .{
.root_source_file = b.path("src/httpx.zig"),
});
const examples = [_]struct { name: []const u8, path: []const u8, skip_run_all: bool = false }{
.{ .name = "simple_get", .path = "examples/simple_get.zig" },
.{ .name = "post_json", .path = "examples/post_json.zig" },
.{ .name = "concurrent_requests", .path = "examples/concurrent_requests.zig" },
.{ .name = "custom_headers", .path = "examples/custom_headers.zig" },
.{ .name = "udp_local", .path = "examples/udp_local.zig" },
.{ .name = "simple_server", .path = "examples/simple_server.zig", .skip_run_all = true },
.{ .name = "router_example", .path = "examples/router_example.zig", .skip_run_all = true },
.{ .name = "middleware_example", .path = "examples/middleware_example.zig", .skip_run_all = true },
.{ .name = "streaming", .path = "examples/streaming.zig" },
.{ .name = "interceptors", .path = "examples/interceptors.zig" },
.{ .name = "connection_pool", .path = "examples/connection_pool.zig" },
.{ .name = "static_files", .path = "examples/static_files.zig", .skip_run_all = true },
.{ .name = "http2_example", .path = "examples/http2_example.zig" },
.{ .name = "http3_example", .path = "examples/http3_example.zig" },
};
inline for (examples) |example| {
const exe = b.addExecutable(.{
.name = example.name,
.root_module = b.createModule(.{
.root_source_file = b.path(example.path),
.target = target,
.optimize = optimize,
}),
});
exe.root_module.addImport("httpx", httpx_module);
if (target.result.os.tag == .windows) {
exe.linkSystemLibrary("ws2_32");
exe.linkSystemLibrary("mswsock");
}
const install_exe = b.addInstallArtifact(exe, .{});
const example_step = b.step("example-" ++ example.name, "Build " ++ example.name ++ " example");
example_step.dependOn(&install_exe.step);
const run_exe = b.addRunArtifact(exe);
run_exe.step.dependOn(&install_exe.step);
const run_step = b.step("run-" ++ example.name, "Run " ++ example.name ++ " example");
run_step.dependOn(&run_exe.step);
}
const run_all_examples = b.step("run-all-examples", "Run all examples sequentially");
var previous_run_step: ?*std.Build.Step = null;
inline for (examples) |example| {
if (example.skip_run_all) continue;
const exe = b.addExecutable(.{
.name = "run-all-" ++ example.name,
.root_module = b.createModule(.{
.root_source_file = b.path(example.path),
.target = target,
.optimize = optimize,
}),
});
exe.root_module.addImport("httpx", httpx_module);
if (target.result.os.tag == .windows) {
exe.linkSystemLibrary("ws2_32");
exe.linkSystemLibrary("mswsock");
}
const install_exe = b.addInstallArtifact(exe, .{});
const run_exe = b.addRunArtifact(exe);
run_exe.step.dependOn(&install_exe.step);
if (previous_run_step) |prev| {
run_exe.step.dependOn(prev);
}
previous_run_step = &run_exe.step;
}
if (previous_run_step) |last| {
run_all_examples.dependOn(last);
}
const tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/httpx.zig"),
.target = target,
.optimize = optimize,
}),
});
if (target.result.os.tag == .windows) {
tests.linkSystemLibrary("ws2_32");
tests.linkSystemLibrary("mswsock");
}
const run_tests = b.addRunArtifact(tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_tests.step);
const test_all_step = b.step("test-all", "Run all module tests (alias for test)");
test_all_step.dependOn(&run_tests.step);
const bench_exe = b.addExecutable(.{
.name = "benchmark",
.root_module = b.createModule(.{
.root_source_file = b.path("bench/main.zig"),
.target = target,
.optimize = .ReleaseFast,
}),
});
bench_exe.root_module.addImport("httpx", httpx_module);
if (target.result.os.tag == .windows) {
bench_exe.linkSystemLibrary("ws2_32");
bench_exe.linkSystemLibrary("mswsock");
}
const install_bench = b.addInstallArtifact(bench_exe, .{});
const run_bench = b.addRunArtifact(bench_exe);
run_bench.step.dependOn(&install_bench.step);
const bench_step = b.step("bench", "Run benchmarks");
bench_step.dependOn(&run_bench.step);
// Cross-compilation targets to verify support
const cross_targets = [_]std.Target.Query{
.{ .cpu_arch = .x86_64, .os_tag = .linux },
.{ .cpu_arch = .aarch64, .os_tag = .linux },
.{ .cpu_arch = .x86, .os_tag = .linux },
.{ .cpu_arch = .x86_64, .os_tag = .windows },
.{ .cpu_arch = .aarch64, .os_tag = .windows },
.{ .cpu_arch = .x86, .os_tag = .windows },
.{ .cpu_arch = .x86_64, .os_tag = .macos },
.{ .cpu_arch = .aarch64, .os_tag = .macos },
};
const build_all_step = b.step("build-all-targets", "Build library for all supported targets");
for (cross_targets) |t| {
const target_cross = b.resolveTargetQuery(t);
const lib_cross = b.addLibrary(.{
.name = "httpx",
.linkage = .static,
.root_module = b.createModule(.{
.root_source_file = b.path("src/httpx.zig"),
.target = target_cross,
.optimize = optimize,
}),
});
if (t.os_tag == .windows) {
lib_cross.linkSystemLibrary("ws2_32");
lib_cross.linkSystemLibrary("mswsock");
}
// Just build the artifact to verify it compiles
build_all_step.dependOn(&lib_cross.step);
}
const lib = b.addLibrary(.{
.name = "httpx",
.linkage = .static,
.root_module = b.createModule(.{
.root_source_file = b.path("src/httpx.zig"),
.target = target,
.optimize = optimize,
}),
});
if (target.result.os.tag == .windows) {
lib.linkSystemLibrary("ws2_32");
lib.linkSystemLibrary("mswsock");
}
b.installArtifact(lib);
const docs_step = b.step("docs", "Generate library documentation");
const install_docs = b.addInstallDirectory(.{
.source_dir = lib.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});
docs_step.dependOn(&install_docs.step);
}