The NATS C client library ported to the zig build system
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
torque 81a546c524
deps: bump nats.c to 3.9.3
Unfortunately, nats.c 3.10.0 does not build due to adding usage of the
type `SSL_verify_cb`, which is a "newer" OpenSSL API feature that
LibreSSL does not implement (LibreSSL's OpenSSL compatibility is
limited to the OpenSSL 1.0 API from whence it was forked, and the fact
that it worked with nats.c so far was, I think, largely a
coincidence). Unfortunately, the AYCB OpenSSL build wrapper is fairly
sloppy and does not build for any target besides x86_64 Linux. Since
I'm not actively using this library at this point, fixing the OpenSSL
build is a bridge too far for me. Maybe some good Samaritan can fix it
at some point and make it straightforward to swap over.
2025-03-13 22:05:28 -06:00
.github/workflows build: support 0.14.0 2025-03-05 21:40:05 -07:00
build.zig build: support 0.14.0 2025-03-05 21:40:05 -07:00
build.zig.zon deps: bump nats.c to 3.9.3 2025-03-13 22:05:28 -06:00
LICENSE init 2024-09-15 19:48:53 -07:00
LICENSE-NATS_C init 2024-09-15 19:48:53 -07:00
readme.md deps: bump nats.c to 3.9.3 2025-03-13 22:05:28 -06:00

NATS.c

This is the NATS C client library, packaged for Zig.

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:

Usage

First, update your build.zig.zon:

# Initialize a `zig build` project if you haven't already
zig init
# replace <refname> with the version you want to use, e.g. 3.9.3
zig fetch --save git+https://github.com/allyourcodebase/nats.c.git#<refname>

You can then import nats_c in your build.zig with:

const nats_c_dep = b.dependency("nats_c", .{
    .target = target,
    .optimize = optimize,
    .@"enable-libsodium" = true, // Use libsodium for optimized implementations of some signing routines
    .@"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_dep.artifact("nats_c"));

Dependencies

The NATS.c library has optional dependencies:

These dependencies are currently automatically retrieved and compiled as static libraries by the Zig build system.

Zig Version Support Matrix

Refname NATS.c Version Zig 0.14.0 Zig 0.13.x Zig 0.12.x
3.9.3 3.9.3 ✅ ❌ ❌
3.9.1+1 3.9.1 ✅ ❌ ❌
3.9.1 3.9.1 ❌ ✅ ✅
3.8.2+1 3.8.2 ❌ ✅ ✅