From 169fae7f020accbfd18be0e544ad92615f4c42a1 Mon Sep 17 00:00:00 2001 From: torque Date: Sun, 15 Sep 2024 20:06:51 -0700 Subject: [PATCH] build: add libsodium support --- build.zig | 16 ++++++++++++++++ build.zig.zon | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/build.zig b/build.zig index 370ac0d..252d930 100644 --- a/build.zig +++ b/build.zig @@ -4,6 +4,7 @@ pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); + const enable_libsodium = b.option(bool, "enable-libsodium", "Build with libsodium for higher-performance signing (default: true)") orelse true; const enable_tls = b.option(bool, "enable-tls", "Build TLS support (default: true)") orelse true; const tls_verify = b.option(bool, "force-host-verify", "Force hostname verification for TLS connections (default: true)") orelse true; const enable_streaming = b.option(bool, "enable-streaming", "Build with streaming support (default: true)") orelse true; @@ -17,6 +18,15 @@ pub fn build(b: *std.Build) void { "protobuf_c", .{ .target = target, .optimize = optimize }, ) else null; + const libsodium_dep = if (enable_libsodium) b.lazyDependency( + "libsodium", + .{ + .target = target, + .optimize = optimize, + .static = true, + .shared = false, + }, + ) else null; const lib = b.addStaticLibrary(.{ .name = "nats", @@ -100,6 +110,12 @@ pub fn build(b: *std.Build) void { lib.linkLibrary(dep.artifact("protobuf_c")); } + if (libsodium_dep) |dep| { + lib.defineCMacro("NATS_USE_LIBSODIUM", null); + // yep + lib.linkLibrary(dep.artifact(if (tinfo.isMinGW()) "libsodium-static" else "sodium")); + } + b.installArtifact(lib); } diff --git a/build.zig.zon b/build.zig.zon index 69d066f..649350d 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -17,6 +17,11 @@ .hash = "1220f454bf9412333c5d21b8c21b323fc7e4e37b02341bf2fa49f110b8bc5d97c972", .lazy = true, }, + .libsodium = .{ + .url = "git+https://github.com/jedisct1/libsodium.git?ref=1.0.20-RELEASE#9511c982fb1d046470a8b42aa36556cdb7da15de", + .hash = "1220d265dc673167ffe4a3cefe2840893d2910cfd773cfb1893ff768d5f1351d2a1f", + .lazy = true, + }, }, .paths = .{ "build.zig",