Skip to content

Commit 515ab43

Browse files
committed
Use Homebrew include directory for pcre2.h on macOS if necessary
When pcre2 is installed via Homebrew on macOS, the header file pcre2.h is typically located in the Homebrew include directory. This leads to build errors since the compiler does not use this directory by default. Therefore, the Homebrew include directory is now added as include directory for the compiler if it contains pcre2.h. In addition, the CI has been extended to check the build on macOS.
1 parent 9d8fae2 commit 515ab43

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

.github/workflows/config.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,33 @@ jobs:
4343
make test TESTS="--show-diff -d apc.serializer=default -d opcache.enable_cli=1 tests"
4444
make test TESTS="--show-diff -d apc.serializer=php -d opcache.enable_cli=1 tests"
4545
46+
# Build and test on macOS (Arm64)
47+
macos:
48+
strategy:
49+
matrix:
50+
version: ["latest"]
51+
os: [macos-latest]
52+
runs-on: ${{matrix.os}}
53+
steps:
54+
- name: Checkout apcu
55+
uses: actions/checkout@v6
56+
- name: Setup PHP
57+
uses: shivammathur/setup-php@v2
58+
with:
59+
php-version: ${{matrix.version}}
60+
- name: phpize
61+
run: phpize
62+
- name: configure
63+
run: ./configure --enable-apcu-debug
64+
- name: make
65+
run: make
66+
- name: test
67+
run: |
68+
make test TESTS="--show-diff -d apc.serializer=default tests"
69+
make test TESTS="--show-diff -d apc.serializer=php tests"
70+
make test TESTS="--show-diff -d apc.serializer=default -d opcache.enable_cli=1 tests"
71+
make test TESTS="--show-diff -d apc.serializer=php -d opcache.enable_cli=1 tests"
72+
4673
# Build and test on Windows
4774
windows:
4875
strategy:

config.m4

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,23 @@ if test "$PHP_APCU" != "no"; then
201201

202202
AC_CHECK_FUNCS(sigaction)
203203

204+
dnl Ensure that the compiler can include pcre2.h if it was installed via Homebrew on macOS
205+
dnl See https://github.com/krakjoe/apcu/issues/572
206+
AC_CHECK_HEADER([pcre2.h], [apcu_pcre2_found=yes], [apcu_pcre2_found=no], [#define PCRE2_CODE_UNIT_WIDTH 8])
207+
if test "$apcu_pcre2_found" = "no"; then
208+
AC_CHECK_PROG([apcu_brew], [brew], [brew])
209+
if test -n "$apcu_brew"; then
210+
apcu_homebrew_include_dir="$($apcu_brew --prefix 2> /dev/null)/include"
211+
AC_MSG_CHECKING([for pcre2.h in homebrew include directory $apcu_homebrew_include_dir])
212+
if test -f "$apcu_homebrew_include_dir/pcre2.h"; then
213+
PHP_ADD_INCLUDE([$apcu_homebrew_include_dir])
214+
AC_MSG_RESULT([yes])
215+
else
216+
AC_MSG_RESULT([no])
217+
fi
218+
fi
219+
fi
220+
204221
for i in -Wall -Wextra -Wno-clobbered -Wno-unused-parameter; do
205222
AX_CHECK_COMPILE_FLAG([$i], [APCU_CFLAGS="$APCU_CFLAGS $i"])
206223
done

package.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
is no longer computed, as the hash is not needed for the unserialization. This significantly
6262
improves performance when saving larger objects or arrays by using a serializer (tested with
6363
the PHP serializer, which is currently the default).
64+
- Fix build on macOS. If pcre2 was installed via Homebrew, the header file pcre2.h wasn't found
65+
during the build process.
6466

6567
Internal changes:
6668
- Added stress test to CI. This test will hopefully help to detect unexpected behavior
@@ -70,6 +72,7 @@
7072
- The pipeline now uses php/php-windows-builder for building and testing on Windows.
7173
- Fix potential compiler warnings by using proper format specifiers.
7274
- Transition to actions/checkout@v6 because of the Node.js 20 deprecation.
75+
- Added tests on macOS to the CI.
7376
</notes>
7477
<contents>
7578
<dir name="/">

0 commit comments

Comments
 (0)