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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
const std = @import("std");
const NativeTargetInfo = std.zig.system.NativeTargetInfo;
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const module = b.addModule("oniguruma", .{
.root_source_file = b.path("main.zig"),
.target = target,
.optimize = optimize,
});
// For dynamic linking, we prefer dynamic linking and to search by
// mode first. Mode first will search all paths for a dynamic library
// before falling back to static.
const dynamic_link_opts: std.Build.Module.LinkSystemLibraryOptions = .{
.preferred_link_mode = .dynamic,
.search_strategy = .mode_first,
};
var test_exe: ?*std.Build.Step.Compile = null;
if (target.query.isNative()) {
test_exe = b.addTest(.{
.name = "test",
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"),
.target = target,
.optimize = optimize,
}),
});
const tests_run = b.addRunArtifact(test_exe.?);
const test_step = b.step("test", "Run tests");
test_step.dependOn(&tests_run.step);
// Uncomment this if we're debugging tests
b.installArtifact(test_exe.?);
}
if (b.systemIntegrationOption("oniguruma", .{})) {
module.linkSystemLibrary("oniguruma", dynamic_link_opts);
if (test_exe) |exe| {
exe.root_module.linkSystemLibrary("oniguruma", dynamic_link_opts);
}
} else {
const lib = try buildLib(b, module, .{
.target = target,
.optimize = optimize,
});
if (test_exe) |exe| {
exe.root_module.linkLibrary(lib);
}
}
}
fn buildLib(b: *std.Build, module: *std.Build.Module, options: anytype) !*std.Build.Step.Compile {
const target = options.target;
const optimize = options.optimize;
const lib = b.addLibrary(.{
.name = "oniguruma",
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
.linkage = .static,
});
const t = target.result;
const is_windows = t.os.tag == .windows;
if (target.result.os.tag.isDarwin()) {
const apple_sdk = @import("apple_sdk");
try apple_sdk.addPaths(b, lib);
}
if (b.lazyDependency("oniguruma", .{})) |upstream| {
lib.root_module.addIncludePath(upstream.path("src"));
module.addIncludePath(upstream.path("src"));
lib.root_module.addConfigHeader(b.addConfigHeader(.{
.style = .{ .cmake = upstream.path("src/config.h.cmake.in") },
}, .{
.PACKAGE = "oniguruma",
.PACKAGE_VERSION = "6.9.9",
.VERSION = "6.9.9",
.HAVE_ALLOCA = true,
.HAVE_ALLOCA_H = !is_windows,
.USE_CRNL_AS_LINE_TERMINATOR = is_windows,
.HAVE_STDINT_H = true,
.HAVE_SYS_TIMES_H = !is_windows,
.HAVE_SYS_TIME_H = !is_windows,
.HAVE_SYS_TYPES_H = true,
.HAVE_UNISTD_H = !is_windows,
.HAVE_INTTYPES_H = true,
.SIZEOF_INT = t.cTypeByteSize(.int),
.SIZEOF_LONG = t.cTypeByteSize(.long),
.SIZEOF_LONG_LONG = t.cTypeByteSize(.longlong),
.SIZEOF_VOIDP = t.ptrBitWidth() / t.cTypeBitSize(.char),
}));
var flags: std.ArrayList([]const u8) = .empty;
defer flags.deinit(b.allocator);
if (target.result.abi == .msvc) {
try flags.appendSlice(b.allocator, &.{
"-fno-sanitize=undefined",
"-fno-sanitize-trap=undefined",
});
}
lib.root_module.addCSourceFiles(.{
.root = upstream.path(""),
.flags = flags.items,
.files = &.{
"src/regerror.c",
"src/regparse.c",
"src/regext.c",
"src/regcomp.c",
"src/regexec.c",
"src/reggnu.c",
"src/regenc.c",
"src/regsyntax.c",
"src/regtrav.c",
"src/regversion.c",
"src/st.c",
"src/onig_init.c",
"src/unicode.c",
"src/ascii.c",
"src/utf8.c",
"src/utf16_be.c",
"src/utf16_le.c",
"src/utf32_be.c",
"src/utf32_le.c",
"src/euc_jp.c",
"src/sjis.c",
"src/iso8859_1.c",
"src/iso8859_2.c",
"src/iso8859_3.c",
"src/iso8859_4.c",
"src/iso8859_5.c",
"src/iso8859_6.c",
"src/iso8859_7.c",
"src/iso8859_8.c",
"src/iso8859_9.c",
"src/iso8859_10.c",
"src/iso8859_11.c",
"src/iso8859_13.c",
"src/iso8859_14.c",
"src/iso8859_15.c",
"src/iso8859_16.c",
"src/euc_tw.c",
"src/euc_kr.c",
"src/big5.c",
"src/gb18030.c",
"src/koi8_r.c",
"src/cp1251.c",
"src/euc_jp_prop.c",
"src/sjis_prop.c",
"src/unicode_unfold_key.c",
"src/unicode_fold1_key.c",
"src/unicode_fold2_key.c",
"src/unicode_fold3_key.c",
},
});
lib.installHeadersDirectory(
upstream.path("src"),
"",
.{ .include_extensions = &.{".h"} },
);
}
b.installArtifact(lib);
return lib;
}
|