|
| 1 | +const std = @import("std"); |
| 2 | + |
| 3 | +pub fn build(b: *std.Build) void { |
| 4 | + const target = b.standardTargetOptions(.{}); |
| 5 | + const optimize = b.standardOptimizeOption(.{}); |
| 6 | + |
| 7 | + const upstream = b.dependency("upstream", .{ |
| 8 | + .target = target, |
| 9 | + .optimize = optimize, |
| 10 | + }); |
| 11 | + |
| 12 | + const lib = b.addStaticLibrary(.{ |
| 13 | + .name = "picohttpparser", |
| 14 | + .target = target, |
| 15 | + .optimize = optimize, |
| 16 | + }); |
| 17 | + lib.addIncludePath(b.path(".")); |
| 18 | + lib.linkLibC(); |
| 19 | + lib.addCSourceFiles(.{ |
| 20 | + .root = upstream.path("."), |
| 21 | + .files = &[_][]const u8{ |
| 22 | + "picohttpparser.c", |
| 23 | + }, |
| 24 | + .flags = &[_][]const u8{ |
| 25 | + "-Wall", "-fsanitize=address,undefined", |
| 26 | + }, |
| 27 | + }); |
| 28 | + lib.installHeader(upstream.path("picohttpparser.h"), "picohttpparser.h"); |
| 29 | + |
| 30 | + b.installArtifact(lib); |
| 31 | + |
| 32 | + // Tests |
| 33 | + |
| 34 | + const picotest = b.dependency("picotest", .{ |
| 35 | + .target = target, |
| 36 | + .optimize = optimize, |
| 37 | + }); |
| 38 | + |
| 39 | + const tests = b.addExecutable(.{ |
| 40 | + .name = "test-bin", |
| 41 | + .target = target, |
| 42 | + .optimize = optimize, |
| 43 | + }); |
| 44 | + tests.linkLibrary(lib); |
| 45 | + tests.addIncludePath(upstream.path(".")); |
| 46 | + tests.addIncludePath(picotest.path(".")); |
| 47 | + tests.addCSourceFiles(.{ |
| 48 | + .root = picotest.path("."), |
| 49 | + .files = &[_][]const u8{ |
| 50 | + "picotest.c", |
| 51 | + }, |
| 52 | + .flags = &[_][]const u8{ |
| 53 | + "-Wall", "-fsanitize=address,undefined", |
| 54 | + }, |
| 55 | + }); |
| 56 | + tests.addCSourceFiles(.{ |
| 57 | + .root = upstream.path("."), |
| 58 | + .files = &[_][]const u8{ |
| 59 | + "test.c", |
| 60 | + }, |
| 61 | + .flags = &[_][]const u8{ |
| 62 | + "-Wall", "-fsanitize=address,undefined", |
| 63 | + }, |
| 64 | + }); |
| 65 | + |
| 66 | + const run_tests = b.addRunArtifact(tests); |
| 67 | + const test_step = b.step("test", "Run the tests"); |
| 68 | + test_step.dependOn(&run_tests.step); |
| 69 | +} |
0 commit comments