Skip to content

Commit 74ecc63

Browse files
committed
Some changes...
1 parent fe83262 commit 74ecc63

File tree

3 files changed

+56
-15
lines changed

3 files changed

+56
-15
lines changed

bindings/zig/build.zig

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ pub fn build(b: *std.Build) void {
1717
// set a preferred release mode, allowing the user to decide how to optimize.
1818
const optimize = b.standardOptimizeOption(.{});
1919

20+
const pkg_dep = b.option(bool, "fetch", "Download libzmq with zig-pkg [default: false]") orelse false;
21+
2022
const libzmq_dep = b.dependency("libzmq", .{
2123
.optimize = optimize,
2224
.target = target,
2325
});
2426
const libzmq = libzmq_dep.artifact("zmq");
27+
2528
const config_header = if (!target.isWindows()) b.addConfigHeader(.{
2629
.style = .blank,
2730
.include_path = "platform.h",
@@ -38,26 +41,46 @@ pub fn build(b: *std.Build) void {
3841
.include_path = "platform.h",
3942
}, .{});
4043

41-
const lib = b.addSharedLibrary(.{
42-
.name = "zig_czmq",
44+
const shared = b.option(bool, "shared", "Build shared Library [default: false]") orelse false;
45+
const lib = if (shared) b.addSharedLibrary(.{
46+
.name = "czmq_zig",
4347
// In this case the main source file is merely a path, however, in more
4448
// complicated build scripts, this could be a generated file.
45-
.root_source_file = .{ .path = "src/main.zig" },
46-
.version = .{ .major = 4, .minor = 2, .patch = 2 },
49+
//.root_source_file = .{ .path = "src/main.zig" },
50+
.version = .{
51+
.major = 4,
52+
.minor = 2,
53+
.patch = 2,
54+
},
55+
.target = target,
56+
.optimize = optimize,
57+
}) else b.addStaticLibrary(.{
58+
.name = "czmq_zig",
59+
.root_source_file = .{ .path = "src/czmq.zig" },
4760
.target = target,
4861
.optimize = optimize,
4962
});
5063
lib.addConfigHeader(config_header);
5164
lib.addIncludePath("../../include");
5265
lib.addIncludePath(config_header.include_path);
5366
lib.addCSourceFiles(lib_src, lib_flags);
54-
if (target.isWindows()) {
67+
if (target.isWindows() and shared) {
5568
lib.linkSystemLibraryName("ws2_32");
5669
lib.linkSystemLibraryName("rpcrt4");
5770
lib.linkSystemLibraryName("iphlpapi");
5871
}
59-
lib.linkLibrary(libzmq);
60-
lib.linkLibC();
72+
if (pkg_dep)
73+
lib.linkLibrary(libzmq)
74+
else
75+
lib.linkSystemLibrary("zmq");
76+
if (target.isLinux() and shared) {
77+
lib.linkSystemLibrary("dl");
78+
lib.linkSystemLibrary("rt");
79+
}
80+
if (target.getAbi() != .msvc) {
81+
lib.linkLibCpp();
82+
lib.linkLibC();
83+
}
6184
// This declares intent for the library to be installed into the standard
6285
// location when the user invokes the "install" step (the default step when
6386
// running `zig build`).
@@ -67,21 +90,27 @@ pub fn build(b: *std.Build) void {
6790

6891
// Creates a step for unit testing.
6992
const libtest = b.addTest(.{
70-
.root_source_file = .{ .path = "src/main.zig" },
93+
.root_source_file = .{ .path = "src/czmq.zig" },
7194
.target = target,
7295
.optimize = optimize,
7396
});
7497
libtest.addConfigHeader(config_header);
7598
libtest.addIncludePath(config_header.include_path);
7699
libtest.addIncludePath("../../include");
77100
libtest.addCSourceFiles(lib_src, lib_flags);
78-
if (target.isWindows()) {
101+
if (target.isWindows() and shared) {
79102
libtest.linkSystemLibraryName("ws2_32");
80103
libtest.linkSystemLibraryName("rpcrt4");
81104
libtest.linkSystemLibraryName("iphlpapi");
82105
}
83-
libtest.linkLibrary(libzmq);
84-
libtest.linkLibC();
106+
if (pkg_dep)
107+
libtest.linkLibrary(libzmq)
108+
else
109+
libtest.linkSystemLibrary("zmq");
110+
if (target.getAbi() != .msvc) {
111+
libtest.linkLibCpp();
112+
libtest.linkLibC();
113+
}
85114
// This creates a build step. It will be visible in the `zig build --help` menu,
86115
// and can be selected like this: `zig build test`
87116
// This will evaluate the `test` step rather than the default, which is "install".
@@ -93,6 +122,7 @@ const lib_flags: []const []const u8 = &.{
93122
"-std=gnu99",
94123
"-O3",
95124
"-Wall",
125+
"-pedantic",
96126
};
97127
const lib_src: []const []const u8 = &.{
98128
"../../src/zactor.c",
@@ -126,4 +156,14 @@ const lib_src: []const []const u8 = &.{
126156
"../../src/zproxy.c",
127157
"../../src/zrex.c",
128158
"../../src/zgossip_msg.c",
159+
"../../src/ztrie.c",
160+
"../../src/zargs.c",
161+
"../../src/zproc.c",
162+
"../../src/ztimerset.c",
163+
"../../src/zhttp_server.c",
164+
"../../src/zhttp_client.c",
165+
"../../src/zhttp_request.c",
166+
"../../src/zhttp_response.c",
167+
"../../src/zhttp_server_options.c",
168+
"../../src/zosc.c",
129169
};

bindings/zig/build.zig.zon

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
.{
2-
.name = "libzig_czmq",
2+
.name = "libczmq_zig",
33
.version = "4.2.2",
44

55
.dependencies = .{
66
.libzmq = .{
7-
.url = "https://github.com/kassane/libzmq/archive/a6438dc78d00f3736ede988b0fdc2f6361c442b4.tar.gz",
8-
.hash = "1220fc3abc4aa9fb75c61b00297a2ec1d4f70d7f65f4151f6f7a93f59a265a56bc9e",
7+
.url = "https://github.com/zeromq/libzmq/archive/2ba59dac6f115d30e1648be21a8349531df87241.tar.gz",
8+
.hash = "12202e8734a0a6bf884eeba59d493fbf907bdf173115495e56e97a45ff5424d89ab1",
99
},
1010
},
1111
}

bindings/zig/src/main.zig renamed to bindings/zig/src/czmq.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const std = @import("std");
22
const czmq = @cImport(@cInclude("czmq.h"));
33
const testing = std.testing;
4+
const debug = std.debug;
45

56
test "Reference all decls" {
67
_ = czmq;
@@ -10,6 +11,6 @@ test "Reference all decls" {
1011
test "Hello 0MQ" {
1112
var publisher: ?*czmq.zsock_t = czmq.zsock_new(czmq.ZMQ_PUB);
1213
czmq.zsock_set_curve_server(publisher, @boolToInt(true));
13-
std.debug.print("\nHello, Curves!{s}", .{"\n"});
14+
debug.print("\nHello, Curves!{s}", .{"\n"});
1415
czmq.zsock_destroy(&publisher);
1516
}

0 commit comments

Comments
 (0)