@@ -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};
97127const 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};
0 commit comments