From 29966dc838729648cd12536f71e7fc4e1ff6f82d Mon Sep 17 00:00:00 2001 From: torque Date: Thu, 31 Aug 2023 23:50:18 -0700 Subject: [PATCH] build: link LibreSSL for SSL support I don't have a single clue in heck if this actually works, but it at least does compile. At some point I will probably add a test or two to find out how broken this is. --- build.zig.zon | 7 ++++++- nats-c.build.zig | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/build.zig.zon b/build.zig.zon index 151f04b..7ce7fb4 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,5 +1,10 @@ .{ .name = "nats-client", .version = "0.0.1", - .dependencies = .{}, + .dependencies = .{ + .libressl = .{ + .url = "https://github.com/epicyclic-dev/LibreSSL-portable/archive/cedfc5580d2e665d66d8f357469e472bc12a099b.tar.gz", + .hash = "12204315709cc148a4c51661aa76db76bbe5192fbc762336f405c9069e95c5abf1ec", + }, + }, } diff --git a/nats-c.build.zig b/nats-c.build.zig index 3c25a6f..716442d 100644 --- a/nats-c.build.zig +++ b/nats-c.build.zig @@ -30,6 +30,11 @@ pub fn nats_c_lib( // lib.addIncludePath(.{ .path = nats_src_prefix ++ "stan" }); // lib.addCSourceFiles(&streaming_sources, &cflags); + const ssl_dep = b.dependency("libressl", .{ + .target = options.target, + .optimize = options.optimize, + }); + const tinfo = lib.target_info.target; switch (tinfo.os.tag) { .windows => { @@ -48,18 +53,23 @@ pub fn nats_c_lib( lib.addCSourceFiles(&unix_sources, &cflags); lib.defineCMacro("_GNU_SOURCE", null); lib.defineCMacro("LINUX", null); - // may need to link pthread and rt. Not sure if those are inluded with linkLibC + // may need to link pthread and rt. Not sure if those are included with linkLibC lib.linkSystemLibrary("pthread"); lib.linkSystemLibrary("rt"); }, } + lib.defineCMacro("NATS_HAS_TLS", null); + lib.defineCMacro("NATS_USE_OPENSSL_1_1", null); + lib.defineCMacro("NATS_FORCE_HOST_VERIFICATION", null); lib.defineCMacro("_REENTRANT", null); inline for (install_headers) |header| { lib.installHeader(nats_src_prefix ++ header, "nats/" ++ header); } + lib.linkLibrary(ssl_dep.artifact("ssl")); + b.installArtifact(lib); return lib;