From 2923f4d566379a9f367bc3e2dfcbc655f705f64d Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Fri, 20 Dec 2024 01:15:44 +0100 Subject: [PATCH] initial commit --- .github/workflows/zig.yml | 24 ++++++++++++++ .gitignore | 1 + build.zig | 69 +++++++++++++++++++++++++++++++++++++++ build.zig.zon | 20 ++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 .github/workflows/zig.yml create mode 100644 .gitignore create mode 100644 build.zig create mode 100644 build.zig.zon diff --git a/.github/workflows/zig.yml b/.github/workflows/zig.yml new file mode 100644 index 0000000..c471a59 --- /dev/null +++ b/.github/workflows/zig.yml @@ -0,0 +1,24 @@ +name: CI - Zig + +on: + create: + push: + branches: master + pull_request: + schedule: + - cron: "0 18 * * *" + workflow_dispatch: + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: goto-bus-stop/setup-zig@v2 + - run: zig fmt --check . + - run: zig build + - run: zig build test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..19892e4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.zig-cache diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..c21ba18 --- /dev/null +++ b/build.zig @@ -0,0 +1,69 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const upstream = b.dependency("upstream", .{ + .target = target, + .optimize = optimize, + }); + + const lib = b.addStaticLibrary(.{ + .name = "picohttpparser", + .target = target, + .optimize = optimize, + }); + lib.addIncludePath(b.path(".")); + lib.linkLibC(); + lib.addCSourceFiles(.{ + .root = upstream.path("."), + .files = &[_][]const u8{ + "picohttpparser.c", + }, + .flags = &[_][]const u8{ + "-Wall", "-fsanitize=address,undefined", + }, + }); + lib.installHeader(upstream.path("picohttpparser.h"), "picohttpparser.h"); + + b.installArtifact(lib); + + // Tests + + const picotest = b.dependency("picotest", .{ + .target = target, + .optimize = optimize, + }); + + const tests = b.addExecutable(.{ + .name = "test-bin", + .target = target, + .optimize = optimize, + }); + tests.linkLibrary(lib); + tests.addIncludePath(upstream.path(".")); + tests.addIncludePath(picotest.path(".")); + tests.addCSourceFiles(.{ + .root = picotest.path("."), + .files = &[_][]const u8{ + "picotest.c", + }, + .flags = &[_][]const u8{ + "-Wall", "-fsanitize=address,undefined", + }, + }); + tests.addCSourceFiles(.{ + .root = upstream.path("."), + .files = &[_][]const u8{ + "test.c", + }, + .flags = &[_][]const u8{ + "-Wall", "-fsanitize=address,undefined", + }, + }); + + const run_tests = b.addRunArtifact(tests); + const test_step = b.step("test", "Run the tests"); + test_step.dependOn(&run_tests.step); +} diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..ec4a336 --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,20 @@ +.{ + .name = "picohttpparser", + .version = "0.0.0", + .dependencies = .{ + .upstream = .{ + .url = "git+https://github.com/h2o/picohttpparser?ref=master#f8d0513f1a7a111f2597d643b073935a8afaf9e5", + .hash = "1220783b493dce554f478bef55bdd94acd7dbb753dc8bc17dc2fbc57709b2a8a0909", + }, + .picotest = .{ + .url = "git+https://github.com/h2o/picotest?ref=master#a99858e0c33b97b24cd09ceae729f2be33ec01e1", + .hash = "1220d93e9c4cfccdc0bf3ea0c30f85785f8e7e0e0096b1d2fe16a9713b7261667c33", + }, + }, + .minimum_zig_version = "0.13.0", + + .paths = .{ + "build.zig", + "build.zig.zon", + }, +}