An HTTP/1.1 server for zig
0

Configure Feed

Select the types of activity you want to include in your feed.

http.zig / build.zig
4.0 kB 102 lines
1const std = @import("std"); 2 3pub fn build(b: *std.Build) !void { 4 const target = b.standardTargetOptions(.{}); 5 const optimize = b.standardOptimizeOption(.{}); 6 7 const dep_opts = .{ .target = target, .optimize = optimize }; 8 const metrics_module = b.dependency("metrics", dep_opts).module("metrics"); 9 const websocket_module = b.dependency("websocket", dep_opts).module("websocket"); 10 11 const enable_tsan = b.option(bool, "tsan", "Enable ThreadSanitizer"); 12 13 const httpz_module = b.addModule("httpz", .{ 14 .link_libc = true, 15 .root_source_file = b.path("src/httpz.zig"), 16 .target = target, 17 .optimize = optimize, 18 .sanitize_thread = enable_tsan, 19 .imports = &.{ 20 .{ .name = "metrics", .module = metrics_module }, 21 .{ .name = "websocket", .module = websocket_module }, 22 }, 23 }); 24 { 25 const options = b.addOptions(); 26 options.addOption(bool, "httpz_blocking", false); 27 httpz_module.addOptions("build", options); 28 } 29 30 { 31 const test_filter = b.option([]const []const u8, "test-filter", "Filters for test: specify multiple times for multiple filters"); 32 const tests = b.addTest(.{ 33 .root_module = httpz_module, 34 .filters = test_filter orelse &.{}, 35 .test_runner = .{ .path = b.path("test_runner.zig"), .mode = .simple }, 36 }); 37 const force_blocking = b.option(bool, "force_blocking", "Force blocking mode") orelse false; 38 { 39 const options = b.addOptions(); 40 options.addOption(bool, "httpz_blocking", force_blocking); 41 tests.root_module.addOptions("build", options); 42 } 43 { 44 // const options = b.addOptions(); 45 // options.addOption(bool, "websocket_blocking", force_blocking); 46 // websocket_module.addOptions("build", options); 47 } 48 49 tests.root_module.addImport("metrics", metrics_module); 50 // tests.root_module.addImport("websocket", websocket_module); 51 const run_test = b.addRunArtifact(tests); 52 run_test.has_side_effects = true; 53 54 const test_step = b.step("test", "Run tests"); 55 test_step.dependOn(&run_test.step); 56 } 57 58 const examples = [_]struct { 59 file: []const u8, 60 name: []const u8, 61 libc: bool = false, 62 }{ 63 .{ .file = "examples/01_basic.zig", .name = "example_1" }, 64 .{ .file = "examples/02_handler.zig", .name = "example_2" }, 65 .{ .file = "examples/03_dispatch.zig", .name = "example_3" }, 66 .{ .file = "examples/04_action_context.zig", .name = "example_4" }, 67 .{ .file = "examples/05_request_takeover.zig", .name = "example_5" }, 68 .{ .file = "examples/06_middleware.zig", .name = "example_6" }, 69 .{ .file = "examples/07_advanced_routing.zig", .name = "example_7" }, 70 .{ .file = "examples/08_websocket.zig", .name = "example_8" }, 71 // @ZIG016 72 // .{ .file = "examples/09_shutdown.zig", .name = "example_9", .libc = true }, 73 .{ .file = "examples/10_file_upload.zig", .name = "example_10" }, 74 .{ .file = "examples/11_html_streaming.zig", .name = "example_11" }, 75 }; 76 77 { 78 for (examples) |ex| { 79 const exe = b.addExecutable(.{ 80 .name = ex.name, 81 .root_module = b.createModule(.{ 82 .root_source_file = b.path(ex.file), 83 .target = target, 84 .optimize = optimize, 85 .imports = &.{ 86 .{ .name = "httpz", .module = httpz_module }, 87 }, 88 }), 89 }); 90 b.installArtifact(exe); 91 92 const run_cmd = b.addRunArtifact(exe); 93 run_cmd.step.dependOn(b.getInstallStep()); 94 if (b.args) |args| { 95 run_cmd.addArgs(args); 96 } 97 98 const run_step = b.step(ex.name, ex.file); 99 run_step.dependOn(&run_cmd.step); 100 } 101 } 102}