-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.zig
More file actions
282 lines (239 loc) · 11.7 KB
/
build.zig
File metadata and controls
282 lines (239 loc) · 11.7 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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// ============================================================================
// Dependencies
// ============================================================================
const libxev_dep = b.dependency("libxev", .{
.target = target,
.optimize = optimize,
});
// ============================================================================
// Library
// ============================================================================
const lib = b.addStaticLibrary(.{
.name = "libxev-http",
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
});
lib.root_module.addImport("xev", libxev_dep.module("xev"));
b.installArtifact(lib);
// ============================================================================
// Examples and Tools
// ============================================================================
// Multi-mode example server (supports basic, secure, and dev modes)
const example_server = b.addExecutable(.{
.name = "example-server",
.root_source_file = b.path("examples/basic_server.zig"),
.target = target,
.optimize = optimize,
});
example_server.root_module.addImport("xev", libxev_dep.module("xev"));
example_server.root_module.addImport("libxev-http", lib.root_module);
b.installArtifact(example_server);
const run_example = b.addRunArtifact(example_server);
run_example.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_example.addArgs(args);
}
const run_example_step = b.step("run-basic", "🚀 Run the multi-mode example server (use --mode=basic|secure|dev)");
run_example_step.dependOn(&run_example.step);
// ============================================================================
// Tests
// ============================================================================
// Main library tests
const lib_unit_tests = b.addTest(.{
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
});
lib_unit_tests.root_module.addImport("xev", libxev_dep.module("xev"));
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
const test_step = b.step("test", "🧪 Run core library unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
// Integration tests
const integration_tests = b.addTest(.{
.root_source_file = b.path("tests/integration_test.zig"),
.target = target,
.optimize = optimize,
});
integration_tests.root_module.addImport("xev", libxev_dep.module("xev"));
integration_tests.root_module.addImport("libxev-http", lib.root_module);
const run_integration_tests = b.addRunArtifact(integration_tests);
const integration_test_step = b.step("test-integration", "🔗 Run integration tests");
integration_test_step.dependOn(&run_integration_tests.step);
// ============================================================================
// Module-specific Tests
// ============================================================================
// HTTP Request module tests
const request_tests = b.addTest(.{
.root_source_file = b.path("src/request.zig"),
.target = target,
.optimize = optimize,
});
request_tests.root_module.addImport("xev", libxev_dep.module("xev"));
// HTTP Response module tests
const response_tests = b.addTest(.{
.root_source_file = b.path("src/response.zig"),
.target = target,
.optimize = optimize,
});
response_tests.root_module.addImport("xev", libxev_dep.module("xev"));
// Context module tests
const context_tests = b.addTest(.{
.root_source_file = b.path("src/context.zig"),
.target = target,
.optimize = optimize,
});
context_tests.root_module.addImport("xev", libxev_dep.module("xev"));
// Router module tests
const router_tests = b.addTest(.{
.root_source_file = b.path("src/router.zig"),
.target = target,
.optimize = optimize,
});
router_tests.root_module.addImport("xev", libxev_dep.module("xev"));
// Buffer module tests
const buffer_tests = b.addTest(.{
.root_source_file = b.path("src/buffer.zig"),
.target = target,
.optimize = optimize,
});
buffer_tests.root_module.addImport("xev", libxev_dep.module("xev"));
// Configuration module tests
const config_tests = b.addTest(.{
.root_source_file = b.path("src/config.zig"),
.target = target,
.optimize = optimize,
});
config_tests.root_module.addImport("xev", libxev_dep.module("xev"));
// Security and timeout protection module tests
const security_tests = b.addTest(.{
.root_source_file = b.path("src/security.zig"),
.target = target,
.optimize = optimize,
});
security_tests.root_module.addImport("xev", libxev_dep.module("xev"));
// URL encoding/decoding module tests
const url_tests = b.addTest(.{
.root_source_file = b.path("src/url.zig"),
.target = target,
.optimize = optimize,
});
url_tests.root_module.addImport("xev", libxev_dep.module("xev"));
// Middleware module tests
const middleware_tests = b.addTest(.{
.root_source_file = b.path("src/middleware.zig"),
.target = target,
.optimize = optimize,
});
middleware_tests.root_module.addImport("xev", libxev_dep.module("xev"));
// ============================================================================
// Test Execution Steps
// ============================================================================
// Module test runners
const run_request_tests = b.addRunArtifact(request_tests);
const run_response_tests = b.addRunArtifact(response_tests);
const run_context_tests = b.addRunArtifact(context_tests);
const run_router_tests = b.addRunArtifact(router_tests);
const run_buffer_tests = b.addRunArtifact(buffer_tests);
const run_config_tests = b.addRunArtifact(config_tests);
const run_security_tests = b.addRunArtifact(security_tests);
const run_url_tests = b.addRunArtifact(url_tests);
const run_middleware_tests = b.addRunArtifact(middleware_tests);
// Individual module test steps
const request_test_step = b.step("test-request", "📨 Run HTTP request module tests");
request_test_step.dependOn(&run_request_tests.step);
const response_test_step = b.step("test-response", "📤 Run HTTP response module tests");
response_test_step.dependOn(&run_response_tests.step);
const context_test_step = b.step("test-context", "🔄 Run context module tests");
context_test_step.dependOn(&run_context_tests.step);
const router_test_step = b.step("test-router", "🛣️ Run router module tests");
router_test_step.dependOn(&run_router_tests.step);
const buffer_test_step = b.step("test-buffer", "📦 Run buffer module tests");
buffer_test_step.dependOn(&run_buffer_tests.step);
const config_test_step = b.step("test-config", "⚙️ Run configuration module tests");
config_test_step.dependOn(&run_config_tests.step);
const security_test_step = b.step("test-security", "🛡️ Run security and timeout protection tests");
security_test_step.dependOn(&run_security_tests.step);
const url_test_step = b.step("test-url", "🔗 Run URL encoding/decoding module tests");
url_test_step.dependOn(&run_url_tests.step);
const middleware_test_step = b.step("test-middleware", "🔧 Run middleware module tests");
middleware_test_step.dependOn(&run_middleware_tests.step);
// ============================================================================
// Comprehensive Test Suites
// ============================================================================
// Complete test suite - runs ALL tests
const test_all_step = b.step("test-all", "🧪 Run ALL tests (unit + integration + modules)");
test_all_step.dependOn(&run_lib_unit_tests.step);
test_all_step.dependOn(&run_integration_tests.step);
test_all_step.dependOn(&run_request_tests.step);
test_all_step.dependOn(&run_response_tests.step);
test_all_step.dependOn(&run_context_tests.step);
test_all_step.dependOn(&run_router_tests.step);
test_all_step.dependOn(&run_buffer_tests.step);
test_all_step.dependOn(&run_config_tests.step);
test_all_step.dependOn(&run_security_tests.step);
test_all_step.dependOn(&run_url_tests.step);
// Coverage analysis (runs all tests with detailed output)
const test_coverage_step = b.step("test-coverage", "📊 Run all tests with coverage analysis");
test_coverage_step.dependOn(test_all_step);
// Quick test suite (core functionality only)
const test_quick_step = b.step("test-quick", "⚡ Run quick tests (core library + integration)");
test_quick_step.dependOn(&run_lib_unit_tests.step);
test_quick_step.dependOn(&run_integration_tests.step);
// ============================================================================
// Convenience Steps
// ============================================================================
// Example server shortcuts
const run_basic_mode = b.step("run-basic-mode", "🚀 Run example server in basic mode");
run_basic_mode.dependOn(&run_example.step);
const run_secure_mode_step = b.addSystemCommand(&.{ "zig", "build", "run-basic", "--", "--mode=secure" });
const run_secure_mode = b.step("run-secure-mode", "🔒 Run example server in secure mode");
run_secure_mode.dependOn(&run_secure_mode_step.step);
const run_dev_mode_step = b.addSystemCommand(&.{ "zig", "build", "run-basic", "--", "--mode=dev" });
const run_dev_mode = b.step("run-dev-mode", "🛠️ Run example server in development mode");
run_dev_mode.dependOn(&run_dev_mode_step.step);
// Help step
const help_step = b.step("help", "📖 Show available build commands");
help_step.dependOn(&b.addSystemCommand(&.{
"echo",
\\
\\🚀 libxev-http Build Commands:
\\
\\📦 Library:
\\ install Build and install the library
\\
\\🎯 Examples:
\\ run-basic Run multi-mode example server
\\ run-basic-mode Run example server in basic mode
\\ run-secure-mode Run example server in secure mode
\\ run-dev-mode Run example server in development mode
\\
\\🧪 Testing:
\\ test Run core library unit tests
\\ test-integration Run integration tests
\\ test-quick Run quick tests (core + integration)
\\ test-all Run ALL tests (comprehensive)
\\ test-coverage Run tests with coverage analysis
\\
\\🔧 Module Tests:
\\ test-request Test HTTP request module
\\ test-response Test HTTP response module
\\ test-context Test context module
\\ test-router Test router module
\\ test-buffer Test buffer module
\\ test-config Test configuration module
\\ test-security Test security and timeout protection
\\ test-url Test URL encoding/decoding module
\\ test-middleware Test middleware module
\\
\\💡 Usage Examples:
\\ zig build run-basic -- --mode=secure
\\ zig build test-all
\\ zig build help
\\
}).step);
}