diff --git a/build.zig b/build.zig index 1e0b41d..9b7b69f 100644 --- a/build.zig +++ b/build.zig @@ -9,19 +9,19 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const nats = b.addModule("nats", .{ - .root_source_file = .{ .path = "src/nats.zig" }, + .root_source_file = b.path("src/nats.zig"), }); - nats.addIncludePath(.{ .path = b.getInstallPath(.header, "") }); const nats_c = nats_build.nats_c_lib(b, .{ .name = "nats-c", .target = target, .optimize = optimize, }); + nats.linkLibrary(nats_c); const tests = b.addTest(.{ .name = "nats-zig-unit-tests", - .root_source_file = .{ .path = "tests/main.zig" }, + .root_source_file = b.path("tests/main.zig"), .target = target, .optimize = optimize, }); @@ -38,7 +38,6 @@ pub fn build(b: *std.Build) void { .target = target, .optimize = optimize, .nats_module = nats, - .nats_c = nats_c, }); } @@ -46,7 +45,6 @@ const ExampleOptions = struct { target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, nats_module: *std.Build.Module, - nats_c: *std.Build.Step.Compile, }; const Example = struct { @@ -66,13 +64,12 @@ pub fn add_examples(b: *std.Build, options: ExampleOptions) void { inline for (examples) |example| { const ex_exe = b.addExecutable(.{ .name = example.name, - .root_source_file = .{ .path = example.file }, + .root_source_file = b.path(example.file), .target = options.target, .optimize = .Debug, }); ex_exe.root_module.addImport("nats", options.nats_module); - ex_exe.linkLibrary(options.nats_c); const install = b.addInstallArtifact(ex_exe, .{}); example_step.dependOn(&install.step); diff --git a/build.zig.zon b/build.zig.zon index 20997aa..cdd1dea 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ - .name = "nats.zig", - .version = "0.0.1", + .name = "nats_client", + .version = "0.1.0", .paths = .{ "src", "deps/nats.c/src", @@ -13,8 +13,8 @@ }, .dependencies = .{ .libressl = .{ - .url = "https://github.com/epicyclic-dev/LibreSSL-portable/archive/e95f71abab96329b3465b931822ba250c8f49236.tar.gz", - .hash = "12209998e2dc9474dc232f6be9a8bde9e49cde3e42ed71bfe8d514758f0a398b3d30", + .url = "https://github.com/epicyclic-dev/LibreSSL-portable/archive/62af702f8d57a4cd651e1cc30784abf39a3a4e66.tar.gz", + .hash = "122045ccefa4e7b4537e106d3045150f77d2aad4fce730d59678a9a8a151608a1d17", }, }, } diff --git a/nats-c.build.zig b/nats-c.build.zig index bbff4a7..f80587b 100644 --- a/nats-c.build.zig +++ b/nats-c.build.zig @@ -25,11 +25,11 @@ pub fn nats_c_lib( lib.linkLibC(); lib.addCSourceFiles(.{ .files = &common_sources, .flags = &cflags }); - lib.addIncludePath(.{ .path = nats_src_prefix ++ "include" }); + lib.addIncludePath(b.path(nats_src_prefix ++ "include")); // if building with streaming support (protocol.pb-c.c includes // , unfortunately) - lib.addIncludePath(.{ .path = "deps" }); - lib.addIncludePath(.{ .path = nats_src_prefix ++ "stan" }); + lib.addIncludePath(b.path("deps")); + lib.addIncludePath(b.path(nats_src_prefix ++ "stan")); lib.addCSourceFiles(.{ .files = &streaming_sources, .flags = &cflags }); lib.addCSourceFiles(.{ .files = &protobuf_c_sources, .flags = &cflags }); diff --git a/src/connection.zig b/src/connection.zig index 49e247f..2de3e6b 100644 --- a/src/connection.zig +++ b/src/connection.zig @@ -14,9 +14,7 @@ const std = @import("std"); -pub const nats_c = @cImport({ - @cInclude("nats/nats.h"); -}); +const nats_c = @import("./nats_c.zig").nats_c; const Subscription = @import("./subscription.zig").Subscription; const SubscriptionCallbackSignature = @import("./subscription.zig").SubscriptionCallbackSignature; diff --git a/src/error.zig b/src/error.zig index cd508c9..40d81e1 100644 --- a/src/error.zig +++ b/src/error.zig @@ -14,9 +14,7 @@ const std = @import("std"); -pub const nats_c = @cImport({ - @cInclude("nats/nats.h"); -}); +const nats_c = @import("./nats_c.zig").nats_c; // pub const AllocError = Error || std.mem.Allocator.Error; diff --git a/src/message.zig b/src/message.zig index 08e1dd5..e463519 100644 --- a/src/message.zig +++ b/src/message.zig @@ -14,9 +14,7 @@ const std = @import("std"); -pub const nats_c = @cImport({ - @cInclude("nats/nats.h"); -}); +const nats_c = @import("./nats_c.zig").nats_c; const err_ = @import("./error.zig"); const Error = err_.Error; diff --git a/src/nats.zig b/src/nats.zig index bace72f..da6d5a4 100644 --- a/src/nats.zig +++ b/src/nats.zig @@ -14,9 +14,7 @@ const std = @import("std"); -pub const nats_c = @cImport({ - @cInclude("nats/nats.h"); -}); +pub const nats_c = @import("./nats_c.zig").nats_c; const err_ = @import("./error.zig"); const con_ = @import("./connection.zig"); diff --git a/src/nats_c.zig b/src/nats_c.zig new file mode 100644 index 0000000..80df899 --- /dev/null +++ b/src/nats_c.zig @@ -0,0 +1,3 @@ +pub const nats_c = @cImport({ + @cInclude("nats/nats.h"); +}); diff --git a/src/statistics.zig b/src/statistics.zig index 262b652..d329fd8 100644 --- a/src/statistics.zig +++ b/src/statistics.zig @@ -14,9 +14,7 @@ const std = @import("std"); -const nats_c = @cImport({ - @cInclude("nats/nats.h"); -}); +const nats_c = @import("./nats_c.zig").nats_c; const err_ = @import("./error.zig"); const Status = err_.Status; diff --git a/src/subscription.zig b/src/subscription.zig index a01522c..f430f2a 100644 --- a/src/subscription.zig +++ b/src/subscription.zig @@ -14,9 +14,7 @@ const std = @import("std"); -pub const nats_c = @cImport({ - @cInclude("nats/nats.h"); -}); +const nats_c = @import("./nats_c.zig").nats_c; const Connection = @import("./connection.zig").Connection; diff --git a/src/thunk.zig b/src/thunk.zig index 956fbd9..8a10fa4 100644 --- a/src/thunk.zig +++ b/src/thunk.zig @@ -14,9 +14,7 @@ const std = @import("std"); -pub const nats_c = @cImport({ - @cInclude("nats/nats.h"); -}); +const nats_c = @import("./nats_c.zig").nats_c; pub fn checkUserDataType(comptime T: type) void { switch (@typeInfo(T)) { diff --git a/tests/util.zig b/tests/util.zig index 6fa0ae9..65c9ce3 100644 --- a/tests/util.zig +++ b/tests/util.zig @@ -20,7 +20,7 @@ const TestLaunchError = error{ pub const TestServer = struct { allocator: std.mem.Allocator, - process: std.ChildProcess, + process: std.process.Child, key_dir: ?std.testing.TmpDir, url: [:0]u8, @@ -99,8 +99,8 @@ pub const TestServer = struct { const out_dir = std.testing.tmpDir(.{}); key_dir = out_dir; - try out_dir.dir.writeFile("server.key", pair.key); - try out_dir.dir.writeFile("server.cert", pair.cert); + try out_dir.dir.writeFile(.{ .sub_path = "server.key", .data = pair.key }); + try out_dir.dir.writeFile(.{ .sub_path = "server.cert", .data = pair.cert }); // since testing.tmpDir will actually bury itself in zig-cache/tmp, // there's not an easy way to extract files from within the temp // directory except through using realPath, as far as I can tell @@ -123,7 +123,7 @@ pub const TestServer = struct { defer options.allocator.free(args); - var child = std.ChildProcess.init(args, options.allocator); + var child = std.process.Child.init(args, options.allocator); child.stdin_behavior = .Ignore; child.stdout_behavior = .Pipe; child.stderr_behavior = .Pipe;