Skip to content

Commit fc55df7

Browse files
committed
Add zig build to CI
1 parent ad966b7 commit fc55df7

File tree

2 files changed

+105
-12
lines changed

2 files changed

+105
-12
lines changed

.github/workflows/dev.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,30 @@ jobs:
274274
- name: Test
275275
run: cd build && ctest -j3 --output-on-failure
276276

277+
zebrilus:
278+
# Tests with: Zig compiler
279+
name: Zig
280+
runs-on: ubuntu-latest
281+
steps:
282+
- name: Setup
283+
run: |
284+
sudo snap install zig --classic --beta
285+
286+
- name: Checkout
287+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
288+
with:
289+
submodules: true
290+
291+
- name: Build
292+
run: zig build
293+
294+
- name: Test
295+
run: |
296+
# Zig does something weird with the stack - it uses more space than the
297+
# equivalent plain C program.
298+
ulimit -S -s 16384
299+
srcdir=`pwd` pcre2test=`pwd`/zig-out/bin/pcre2test ./RunTest
300+
277301
heron:
278302
# Job to verify that the tasks performed by PrepareRelease have been done. It is
279303
# the committer's responsibility (currently) to run PrepareRelease themselves when

build.zig

Lines changed: 81 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ pub fn build(b: *std.Build) !void {
1616
_ = copyFiles.addCopyFile(b.path("src/config.h.generic"), "config.h");
1717
_ = copyFiles.addCopyFile(b.path("src/pcre2.h.generic"), "pcre2.h");
1818

19+
// pcre2-8/16/32.so
20+
1921
const lib = std.Build.Step.Compile.create(b, .{
2022
.name = b.fmt("pcre2-{s}", .{@tagName(codeUnitWidth)}),
2123
.root_module = .{
@@ -27,22 +29,21 @@ pub fn build(b: *std.Build) !void {
2729
.linkage = linkage,
2830
});
2931

32+
lib.defineCMacro("HAVE_CONFIG_H", null);
33+
lib.defineCMacro("HAVE_MEMMOVE", null);
34+
lib.defineCMacro("PCRE2_CODE_UNIT_WIDTH", @tagName(codeUnitWidth));
35+
lib.defineCMacro("SUPPORT_UNICODE", null);
3036
if (linkage == .static) {
31-
try lib.root_module.c_macros.append(b.allocator, "-DPCRE2_STATIC");
37+
lib.defineCMacro("PCRE2_STATIC", null);
3238
}
3339

34-
lib.root_module.addCMacro("PCRE2_CODE_UNIT_WIDTH", @tagName(codeUnitWidth));
40+
lib.addIncludePath(b.path("src"));
41+
lib.addIncludePath(copyFiles.getDirectory());
3542

3643
lib.addCSourceFile(.{
3744
.file = copyFiles.addCopyFile(b.path("src/pcre2_chartables.c.dist"), "pcre2_chartables.c"),
38-
.flags = &.{
39-
"-DHAVE_CONFIG_H",
40-
},
4145
});
4246

43-
lib.addIncludePath(b.path("src"));
44-
lib.addIncludePath(copyFiles.getDirectory());
45-
4647
lib.addCSourceFiles(.{
4748
.files = &.{
4849
"src/pcre2_auto_possess.c",
@@ -56,6 +57,7 @@ pub fn build(b: *std.Build) !void {
5657
"src/pcre2_error.c",
5758
"src/pcre2_extuni.c",
5859
"src/pcre2_find_bracket.c",
60+
"src/pcre2_jit_compile.c",
5961
"src/pcre2_maketables.c",
6062
"src/pcre2_match.c",
6163
"src/pcre2_match_data.c",
@@ -73,12 +75,79 @@ pub fn build(b: *std.Build) !void {
7375
"src/pcre2_valid_utf.c",
7476
"src/pcre2_xclass.c",
7577
},
76-
.flags = &.{
77-
"-DHAVE_CONFIG_H",
78-
"-DPCRE2_STATIC",
79-
},
8078
});
8179

8280
lib.installHeader(b.path("src/pcre2.h.generic"), "pcre2.h");
8381
b.installArtifact(lib);
82+
83+
84+
// pcre2test
85+
86+
const pcre2test = b.addExecutable(.{
87+
.name = "pcre2test",
88+
.target = target,
89+
.optimize = optimize,
90+
});
91+
92+
93+
// pcre2-posix.so
94+
95+
if (codeUnitWidth == CodeUnitWidth.@"8") {
96+
const posixLib = std.Build.Step.Compile.create(b, .{
97+
.name = "pcre2-posix",
98+
.root_module = .{
99+
.target = target,
100+
.optimize = optimize,
101+
.link_libc = true,
102+
},
103+
.kind = .lib,
104+
.linkage = linkage,
105+
});
106+
107+
posixLib.defineCMacro("HAVE_CONFIG_H", null);
108+
posixLib.defineCMacro("HAVE_MEMMOVE", null);
109+
posixLib.defineCMacro("PCRE2_CODE_UNIT_WIDTH", @tagName(codeUnitWidth));
110+
posixLib.defineCMacro("SUPPORT_UNICODE", null);
111+
if (linkage == .static) {
112+
posixLib.defineCMacro("PCRE2_STATIC", null);
113+
}
114+
115+
posixLib.addIncludePath(b.path("src"));
116+
posixLib.addIncludePath(copyFiles.getDirectory());
117+
118+
posixLib.addCSourceFiles(.{
119+
.files = &.{
120+
"src/pcre2posix.c",
121+
},
122+
});
123+
124+
b.installArtifact(posixLib);
125+
126+
pcre2test.linkLibrary(posixLib);
127+
}
128+
129+
130+
// pcre2test (again)
131+
132+
pcre2test.defineCMacro("HAVE_CONFIG_H", null);
133+
pcre2test.defineCMacro("HAVE_MEMMOVE", null);
134+
pcre2test.defineCMacro("HAVE_UNISTD_H", null);
135+
pcre2test.defineCMacro("HAVE_STRERROR", null);
136+
pcre2test.defineCMacro("SUPPORT_UNICODE", null);
137+
pcre2test.defineCMacro(b.fmt("SUPPORT_PCRE2_{s}", .{@tagName(codeUnitWidth)}), null);
138+
if (linkage == .static) {
139+
pcre2test.defineCMacro("PCRE2_STATIC", null);
140+
}
141+
142+
pcre2test.addIncludePath(b.path("src"));
143+
pcre2test.addIncludePath(copyFiles.getDirectory());
144+
145+
pcre2test.addCSourceFile(.{
146+
.file = b.path("src/pcre2test.c"),
147+
});
148+
149+
pcre2test.linkLibC();
150+
pcre2test.linkLibrary(lib);
151+
152+
b.installArtifact(pcre2test);
84153
}

0 commit comments

Comments
 (0)