build: update for zig-0.12.0-dev.2208+4debd4338
Incorporate various build API changes. Hopefully there won't be any other major API changes before the 0.12.0 release.
This commit is contained in:
parent
3462b3cdb6
commit
4124b912eb
11
build.zig
11
build.zig
@ -9,8 +9,9 @@ pub fn build(b: *std.Build) void {
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const nats = b.addModule("nats", .{
|
||||
.source_file = .{ .path = "src/nats.zig" },
|
||||
.root_source_file = .{ .path = "src/nats.zig" },
|
||||
});
|
||||
nats.addIncludePath(.{ .path = b.getInstallPath(.header, "") });
|
||||
|
||||
const nats_c = nats_build.nats_c_lib(b, .{
|
||||
.name = "nats-c",
|
||||
@ -25,7 +26,7 @@ pub fn build(b: *std.Build) void {
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
tests.addModule("nats", nats);
|
||||
tests.root_module.addImport("nats", nats);
|
||||
tests.linkLibrary(nats_c);
|
||||
|
||||
const run_main_tests = b.addRunArtifact(tests);
|
||||
@ -42,7 +43,7 @@ pub fn build(b: *std.Build) void {
|
||||
}
|
||||
|
||||
const ExampleOptions = struct {
|
||||
target: std.zig.CrossTarget,
|
||||
target: std.Build.ResolvedTarget,
|
||||
optimize: std.builtin.OptimizeMode,
|
||||
nats_module: *std.Build.Module,
|
||||
nats_c: *std.Build.Step.Compile,
|
||||
@ -59,7 +60,7 @@ const examples = [_]Example{
|
||||
.{ .name = "pub_bytes", .file = "examples/pub_bytes.zig" },
|
||||
};
|
||||
|
||||
pub fn add_examples(b: *std.build, options: ExampleOptions) void {
|
||||
pub fn add_examples(b: *std.Build, options: ExampleOptions) void {
|
||||
const example_step = b.step("examples", "build examples");
|
||||
|
||||
inline for (examples) |example| {
|
||||
@ -70,7 +71,7 @@ pub fn add_examples(b: *std.build, options: ExampleOptions) void {
|
||||
.optimize = .Debug,
|
||||
});
|
||||
|
||||
ex_exe.addModule("nats", options.nats_module);
|
||||
ex_exe.root_module.addImport("nats", options.nats_module);
|
||||
ex_exe.linkLibrary(options.nats_c);
|
||||
|
||||
const install = b.addInstallArtifact(ex_exe, .{});
|
||||
|
@ -1,10 +1,20 @@
|
||||
.{
|
||||
.name = "nats-client",
|
||||
.version = "0.0.1",
|
||||
.paths = .{
|
||||
"src",
|
||||
"deps/nats.c/src",
|
||||
"deps/nats.c/LICENSE",
|
||||
"deps/protobuf-c",
|
||||
"build.zig",
|
||||
"nats-c.build.zig",
|
||||
"build.zig.zon",
|
||||
"LICENSE",
|
||||
},
|
||||
.dependencies = .{
|
||||
.libressl = .{
|
||||
.url = "https://github.com/epicyclic-dev/LibreSSL-portable/archive/2b68369a2b883714cea05357aa378b3a3e8ef2f6.tar.gz",
|
||||
.hash = "12206b907fcb1dea424d122d29a0549bdc6c83648e0433973388b2efb6813b36a8fa",
|
||||
.url = "https://github.com/epicyclic-dev/LibreSSL-portable/archive/9f74aeb1d2f5db5c375a1040cbd2b9abfa2749d1.tar.gz",
|
||||
.hash = "122092a200f7e27e90974013d7e5cd5ef27438f67016852b5244ea287018263e78dc",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ const std = @import("std");
|
||||
|
||||
const NatsCOptions = struct {
|
||||
name: []const u8,
|
||||
target: std.zig.CrossTarget,
|
||||
target: std.Build.ResolvedTarget,
|
||||
optimize: std.builtin.OptimizeMode,
|
||||
};
|
||||
|
||||
@ -24,36 +24,36 @@ pub fn nats_c_lib(
|
||||
};
|
||||
|
||||
lib.linkLibC();
|
||||
lib.addCSourceFiles(&common_sources, &cflags);
|
||||
lib.addCSourceFiles(.{ .files = &common_sources, .flags = &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(.{ .path = "deps" });
|
||||
lib.addIncludePath(.{ .path = nats_src_prefix ++ "stan" });
|
||||
lib.addCSourceFiles(&streaming_sources, &cflags);
|
||||
lib.addCSourceFiles(&protobuf_c_sources, &cflags);
|
||||
lib.addCSourceFiles(.{ .files = &streaming_sources, .flags = &cflags });
|
||||
lib.addCSourceFiles(.{ .files = &protobuf_c_sources, .flags = &cflags });
|
||||
|
||||
const ssl_dep = b.dependency("libressl", .{
|
||||
.target = options.target,
|
||||
.optimize = options.optimize,
|
||||
});
|
||||
|
||||
const tinfo = lib.target_info.target;
|
||||
const tinfo = options.target.result;
|
||||
switch (tinfo.os.tag) {
|
||||
.windows => {
|
||||
lib.addCSourceFiles(&win_sources, &cflags);
|
||||
lib.addCSourceFiles(.{ .files = &win_sources, .flags = &cflags });
|
||||
if (tinfo.abi != .msvc) {
|
||||
lib.addCSourceFiles(&.{"src/win-crosshack.c"}, &cflags);
|
||||
lib.addCSourceFiles(.{ .files = &.{"src/win-crosshack.c"}, .flags = &cflags });
|
||||
}
|
||||
lib.defineCMacro("_WIN32", null);
|
||||
lib.linkSystemLibrary("ws2_32");
|
||||
},
|
||||
.macos => {
|
||||
lib.addCSourceFiles(&unix_sources, &cflags);
|
||||
lib.addCSourceFiles(.{ .files = &unix_sources, .flags = &cflags });
|
||||
lib.defineCMacro("DARWIN", null);
|
||||
},
|
||||
else => {
|
||||
lib.addCSourceFiles(&unix_sources, &cflags);
|
||||
lib.addCSourceFiles(.{ .files = &unix_sources, .flags = &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
|
||||
|
Loading…
x
Reference in New Issue
Block a user