Skip to content

Commit 5363623

Browse files
committed
Add PCRE2 support
This is still work in progress. Work on oniguruma (https://github.com/kkos/oniguruma) has been discontinued so we need to find some other regex implementation. To build and test: ./configure --with-oniguruma=no --with-pcre2 make make check ./jq --run-tests < ./tests/onig.test ./jq --run-tests < ./tests/pcre2.test Known TODOs: - Proper configure options (skip vendor for pcre2?) - What about libjq usage? dont builtin and require libpcre2? (seems to be what debian does already for libonig) - pcre2 in ci/release workflows - Update Dockerfile - Update docs Build status: - macos: Switch to native arm64/arm64 build hosts to simplify build a bit - windows: Build fails to find libs and headers installed by pcre2-devel, no idea why, but pcre2-config seem to run - linux native: Test fails due to old version of pcre2 (see below) - linux cross: Maybe switch to docker build --platform Good references: - https://github.com/PCRE2Project/pcre2/blob/master/src/pcre2demo.c Pre pcre2_next_match usage: - https://github.com/PCRE2Project/pcre2/blob/eb3bd3cf1418cb1a0eabf984b0b1e80b6bdd9314~1/src/pcre2demo.c (pre pcre2_next_match usage) - pcre2test cli tools is a good Playaround for pcre2 Notes: ".+?\\b" test in onig.test seems to be behaves differently depending on pcre2 version. I suspect this fix in 10.43: PCRE2Project/pcre2@0a55280 I noticed a clang -fsanitize=memory use-of-uninitialized-valu issue but it seems to go awa with pcre2 master Related to #3313
1 parent cff4e00 commit 5363623

File tree

9 files changed

+384
-25
lines changed

9 files changed

+384
-25
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,16 @@ jobs:
8181
- name: Install packages
8282
run: |
8383
sudo apt-get update
84-
sudo apt-get install -y automake autoconf libtool crossbuild-essential-${{ matrix.arch }}
84+
# crossbuild libpcre2?
85+
sudo apt-get install -y automake autoconf libtool libpcre2-dev libpcre2-8-0 crossbuild-essential-${{ matrix.arch }}
8586
- name: Build
8687
run: |
8788
autoreconf -i
8889
./configure \
8990
--host=${{ matrix.CC }} \
9091
--disable-docs \
91-
--with-oniguruma=builtin \
92+
--with-oniguruma=no \
93+
--with-pcre2 \
9294
--enable-static \
9395
--enable-all-static \
9496
CFLAGS="-O2 -pthread -fstack-protector-all"
@@ -127,10 +129,10 @@ jobs:
127129
- arm64
128130
include:
129131
- arch: amd64
130-
target: x86_64-apple-darwin
132+
runs_on: macos-15-intel
131133
- arch: arm64
132-
target: arm64-apple-darwin
133-
runs-on: macos-14
134+
runs_on: macos-15
135+
runs-on: ${{ matrix.runs_on }}
134136
env:
135137
LDFLAGS: -dead_strip
136138
SUFFIX: macos-${{ matrix.arch }}
@@ -143,17 +145,14 @@ jobs:
143145
run: |
144146
# brew update sometimes fails with "Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask failed!"
145147
brew update || brew update-reset
146-
brew install autoconf automake libtool
147-
- name: Set CC
148-
run: |
149-
echo "CC=clang -target ${{ matrix.target }}$(uname -r)" >> "$GITHUB_ENV"
148+
brew install autoconf automake libtool pcre2
150149
- name: Build
151150
run: |
152151
autoreconf -i
153152
./configure \
154-
--host="${{ matrix.target }}$(uname -r)" \
155153
--disable-docs \
156-
--with-oniguruma=builtin \
154+
--with-oniguruma=no \
155+
--with-pcre2 \
157156
--disable-shared \
158157
--enable-static \
159158
--enable-all-static \
@@ -226,14 +225,17 @@ jobs:
226225
autoconf
227226
automake
228227
libtool
228+
pcre2
229+
pcre2-devel
229230
pacboy: >-
230231
toolchain:p
231232
- name: Build
232233
run: |
233234
autoreconf -i
234235
./configure \
235236
--disable-docs \
236-
--with-oniguruma=builtin \
237+
--with-oniguruma=no \
238+
--with-pcre2 \
237239
--disable-shared \
238240
--enable-static \
239241
--enable-all-static \
@@ -272,13 +274,14 @@ jobs:
272274
- name: Install packages
273275
run: |
274276
sudo apt-get update -qq
275-
sudo apt-get install -y automake autoconf
277+
sudo apt-get install -y automake autoconf libpcre2-dev libpcre2-8-0
276278
- name: Create dist
277279
run: |
278280
autoreconf -i
279281
./configure \
280282
--disable-docs \
281-
--with-oniguruma=builtin
283+
--with-oniguruma=no \
284+
--with-pcre2 \
282285
make distcheck
283286
make dist dist-zip
284287
git diff --exit-code

.github/workflows/scanbuild.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ jobs:
1616
- name: Install packages
1717
run: |
1818
sudo apt-get update -qq
19-
sudo apt-get install -y automake autoconf gdb valgrind clang clang-tools
19+
sudo apt-get install -y automake autoconf gdb valgrind clang clang-tools libpcre2-dev libpcre2-8-0
2020
echo "CC=clang" >> "$GITHUB_ENV"
2121
- name: Build
2222
run: |
2323
autoreconf -i
24-
./configure --enable-valgrind CFLAGS="-g -O0"
24+
./configure --enable-valgrind --with-oniguruma=no --with-pcre2 CFLAGS="-g -O0"
2525
scan-build --keep-going --exclude vendor/ make -j"$(nproc)"
2626
- name: Test
2727
run: |

.github/workflows/valgrind.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ jobs:
1616
- name: Install packages
1717
run: |
1818
sudo apt-get update
19-
sudo apt-get install -y automake autoconf libtool valgrind
19+
sudo apt-get install -y automake autoconf libtool libpcre2-dev libpcre2-8-0 valgrind
2020
- name: Build
2121
run: |
2222
autoreconf -i
2323
./configure \
2424
--disable-docs \
2525
--enable-valgrind \
26-
--with-oniguruma=builtin
26+
--with-oniguruma=no \
27+
--with-pcre2
2728
make -j"$(nproc)"
2829
file ./jq
2930
- name: Test

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ RUN apt-get update \
1010
build-essential \
1111
autoconf \
1212
libtool \
13+
libpcre2-dev \
14+
libpcre2-8-0 \
1315
git \
1416
&& apt-get clean \
1517
&& rm -rf /var/lib/apt/lists/*
@@ -19,7 +21,8 @@ COPY . /app
1921
RUN autoreconf -i \
2022
&& ./configure \
2123
--disable-docs \
22-
--with-oniguruma=builtin \
24+
--with-oniguruma=no \
25+
--with-pcre2 \
2326
--enable-static \
2427
--enable-all-static \
2528
--prefix=/usr/local \

Makefile.am

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ AM_YFLAGS = --warnings=all -Wno-yacc -d
5656
lib_LTLIBRARIES = libjq.la
5757
libjq_la_SOURCES = ${LIBJQ_SRC}
5858
libjq_la_LIBADD = -lm
59-
libjq_la_LDFLAGS = $(onig_LDFLAGS) -export-symbols-regex '^j[qv]_' -version-info 1:4:0
59+
libjq_la_LDFLAGS = $(onig_LDFLAGS) $(pcre2_LDFLAGS) -export-symbols-regex '^j[qv]_' -version-info 1:4:0
6060

6161
if WIN32
6262
libjq_la_LIBADD += -lshlwapi
@@ -198,11 +198,17 @@ SUBDIRS = vendor/oniguruma
198198
endif
199199

200200
AM_CFLAGS += $(onig_CFLAGS)
201+
AM_CFLAGS += $(pcre2_CFLAGS)
201202

202203
if WITH_ONIGURUMA
203204
TESTS += tests/onigtest tests/manonigtest
204205
endif
205206

207+
if WITH_PCRE2
208+
TESTS += tests/onigtest tests/manonigtest
209+
TESTS += tests/pcre2test
210+
endif
211+
206212
### Packaging
207213

208214
install-binaries: $(BUILT_SOURCES)
@@ -230,7 +236,7 @@ EXTRA_DIST = $(DOC_FILES) $(man_MANS) $(TESTS) $(TEST_LOG_COMPILER) \
230236
tests/onig.supp tests/local.supp \
231237
tests/setup tests/torture/input0.json \
232238
tests/optional.test tests/man.test tests/manonig.test \
233-
tests/jq.test tests/onig.test tests/base64.test tests/uri.test \
239+
tests/jq.test tests/onig.test tests/pcre2.test tests/base64.test tests/uri.test \
234240
tests/jq-f-test.sh \
235241
tests/no-main-program.jq tests/yes-main-program.jq
236242

configure.ac

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,44 @@ AC_SUBST(onig_LDFLAGS)
283283
AM_CONDITIONAL([BUILD_ONIGURUMA], [test "x$build_oniguruma" = xyes])
284284
AM_CONDITIONAL([WITH_ONIGURUMA], [test "x$with_oniguruma" != xno])
285285

286+
dnl PCRE2
287+
dnl TODO: proper check
288+
AC_ARG_WITH([pcre2],
289+
[AS_HELP_STRING([--with-pcre2], [Use PCRE2 library])],
290+
[with_pcre2=yes],
291+
[with_pcre2=no])
292+
293+
if test "$with_pcre2" = yes; then
294+
AC_CHECK_PROG(PCRE2_CONFIG, pcre2-config, pcre2-config)
295+
AC_ARG_WITH(pcre2-config,
296+
AS_HELP_STRING([--with-pcre2-config=PATH],
297+
[Location of PCRE2 pcre2-config (auto)]),
298+
[pcre2_config="$withval"],
299+
[pcre2_config=""])
300+
301+
if test "x$pcre2_config" != "x" ; then
302+
AC_MSG_CHECKING(for $pcre2_config)
303+
304+
if test -f $pcre2_config ; then
305+
PCRE2_CONFIG=$pcre2_config
306+
AC_MSG_RESULT(yes)
307+
else
308+
AC_MSG_RESULT(no - searching PATH)
309+
fi
310+
fi
311+
if test "x$PCRE2_CONFIG" = "x"; then
312+
AC_CHECK_PROGS(PCRE2_CONFIG, pcre2-config)
313+
fi
314+
pcre2_CFLAGS=`$PCRE2_CONFIG --cflags`
315+
pcre2_LDFLAGS=`$PCRE2_CONFIG --libs8`
316+
AC_SUBST(pcre2_CFLAGS)
317+
AC_SUBST(pcre2_LDFLAGS)
318+
dnl condtional?
319+
AC_DEFINE([HAVE_PCRE2],1,[Define to 1 if the system includes pcre2])
320+
fi
321+
322+
AM_CONDITIONAL([WITH_PCRE2], [test "x$with_pcre2" != xno])
323+
286324
AC_CONFIG_MACRO_DIRS([config/m4 m4])
287325
AC_CONFIG_FILES([Makefile libjq.pc])
288326
AC_OUTPUT
289-

0 commit comments

Comments
 (0)