forked from zeromq/zproject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzproject_zig.gsl
152 lines (140 loc) · 4.94 KB
/
zproject_zig.gsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Generate minimal Zig build.
#
# This is a code generator built using the iMatix GSL code generation
# language. See https://github.com/zeromq/gsl for details.
#
# Copyright (c) the Contributors as noted in the AUTHORS file.
# This file is part of zproject.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
register_target ("zig", "Zig build")
# Target provides name space isolation for its functions
.macro target_zig
.output "build.zig"
$(project.GENERATED_WARNING_HEADER:)
//! Works only Zig version: 0.11.0 or higher
const std = @import("std");
// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
pub fn build(b: *std.Build) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});
// Generating "platform.h" on $PWD/zig-cache (local build cache)
const config_header = if (!target.isWindows()) b.addConfigHeader(.{
.style = .blank,
.include_path = "platform.h",
}, .{
.CZMQ_BUILD_DRAFT_API = {},
.HAVE_LINUX_WIRELESS_H = {},
.HAVE_NET_IF_H = {},
.HAVE_NET_IF_MEDIA_H = null,
.HAVE_GETIFADDRS = {},
.HAVE_FREEIFADDRS = {},
.HAVE_DECL_AI_V4MAPPED = 0,
}) else b.addConfigHeader(.{
.style = .blank,
.include_path = "platform.h",
}, .{});
const lib = b.addSharedLibrary(.{
.name = "zig_czmq",
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
//.root_source_file = .{ .path = "bindings/zig/src/main.zig" }, // No need zig file to build library (C and/or C++ code only)
.version = .{
.major = 4,
.minor = 2,
.patch = 2,
},
.target = target,
.optimize = optimize,
});
lib.addConfigHeader(config_header);
lib.addIncludePath("include");
lib.addIncludePath(config_header.include_path);
lib.addCSourceFiles(lib_src, lib_flags);
if (target.isWindows()) {
lib.linkSystemLibraryName("ws2_32");
lib.linkSystemLibraryName("rpcrt4");
lib.linkSystemLibraryName("iphlpapi");
}
lib.linkSystemLibrary("zmq");
lib.linkLibC();
// This declares intent for the library to be installed into the standard
// location when the user invokes the "install" step (the default step when
// running `zig build`).
lib.install();
// Creates a step for unit testing.
const libtest = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
libtest.addConfigHeader(config_header);
libtest.addIncludePath(config_header.include_path);
libtest.addIncludePath("include");
libtest.addCSourceFiles(lib_src, lib_flags);
if (target.isWindows()) {
libtest.linkSystemLibraryName("ws2_32");
libtest.linkSystemLibraryName("rpcrt4");
libtest.linkSystemLibraryName("iphlpapi");
}
libtest.linkSystemLibrary("zmq");
libtest.linkLibC();
// This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build test`
// This will evaluate the `test` step rather than the default, which is "install".
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&libtest.step);
}
const lib_flags: []const []const u8 = &.{
"-std=gnu99",
"-O3",
"-Wall",
"-fno-sanitize=undefined",
"-fno-sanitize-trap=undefined",
// disable undefined sanitizer (default on zig/clang wrapper)
};
const lib_src: []const []const u8 = &.{
"src/zactor.c",
"src/zarmour.c",
"src/zcert.c",
"src/zcertstore.c",
"src/zchunk.c",
"src/zclock.c",
"src/zconfig.c",
"src/zdigest.c",
"src/zdir.c",
"src/zdir_patch.c",
"src/zfile.c",
"src/zframe.c",
"src/zhash.c",
"src/zhashx.c",
"src/ziflist.c",
"src/zlist.c",
"src/zlistx.c",
"src/zloop.c",
"src/zmsg.c",
"src/zpoller.c",
"src/zsock.c",
"src/zstr.c",
"src/zsys.c",
"src/zuuid.c",
"src/zauth.c",
"src/zbeacon.c",
"src/zgossip.c",
"src/zmonitor.c",
"src/zproxy.c",
"src/zrex.c",
"src/zgossip_msg.c",
};
.endmacro