Skip to content

Commit 859d833

Browse files
authored
build.zig: update to zig 0.15 (#777)
Also fixes dynamic builds (even in Windows) and improved compatibility by enabling compiler builtins and visibility. While at it, change the JIT flag to `support_jit` for compatibility with cmake, update CI to build with JIT and use the `bigstack` mode that is required with debug builds using clang with sanitizers.
1 parent 507bdd0 commit 859d833

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

.github/workflows/dev.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -473,14 +473,11 @@ jobs:
473473
submodules: true
474474

475475
- name: Build
476-
run: zig build
476+
run: zig build -Dsupport_jit
477477

478478
- name: Test
479479
run: |
480-
# Zig does something weird with the stack - it uses more space than the
481-
# equivalent plain C program.
482-
ulimit -S -s 65536
483-
srcdir=`pwd` pcre2test=`pwd`/zig-out/bin/pcre2test ./RunTest
480+
srcdir=`pwd` pcre2test=`pwd`/zig-out/bin/pcre2test ./RunTest -bigstack
484481
485482
bazel:
486483
# Tests with: Bazel build system

build.zig

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn build(b: *std.Build) !void {
1111
const optimize = b.standardOptimizeOption(.{});
1212
const linkage = b.option(std.builtin.LinkMode, "linkage", "whether to statically or dynamically link the library") orelse @as(std.builtin.LinkMode, if (target.result.isGnuLibC()) .dynamic else .static);
1313
const codeUnitWidth = b.option(CodeUnitWidth, "code-unit-width", "Sets the code unit width") orelse .@"8";
14-
const jit = b.option(bool, "JIT", "Enable/disable JIT compiler support") orelse false;
14+
const jit = b.option(bool, "support_jit", "Enable/disable JIT compiler support") orelse false;
1515

1616
const pcre2_header_dir = b.addWriteFiles();
1717
const pcre2_header = pcre2_header_dir.addCopyFile(b.path("src/pcre2.h.generic"), "pcre2.h");
@@ -26,6 +26,11 @@ pub fn build(b: *std.Build) !void {
2626
.HAVE_UNISTD_H = (target.result.os.tag != .windows),
2727
.HAVE_WINDOWS_H = (target.result.os.tag == .windows),
2828

29+
.HAVE_ATTRIBUTE_UNINITIALIZED = true,
30+
.HAVE_BUILTIN_MUL_OVERFLOW = true,
31+
.HAVE_BUILTIN_UNREACHABLE = true,
32+
.HAVE_VISIBILITY = true,
33+
2934
.HAVE_MEMMOVE = true,
3035
.HAVE_STRERROR = true,
3136

@@ -48,7 +53,7 @@ pub fn build(b: *std.Build) !void {
4853
},
4954
);
5055

51-
// pcre2-8/16/32.so
56+
// pcre2-8/16/32 library
5257

5358
const lib_mod = b.createModule(.{
5459
.target = target,
@@ -122,19 +127,19 @@ pub fn build(b: *std.Build) !void {
122127
.link_libc = true,
123128
});
124129

125-
pcre2test_mod.addImport(b.fmt("pcre2-{s}", .{@tagName(codeUnitWidth)}), lib_mod);
126-
127130
pcre2test_mod.addCMacro("HAVE_CONFIG_H", "");
128131
if (linkage == .static) {
129132
pcre2test_mod.addCMacro("PCRE2_STATIC", "");
133+
} else {
134+
pcre2test_mod.addCMacro("PCRE2POSIX_SHARED", "");
130135
}
131136

132137
const pcre2test = b.addExecutable(.{
133138
.name = "pcre2test",
134139
.root_module = pcre2test_mod,
135140
});
136141

137-
// pcre2-posix.so
142+
// pcre2-posix library
138143

139144
if (codeUnitWidth == CodeUnitWidth.@"8") {
140145
const posixLib_mod = b.createModule(.{
@@ -143,12 +148,12 @@ pub fn build(b: *std.Build) !void {
143148
.link_libc = true,
144149
});
145150

146-
pcre2test_mod.addImport("pcre2_posix", posixLib_mod);
147-
148151
posixLib_mod.addCMacro("HAVE_CONFIG_H", "");
149152
posixLib_mod.addCMacro("PCRE2_CODE_UNIT_WIDTH", @tagName(codeUnitWidth));
150153
if (linkage == .static) {
151154
posixLib_mod.addCMacro("PCRE2_STATIC", "");
155+
} else {
156+
posixLib_mod.addCMacro("PCRE2POSIX_SHARED", "");
152157
}
153158

154159
const posixLib = b.addLibrary(.{
@@ -167,8 +172,12 @@ pub fn build(b: *std.Build) !void {
167172
},
168173
});
169174

175+
posixLib.linkLibrary(lib);
176+
170177
posixLib.installHeader(b.path("src/pcre2posix.h"), "pcre2posix.h");
171178
b.installArtifact(posixLib);
179+
180+
pcre2test.linkLibrary(posixLib);
172181
}
173182

174183
// pcre2test (again)
@@ -181,5 +190,7 @@ pub fn build(b: *std.Build) !void {
181190
.file = b.path("src/pcre2test.c"),
182191
});
183192

193+
pcre2test.linkLibrary(lib);
194+
184195
b.installArtifact(pcre2test);
185196
}

0 commit comments

Comments
 (0)