Skip to content

Commit b848d58

Browse files
Merge v2.3 into v2.x (#2006)
2 parents 0c3187f + 79b6416 commit b848d58

2 files changed

Lines changed: 91 additions & 15 deletions

File tree

.github/workflows/tests.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,63 @@ jobs:
235235
files: test-results.xml
236236
flags: "${{ env.SERVER_VERSION }}-server"
237237
token: ${{ secrets.CODECOV_TOKEN }}
238+
239+
# Verifies that the extension can be compiled statically into PHP (i.e. with
240+
# --enable-mongodb instead of --enable-mongodb=shared), as done by projects
241+
# like StaticPHP. This exercises the PHP in-tree build path where configure
242+
# is invoked from the PHP source root rather than the extension directory.
243+
test-static-php-build:
244+
name: "Static PHP Build"
245+
runs-on: "ubuntu-latest"
246+
env:
247+
# Update this when cutting a new PHP 8.3 patch release
248+
PHP_VERSION: "8.3.21"
249+
250+
steps:
251+
- name: "Checkout"
252+
uses: "actions/checkout@v6"
253+
with:
254+
submodules: true
255+
path: "mongo-php-driver"
256+
257+
- name: "Install build dependencies"
258+
run: |
259+
sudo apt-get update -q
260+
sudo apt-get install -y \
261+
autoconf \
262+
bison \
263+
libsqlite3-dev \
264+
libssl-dev \
265+
libxml2-dev \
266+
pkg-config \
267+
re2c
268+
269+
- name: "Download PHP ${{ env.PHP_VERSION }} source"
270+
run: |
271+
curl -fsSL "https://www.php.net/distributions/php-${{ env.PHP_VERSION }}.tar.gz" | tar -xz
272+
mv "php-${{ env.PHP_VERSION }}" php-src
273+
274+
- name: "Link extension into PHP source tree"
275+
run: ln -s "$GITHUB_WORKSPACE/mongo-php-driver" "$GITHUB_WORKSPACE/php-src/ext/mongodb"
276+
277+
- name: "Generate PHP build scripts"
278+
run: cd "$GITHUB_WORKSPACE/php-src" && ./buildconf --force
279+
280+
# Note: --with-openssl is needed for the bundled libmongoc's TLS support.
281+
- name: "Configure PHP with MongoDB extension (static)"
282+
run: |
283+
cd "$GITHUB_WORKSPACE/php-src"
284+
./configure \
285+
--enable-debug \
286+
--enable-cli \
287+
--enable-mongodb \
288+
--enable-mongodb-developer-flags \
289+
--with-openssl
290+
291+
- name: "Build PHP"
292+
run: cd "$GITHUB_WORKSPACE/php-src" && make -j$(nproc)
293+
294+
- name: "Verify MongoDB extension is compiled in"
295+
run: |
296+
"$GITHUB_WORKSPACE/php-src/sapi/cli/php" -m | grep -ix mongodb
297+
"$GITHUB_WORKSPACE/php-src/sapi/cli/php" --ri mongodb

config.m4

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,25 @@ if test "$PHP_MONGODB" != "no"; then
374374
PHP_MONGODB_ADD_SOURCES([src/libmongoc/src/libbson/src/jsonsl/], $PHP_MONGODB_JSONSL_SOURCES, $PHP_MONGODB_BUNDLED_CFLAGS)
375375
PHP_MONGODB_ADD_SOURCES([src/libmongoc/src/libmongoc/src/mongoc/], $PHP_MONGODB_MONGOC_SOURCES, $PHP_MONGODB_BUNDLED_CFLAGS)
376376

377-
dnl Add the build directories as include paths to some generated files
378-
PHP_ADD_INCLUDE([$PWD/src/libmongoc/src/common/src])
379-
PHP_ADD_INCLUDE([$PWD/src/libmongoc/src/libbson/src])
380-
PHP_ADD_INCLUDE([$PWD/src/libmongoc/src/libmongoc/src])
377+
dnl TODO: Use $ext_builddir/$ext_srcdir once this block can move after PHP_NEW_EXTENSION.
378+
dnl $ext_builddir and $ext_srcdir are set by PHP_NEW_EXTENSION, but PHP_ADD_INCLUDE
379+
dnl and PHP_MONGODB_ADD_SOURCES calls must precede PHP_NEW_EXTENSION, so the whole
380+
dnl block cannot be deferred. PHP_EXT_BUILDDIR/PHP_EXT_SRCDIR are M4 macros that
381+
dnl are always available and provide equivalent values without that constraint.
382+
dnl
383+
dnl PHP_EXT_BUILDDIR expands to the extension's directory relative to the build
384+
dnl root: "ext/mongodb" for PHP in-tree builds, "." for phpize builds. Pairing
385+
dnl it with $abs_builddir (the absolute path to wherever configure was invoked)
386+
dnl produces the correct absolute path to the generated config headers regardless
387+
dnl of build layout. Using $PWD here breaks PHP in-tree builds because $PWD is
388+
dnl the PHP source/build root, not the extension's subdirectory within it.
389+
php_mongodb_ext_builddir=PHP_EXT_BUILDDIR(mongodb)
390+
391+
dnl Add the build directories as include paths so the compiler finds generated
392+
dnl config headers (common-config.h, bson/config.h, mongoc-config.h, etc.).
393+
PHP_ADD_INCLUDE([$abs_builddir/$php_mongodb_ext_builddir/src/libmongoc/src/common/src])
394+
PHP_ADD_INCLUDE([$abs_builddir/$php_mongodb_ext_builddir/src/libmongoc/src/libbson/src])
395+
PHP_ADD_INCLUDE([$abs_builddir/$php_mongodb_ext_builddir/src/libmongoc/src/libmongoc/src])
381396

382397
PHP_MONGODB_ADD_INCLUDE([src/libmongoc/src/common/src/])
383398
PHP_MONGODB_ADD_INCLUDE([src/libmongoc/src/uthash/])
@@ -399,16 +414,17 @@ if test "$PHP_MONGODB" != "no"; then
399414
PHP_MONGODB_ADD_BUILD_DIR([src/libmongoc/src/kms-message/src/])
400415
fi
401416

402-
dnl TODO: Use $ext_srcdir if we can move this after PHP_NEW_EXTENSION
403-
ac_config_dir=PHP_EXT_SRCDIR(mongodb)
404-
417+
dnl Write generated config headers into the extension's build directory
418+
dnl (${php_mongodb_ext_builddir}/... relative to the configure invocation directory).
419+
dnl For standalone out-of-source builds this stays in the build tree; for
420+
dnl PHP in-tree builds it lands under ext/mongodb/ rather than the PHP root.
405421
AC_CONFIG_FILES([
406-
src/libmongoc/src/common/src/common-config.h
407-
src/libmongoc/src/libbson/src/bson/config.h
408-
src/libmongoc/src/libbson/src/bson/version.h
409-
src/libmongoc/src/libmongoc/src/mongoc/mongoc-config.h
410-
src/libmongoc/src/libmongoc/src/mongoc/mongoc-config-private.h
411-
src/libmongoc/src/libmongoc/src/mongoc/mongoc-version.h
422+
${php_mongodb_ext_builddir}/src/libmongoc/src/common/src/common-config.h
423+
${php_mongodb_ext_builddir}/src/libmongoc/src/libbson/src/bson/config.h
424+
${php_mongodb_ext_builddir}/src/libmongoc/src/libbson/src/bson/version.h
425+
${php_mongodb_ext_builddir}/src/libmongoc/src/libmongoc/src/mongoc/mongoc-config.h
426+
${php_mongodb_ext_builddir}/src/libmongoc/src/libmongoc/src/mongoc/mongoc-config-private.h
427+
${php_mongodb_ext_builddir}/src/libmongoc/src/libmongoc/src/mongoc/mongoc-version.h
412428
])
413429

414430
if test "x$bundled_utf8proc" = "xyes"; then
@@ -423,7 +439,7 @@ if test "$PHP_MONGODB" != "no"; then
423439
PHP_MONGODB_ADD_SOURCES([src/libmongoc/src/zlib-1.3.1/], $PHP_MONGODB_ZLIB_SOURCES, $PHP_MONGODB_ZLIB_CFLAGS)
424440
PHP_MONGODB_ADD_INCLUDE([src/libmongoc/src/zlib-1.3.1/])
425441
PHP_MONGODB_ADD_BUILD_DIR([src/libmongoc/src/zlib-1.3.1/])
426-
AC_CONFIG_FILES([${ac_config_dir}/src/libmongoc/src/zlib-1.3.1/zconf.h])
442+
AC_CONFIG_FILES([${php_mongodb_ext_builddir}/src/libmongoc/src/zlib-1.3.1/zconf.h])
427443
fi
428444

429445
if test "$PHP_MONGODB_CLIENT_SIDE_ENCRYPTION" = "yes"; then
@@ -462,7 +478,7 @@ if test "$PHP_MONGODB" != "no"; then
462478
PHP_MONGODB_ADD_BUILD_DIR([src/libmongocrypt/kms-message/src/])
463479

464480
AC_CONFIG_FILES([
465-
${ac_config_dir}/src/libmongocrypt/src/mongocrypt-config.h
481+
${php_mongodb_ext_builddir}/src/libmongocrypt/src/mongocrypt-config.h
466482
])
467483
fi
468484
fi

0 commit comments

Comments
 (0)