diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..ce064da --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,40 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + branches: + - master + workflow_dispatch: + +jobs: + build: + strategy: + fail-fast: false + matrix: + zig-version: ["0.13.0"] + os: [ubuntu-latest, macos-latest, windows-latest] + include: + - zig-version: "0.12.1" + os: ubuntu-latest + - zig-version: "master" + check-format: true + os: ubuntu-latest + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Zig + uses: mlugg/setup-zig@v1 + with: + version: ${{ matrix.zig-version }} + + - if: ${{ matrix.check-format }} + name: Check Formatting + run: zig fmt --ast-check --check . + + - name: Build + run: zig build --summary all diff --git a/build.zig b/build.zig index e703666..370ac0d 100644 --- a/build.zig +++ b/build.zig @@ -24,9 +24,7 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }); - const cflags: []const []const u8 = &.{ - "-fno-sanitize=undefined", - }; + const cflags: []const []const u8 = &.{}; const src_root = upstream.path("src"); @@ -76,7 +74,7 @@ pub fn build(b: *std.Build) void { for (install_headers) |header| { lib.installHeader( - src_root.path(b, header), + upstream.path(b.pathJoin(&.{ "src", header })), b.pathJoin(&.{ "nats", header }), ); } diff --git a/build.zig.zon b/build.zig.zon index bd9e01e..69d066f 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -10,10 +10,12 @@ .libressl = .{ .url = "git+https://github.com/allyourcodebase/libressl.git?ref=3.9.2#a373b82991947b694196ee630bd6a648d71e2b3f", .hash = "1220b1536d43ed8ce79ee05c53929f90b67dd299e61dfa249fa8f476f17eee46a95f", + .lazy = true, }, .protobuf_c = .{ .url = "git+https://github.com/allyourcodebase/protobuf-c.git?ref=1.5.0#ae7587481485e615d3866861703d41d3efc22b82", .hash = "1220f454bf9412333c5d21b8c21b323fc7e4e37b02341bf2fa49f110b8bc5d97c972", + .lazy = true, }, }, .paths = .{ diff --git a/readme.md b/readme.md index f5f9c4c..2484028 100644 --- a/readme.md +++ b/readme.md @@ -1,23 +1,57 @@ -# LibreSSL +# NATS.c -This is the [NATS C client library](https://github.com/nats-io/nats.c), packaged for [Zig](https://ziglang.org/). +This is the [NATS C client library][nats.c], packaged for [Zig](https://ziglang.org/). -## Installation +## Status + +This library only explicitly supports Linux, macOS, and Windows operating systems. Building for other platforms is currently untested, so your mileage may vary. + +## Zig Bindings + +The following projects provide zig language bindings to the NATS.c library: + +- [`epicyclic-dev/nats-client`][epicyclic-dev-bindings] + +## Usage First, update your `build.zig.zon`: -``` +```sh # Initialize a `zig build` project if you haven't already zig init -zig fetch --save +# replace with the version you want to use, e.g. 3.8.2 +zig fetch --save git+https://github.com/allyourcodebase/protobuf-c# ``` You can then import `nats_c` in your `build.zig` with: ```zig -const nats_c_dependency = b.dependency("nats_c", .{ +const nats_c_dep = b.dependency("nats_c", .{ .target = target, .optimize = optimize, + .@"enable-tls" = true, // enable SSL/TLS support + .@"force-host-verify" = true, // force hostname verification for TLS connections + .@"enable-streaming" = true, // build with support for NATS streaming extensions }); -your_exe.linkLibrary(nats_c_dependency.artifact("nats_c")); +your_exe.linkLibrary(nats_c_dep.artifact("nats_c")); ``` + +## Dependencies + +The NATS.c library has two optional dependencies: + +- [`libressl`][libressl] when building with `enable-tls` +- [`protobuf-c`][protobuf-c] when building with `enable-streaming` + +These dependencies are currently automatically retrieved and compiled as static libraries by the zig build system. + +## Version Support Matrix + +| Refname | NATS.c Version | Zig `0.12.x` | Zig `0.13.x` | Zig `0.14.0-dev` | +|----------|----------------|--------------|--------------|------------------| +| `3.8.2` | `3.8.2` | ✅ | ✅ | ✅ | + +[nats.c]: https://github.com/nats-io/nats.c +[libressl]: https://github.com/allyourcodebase/libressl +[protobuf-c]: https://github.com/allyourcodebase/protobuf-c +[epicyclic-dev-bindings]: https://github.com/epicyclic-dev/nats-client