Compare commits
5 Commits
74bbe30d0a
...
zig-0.11.x
| Author | SHA1 | Date | |
|---|---|---|---|
|
320bef2c63
|
|||
|
28c7890f6c
|
|||
|
5939836bec
|
|||
|
4f26bf8fca
|
|||
|
c4a8ae1a38
|
@@ -22,7 +22,7 @@ Only tagged release versions of `nats.c` will be used. The current version of `n
|
||||
|
||||
# Zig Version Support
|
||||
|
||||
Since the language is still under active development, any written Zig code is a moving target. The master branch targets zig 0.12 development versions (though it is not guaranteed to work with all versions. Check the commit history for specific version updates). The `zig-0.11.x` branch targets the current stable zig release, 0.11.
|
||||
Since the language is still under active development, any written Zig code is a moving target. The plan is to support Zig `0.11.*` exclusively until the NATS library API has good coverage and is stabilized. At that point, if there are major breaking changes, a maintenance branch will be created, and master will probably move to track Zig master.
|
||||
|
||||
# Using
|
||||
|
||||
|
||||
16
build.zig
16
build.zig
@@ -9,7 +9,7 @@ pub fn build(b: *std.Build) void {
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const nats = b.addModule("nats", .{
|
||||
.root_source_file = b.path("src/nats.zig"),
|
||||
.source_file = .{ .path = "src/nats.zig" },
|
||||
});
|
||||
|
||||
const nats_c = nats_build.nats_c_lib(b, .{
|
||||
@@ -17,16 +17,15 @@ pub fn build(b: *std.Build) void {
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
nats.linkLibrary(nats_c);
|
||||
|
||||
const tests = b.addTest(.{
|
||||
.name = "nats-zig-unit-tests",
|
||||
.root_source_file = b.path("tests/main.zig"),
|
||||
.root_source_file = .{ .path = "tests/main.zig" },
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
tests.root_module.addImport("nats", nats);
|
||||
tests.addModule("nats", nats);
|
||||
tests.linkLibrary(nats_c);
|
||||
|
||||
const run_main_tests = b.addRunArtifact(tests);
|
||||
@@ -38,13 +37,15 @@ pub fn build(b: *std.Build) void {
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.nats_module = nats,
|
||||
.nats_c = nats_c,
|
||||
});
|
||||
}
|
||||
|
||||
const ExampleOptions = struct {
|
||||
target: std.Build.ResolvedTarget,
|
||||
target: std.zig.CrossTarget,
|
||||
optimize: std.builtin.OptimizeMode,
|
||||
nats_module: *std.Build.Module,
|
||||
nats_c: *std.Build.Step.Compile,
|
||||
};
|
||||
|
||||
const Example = struct {
|
||||
@@ -64,12 +65,13 @@ 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 = b.path(example.file),
|
||||
.root_source_file = .{ .path = example.file },
|
||||
.target = options.target,
|
||||
.optimize = .Debug,
|
||||
});
|
||||
|
||||
ex_exe.root_module.addImport("nats", options.nats_module);
|
||||
ex_exe.addModule("nats", options.nats_module);
|
||||
ex_exe.linkLibrary(options.nats_c);
|
||||
|
||||
const install = b.addInstallArtifact(ex_exe, .{});
|
||||
example_step.dependOn(&install.step);
|
||||
|
||||
@@ -1,20 +1,10 @@
|
||||
.{
|
||||
.name = "nats_client",
|
||||
.version = "0.1.0",
|
||||
.paths = .{
|
||||
"src",
|
||||
"deps/nats.c/src",
|
||||
"deps/nats.c/LICENSE",
|
||||
"deps/protobuf-c",
|
||||
"build.zig",
|
||||
"nats-c.build.zig",
|
||||
"build.zig.zon",
|
||||
"LICENSE",
|
||||
},
|
||||
.name = "nats.zig",
|
||||
.version = "0.0.1",
|
||||
.dependencies = .{
|
||||
.libressl = .{
|
||||
.url = "https://github.com/epicyclic-dev/LibreSSL-portable/archive/62af702f8d57a4cd651e1cc30784abf39a3a4e66.tar.gz",
|
||||
.hash = "122045ccefa4e7b4537e106d3045150f77d2aad4fce730d59678a9a8a151608a1d17",
|
||||
.url = "https://github.com/epicyclic-dev/LibreSSL-portable/archive/4bbf9ad43fd5d56c8e15bc2e880aab7c4e49731b.tar.gz",
|
||||
.hash = "1220282c6f64f531b9d07d5ed1959708822f4f8dc2486a7005be391c8f5cdf2a502a",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ const std = @import("std");
|
||||
|
||||
const NatsCOptions = struct {
|
||||
name: []const u8,
|
||||
target: std.Build.ResolvedTarget,
|
||||
target: std.zig.CrossTarget,
|
||||
optimize: std.builtin.OptimizeMode,
|
||||
};
|
||||
|
||||
@@ -24,36 +24,36 @@ pub fn nats_c_lib(
|
||||
};
|
||||
|
||||
lib.linkLibC();
|
||||
lib.addCSourceFiles(.{ .files = &common_sources, .flags = &cflags });
|
||||
lib.addIncludePath(b.path(nats_src_prefix ++ "include"));
|
||||
lib.addCSourceFiles(&common_sources, &cflags);
|
||||
lib.addIncludePath(.{ .path = nats_src_prefix ++ "include" });
|
||||
// if building with streaming support (protocol.pb-c.c includes
|
||||
// <protobuf-c/protobuf-c.h>, unfortunately)
|
||||
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 });
|
||||
lib.addIncludePath(.{ .path = "deps" });
|
||||
lib.addIncludePath(.{ .path = nats_src_prefix ++ "stan" });
|
||||
lib.addCSourceFiles(&streaming_sources, &cflags);
|
||||
lib.addCSourceFiles(&protobuf_c_sources, &cflags);
|
||||
|
||||
const ssl_dep = b.dependency("libressl", .{
|
||||
.target = options.target,
|
||||
.optimize = options.optimize,
|
||||
});
|
||||
|
||||
const tinfo = options.target.result;
|
||||
const tinfo = lib.target_info.target;
|
||||
switch (tinfo.os.tag) {
|
||||
.windows => {
|
||||
lib.addCSourceFiles(.{ .files = &win_sources, .flags = &cflags });
|
||||
lib.addCSourceFiles(&win_sources, &cflags);
|
||||
if (tinfo.abi != .msvc) {
|
||||
lib.addCSourceFiles(.{ .files = &.{"src/win-crosshack.c"}, .flags = &cflags });
|
||||
lib.addCSourceFiles(&.{"src/win-crosshack.c"}, &cflags);
|
||||
}
|
||||
lib.defineCMacro("_WIN32", null);
|
||||
lib.linkSystemLibrary("ws2_32");
|
||||
},
|
||||
.macos => {
|
||||
lib.addCSourceFiles(.{ .files = &unix_sources, .flags = &cflags });
|
||||
lib.addCSourceFiles(&unix_sources, &cflags);
|
||||
lib.defineCMacro("DARWIN", null);
|
||||
},
|
||||
else => {
|
||||
lib.addCSourceFiles(.{ .files = &unix_sources, .flags = &cflags });
|
||||
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 included with linkLibC
|
||||
@@ -69,7 +69,7 @@ pub fn nats_c_lib(
|
||||
lib.defineCMacro("_REENTRANT", null);
|
||||
|
||||
inline for (install_headers) |header| {
|
||||
lib.installHeader(b.path(nats_src_prefix ++ header), "nats/" ++ header);
|
||||
lib.installHeader(nats_src_prefix ++ header, "nats/" ++ header);
|
||||
}
|
||||
|
||||
lib.linkLibrary(ssl_dep.artifact("ssl"));
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const nats_c = @import("./nats_c.zig").nats_c;
|
||||
pub const nats_c = @cImport({
|
||||
@cInclude("nats/nats.h");
|
||||
});
|
||||
|
||||
const Subscription = @import("./subscription.zig").Subscription;
|
||||
const SubscriptionCallbackSignature = @import("./subscription.zig").SubscriptionCallbackSignature;
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const nats_c = @import("./nats_c.zig").nats_c;
|
||||
pub const nats_c = @cImport({
|
||||
@cInclude("nats/nats.h");
|
||||
});
|
||||
|
||||
// pub const AllocError = Error || std.mem.Allocator.Error;
|
||||
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const nats_c = @import("./nats_c.zig").nats_c;
|
||||
pub const nats_c = @cImport({
|
||||
@cInclude("nats/nats.h");
|
||||
});
|
||||
|
||||
const err_ = @import("./error.zig");
|
||||
const Error = err_.Error;
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
pub const nats_c = @import("./nats_c.zig").nats_c;
|
||||
pub const nats_c = @cImport({
|
||||
@cInclude("nats/nats.h");
|
||||
});
|
||||
|
||||
const err_ = @import("./error.zig");
|
||||
const con_ = @import("./connection.zig");
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
pub const nats_c = @cImport({
|
||||
@cInclude("nats/nats.h");
|
||||
});
|
||||
@@ -14,7 +14,9 @@
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const nats_c = @import("./nats_c.zig").nats_c;
|
||||
const nats_c = @cImport({
|
||||
@cInclude("nats/nats.h");
|
||||
});
|
||||
|
||||
const err_ = @import("./error.zig");
|
||||
const Status = err_.Status;
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const nats_c = @import("./nats_c.zig").nats_c;
|
||||
pub const nats_c = @cImport({
|
||||
@cInclude("nats/nats.h");
|
||||
});
|
||||
|
||||
const Connection = @import("./connection.zig").Connection;
|
||||
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const nats_c = @import("./nats_c.zig").nats_c;
|
||||
pub const nats_c = @cImport({
|
||||
@cInclude("nats/nats.h");
|
||||
});
|
||||
|
||||
pub fn checkUserDataType(comptime T: type) void {
|
||||
switch (@typeInfo(T)) {
|
||||
|
||||
@@ -20,7 +20,7 @@ const TestLaunchError = error{
|
||||
|
||||
pub const TestServer = struct {
|
||||
allocator: std.mem.Allocator,
|
||||
process: std.process.Child,
|
||||
process: std.ChildProcess,
|
||||
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(.{ .sub_path = "server.key", .data = pair.key });
|
||||
try out_dir.dir.writeFile(.{ .sub_path = "server.cert", .data = pair.cert });
|
||||
try out_dir.dir.writeFile("server.key", pair.key);
|
||||
try out_dir.dir.writeFile("server.cert", 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.process.Child.init(args, options.allocator);
|
||||
var child = std.ChildProcess.init(args, options.allocator);
|
||||
child.stdin_behavior = .Ignore;
|
||||
child.stdout_behavior = .Pipe;
|
||||
child.stderr_behavior = .Pipe;
|
||||
|
||||
Reference in New Issue
Block a user