Skip to content

Commit 0ed421c

Browse files
NWilsonzaucy
andauthored
Add Bazel build to CI (#623)
Add Bazel to CI using Bazelisk from the GitHub test runners. Fix many things in the Bazel build file... and also add basic testing which executes pcre2test using RunTest. --------- Co-authored-by: zaucy <zekewarren@gmail.com>
1 parent 4a268c9 commit 0ed421c

File tree

6 files changed

+130
-14
lines changed

6 files changed

+130
-14
lines changed

.bazelrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/workflows/dev.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ jobs:
210210
steps:
211211
- name: Setup
212212
run: |
213-
sudo apt-get update
214-
sudo apt-get install -y valgrind
213+
sudo apt-get -qq update
214+
sudo apt-get -qq install -y valgrind
215215
216216
- name: Checkout
217217
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -274,6 +274,27 @@ jobs:
274274
- name: Test
275275
run: cd build && ctest -j3 --output-on-failure
276276

277+
bazel:
278+
# Tests with: Bazel build system
279+
name: Bazel
280+
strategy:
281+
fail-fast: false
282+
matrix:
283+
os: ["ubuntu-latest", "windows-latest"]
284+
runs-on: ${{ matrix.os }}
285+
if: github.event_name != 'pull_request'
286+
steps:
287+
- name: Checkout
288+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
289+
with:
290+
submodules: true
291+
292+
- name: Build
293+
run: bazelisk build //... --enable_runfiles --incompatible_strict_action_env
294+
295+
- name: Test
296+
run: bazelisk test //... --enable_runfiles --incompatible_strict_action_env --test_output=all
297+
277298
heron:
278299
# Job to verify that the tasks performed by PrepareRelease have been done. It is
279300
# the committer's responsibility (currently) to run PrepareRelease themselves when

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ src/pcre2_chartables.c
9696
src/stamp-h1
9797

9898
/bazel-*
99+
*.bazel.lock
99100

100101
zig-out/
101102
zig-cache/

BUILD.bazel

Lines changed: 103 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
21
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
2+
load("@bazel_skylib//rules:native_binary.bzl", "native_test")
3+
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
34

45
copy_file(
56
name = "config_h_generic",
@@ -36,6 +37,7 @@ cc_library(
3637
"src/pcre2_error.c",
3738
"src/pcre2_extuni.c",
3839
"src/pcre2_find_bracket.c",
40+
"src/pcre2_jit_compile.c",
3941
"src/pcre2_maketables.c",
4042
"src/pcre2_match.c",
4143
"src/pcre2_match_data.c",
@@ -53,24 +55,118 @@ cc_library(
5355
"src/pcre2_valid_utf.c",
5456
"src/pcre2_xclass.c",
5557
":pcre2_chartables_c",
56-
],
57-
hdrs = glob(["src/*.h"]) + [
58+
"src/pcre2_compile.h",
59+
"src/pcre2_internal.h",
60+
"src/pcre2_intmodedep.h",
61+
"src/pcre2_ucp.h",
62+
"src/pcre2_util.h",
5863
":config_h_generic",
64+
],
65+
textual_hdrs = [
66+
"src/pcre2_jit_match.c",
67+
"src/pcre2_jit_misc.c",
68+
"src/pcre2_ucptables.c",
69+
],
70+
hdrs = [
5971
":pcre2_h_generic",
6072
],
61-
defines = [
73+
local_defines = [
6274
"HAVE_CONFIG_H",
75+
"HAVE_MEMMOVE",
6376
"PCRE2_CODE_UNIT_WIDTH=8",
6477
"PCRE2_STATIC",
78+
"SUPPORT_UNICODE",
6579
],
6680
includes = ["src"],
6781
strip_include_prefix = "src",
6882
visibility = ["//visibility:public"],
6983
)
7084

71-
cc_binary(
72-
name = "pcre2demo",
73-
srcs = ["src/pcre2demo.c"],
85+
cc_library(
86+
name = "pcre2-posix",
87+
srcs = [
88+
"src/pcre2posix.c",
89+
":config_h_generic",
90+
],
91+
hdrs = [
92+
"src/pcre2posix.h",
93+
],
94+
local_defines = [
95+
"HAVE_CONFIG_H",
96+
"HAVE_MEMMOVE",
97+
"PCRE2_CODE_UNIT_WIDTH=8",
98+
"PCRE2_STATIC",
99+
"SUPPORT_UNICODE",
100+
],
101+
includes = ["src"],
102+
strip_include_prefix = "src",
74103
visibility = ["//visibility:public"],
75104
deps = [":pcre2"],
76105
)
106+
107+
# Totally weird issue in Bazel. It won't let you #include any files unless they
108+
# are declared to the build system. OK, fair enough. But - for a cc_binary it
109+
# uses the file extension to determine whether it's a header or a compilation
110+
# unit. But... we have several .c files which are #included, rather than treated
111+
# as a compilation unit.
112+
#
113+
# For cc_library() above, we can overcome this with textual_hdrs. But that
114+
# doesn't work for cc_binary(). Here's our workaround.
115+
#
116+
# https://github.com/bazelbuild/bazel/issues/680
117+
cc_library(
118+
name = "pcre2test_dotc_headers",
119+
hdrs = [
120+
"src/pcre2_chkdint.c",
121+
"src/pcre2_printint.c",
122+
"src/pcre2_tables.c",
123+
"src/pcre2_ucd.c",
124+
"src/pcre2_valid_utf.c",
125+
],
126+
strip_include_prefix = "src",
127+
visibility = ["//visibility:private"],
128+
)
129+
130+
cc_binary(
131+
name = "pcre2test",
132+
srcs = [
133+
"src/pcre2test.c",
134+
":config_h_generic",
135+
],
136+
local_defines = [
137+
"HAVE_CONFIG_H",
138+
"HAVE_MEMMOVE",
139+
"HAVE_STRERROR",
140+
"PCRE2_STATIC",
141+
"SUPPORT_UNICODE",
142+
"SUPPORT_PCRE2_8",
143+
] + select({
144+
"@platforms//os:windows": [],
145+
"//conditions:default": ["HAVE_UNISTD_H"],
146+
}),
147+
linkopts = select({
148+
"@platforms//os:windows": ["-STACK:2500000"],
149+
"//conditions:default": [],
150+
}),
151+
visibility = ["//visibility:public"],
152+
deps = [":pcre2test_dotc_headers", ":pcre2", ":pcre2-posix"],
153+
)
154+
155+
filegroup(
156+
name = "testdata",
157+
srcs = glob(["testdata/*"]),
158+
)
159+
160+
native_test(
161+
name = "pcre2_test",
162+
src = select({
163+
"@platforms//os:windows": "RunTest.bat",
164+
"//conditions:default": "RunTest",
165+
}),
166+
out = select({
167+
"@platforms//os:windows": "RunTest.bat",
168+
"//conditions:default": "RunTest",
169+
}),
170+
data = [":pcre2test", ":testdata"],
171+
size = "small",
172+
)

MODULE.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module(
22
name = "pcre2",
3-
version = "10.40",
3+
version = "10.45-DEV",
44
compatibility_level = 1,
55
)
66

77
bazel_dep(name = "rules_cc", version = "0.0.1")
88
bazel_dep(name = "bazel_skylib", version = "1.2.1")
9+
bazel_dep(name = "platforms", version = "0.0.4")

RunTest.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ if exist ..\testdata\ set srcdir=..)
3939
if [%srcdir%]==[] (
4040
if exist ..\..\testdata\ set srcdir=..\..)
4141
if NOT exist %srcdir%\testdata\ (
42-
Error: echo distribution testdata folder not found!
42+
echo Error: distribution testdata folder not found!
4343
call :conferror
4444
exit /b 1
4545
goto :eof

0 commit comments

Comments
 (0)