@@ -17,11 +17,14 @@ pub fn build(b: *std.Build) void {
17
17
// set a preferred release mode, allowing the user to decide how to optimize.
18
18
const optimize = b .standardOptimizeOption (.{});
19
19
20
+ const pkg_dep = b .option (bool , "fetch" , "Download libzmq with zig-pkg [default: false]" ) orelse false ;
21
+
20
22
const libzmq_dep = b .dependency ("libzmq" , .{
21
23
.optimize = optimize ,
22
24
.target = target ,
23
25
});
24
26
const libzmq = libzmq_dep .artifact ("zmq" );
27
+
25
28
const config_header = if (! target .isWindows ()) b .addConfigHeader (.{
26
29
.style = .blank ,
27
30
.include_path = "platform.h" ,
@@ -38,26 +41,46 @@ pub fn build(b: *std.Build) void {
38
41
.include_path = "platform.h" ,
39
42
}, .{});
40
43
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" ,
43
47
// In this case the main source file is merely a path, however, in more
44
48
// 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" },
47
60
.target = target ,
48
61
.optimize = optimize ,
49
62
});
50
63
lib .addConfigHeader (config_header );
51
64
lib .addIncludePath ("../../include" );
52
65
lib .addIncludePath (config_header .include_path );
53
66
lib .addCSourceFiles (lib_src , lib_flags );
54
- if (target .isWindows ()) {
67
+ if (target .isWindows () and shared ) {
55
68
lib .linkSystemLibraryName ("ws2_32" );
56
69
lib .linkSystemLibraryName ("rpcrt4" );
57
70
lib .linkSystemLibraryName ("iphlpapi" );
58
71
}
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
+ }
61
84
// This declares intent for the library to be installed into the standard
62
85
// location when the user invokes the "install" step (the default step when
63
86
// running `zig build`).
@@ -67,21 +90,27 @@ pub fn build(b: *std.Build) void {
67
90
68
91
// Creates a step for unit testing.
69
92
const libtest = b .addTest (.{
70
- .root_source_file = .{ .path = "src/main .zig" },
93
+ .root_source_file = .{ .path = "src/czmq .zig" },
71
94
.target = target ,
72
95
.optimize = optimize ,
73
96
});
74
97
libtest .addConfigHeader (config_header );
75
98
libtest .addIncludePath (config_header .include_path );
76
99
libtest .addIncludePath ("../../include" );
77
100
libtest .addCSourceFiles (lib_src , lib_flags );
78
- if (target .isWindows ()) {
101
+ if (target .isWindows () and shared ) {
79
102
libtest .linkSystemLibraryName ("ws2_32" );
80
103
libtest .linkSystemLibraryName ("rpcrt4" );
81
104
libtest .linkSystemLibraryName ("iphlpapi" );
82
105
}
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
+ }
85
114
// This creates a build step. It will be visible in the `zig build --help` menu,
86
115
// and can be selected like this: `zig build test`
87
116
// This will evaluate the `test` step rather than the default, which is "install".
@@ -93,6 +122,7 @@ const lib_flags: []const []const u8 = &.{
93
122
"-std=gnu99" ,
94
123
"-O3" ,
95
124
"-Wall" ,
125
+ "-pedantic" ,
96
126
};
97
127
const lib_src : []const []const u8 = &.{
98
128
"../../src/zactor.c" ,
@@ -126,4 +156,14 @@ const lib_src: []const []const u8 = &.{
126
156
"../../src/zproxy.c" ,
127
157
"../../src/zrex.c" ,
128
158
"../../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" ,
129
169
};
0 commit comments