PHPC-2647, PHPC-2715: Fix all possible build configurations (standalone vs. in-tree, in-source vs. out-of-source)#2014
Conversation
Use PHP_EXT_BUILDDIR as the base for all AC_CONFIG_FILES paths so that generated config headers (common-config.h, bson/config.h, mongoc-config.h, etc.) are written to the extension's build directory rather than its source directory, keeping the source tree clean for out-of-source builds. Add PHP_MONGODB_ADD_BUILD_INCLUDE to php_mongodb.m4 as the counterpart to PHP_MONGODB_ADD_INCLUDE: it adds a compiler include path relative to the extension build directory (PHP_EXT_BUILDDIR), which is needed so the compiler can find the generated config headers regardless of whether the build is in-source or out-of-source. Call PHP_MONGODB_ADD_BUILD_INCLUDE for each directory that receives a generated header via AC_CONFIG_FILES: common/src, libbson/src/bson, libmongoc/src/mongoc, and conditionally zlib-1.3.1 and libmongocrypt/src.
ae26918 to
9c8e0ab
Compare
GromNaN
left a comment
There was a problem hiding this comment.
Should you target the branch 2.3?
Correct, fixed. |
f68c0dc to
9941bb5
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the extension’s Autotools configuration to correctly place and include generated config headers across all four supported build layouts (standalone vs. in-tree, in-source vs. out-of-source), and expands CI coverage to exercise the missing in-tree out-of-source layout.
Changes:
- Added a new Autotools helper macro to add include paths rooted at the extension build directory (for generated headers).
- Switched
AC_CONFIG_FILESoutputs inconfig.m4to target the extension build directory and mirrored that with build-directory include paths. - Extended the GitHub Actions in-tree build job to run both in-source and out-of-source PHP builds.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| scripts/autotools/m4/php_mongodb.m4 | Adds PHP_MONGODB_ADD_BUILD_INCLUDE to register include paths for generated headers in the build tree. |
| config.m4 | Writes generated config headers into the extension build directory and adds corresponding build include paths. |
| .github/workflows/tests.yml | Renames/extends the in-tree static PHP build job with a matrix to cover out-of-source builds. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
PHPC-2647, PHPC-2715
This PR revives the original goal of PHPC-2647 — keeping generated config headers (
common-config.h,bson/config.h,mongoc-config.h, etc.) out of the source tree during out-of-source builds — while correctly handling all four build layouts the extension supports. It supersedes the partial fixes in PHPC-2714 and PHPC-2715.The four build layouts
1. phpize — in-source
phpizeis run in the source directory, and./configureis invoked from that same directory. This is the standard workflow for building the extension standalone.PHP_EXT_BUILDDIR(mongodb)=.(resolves to/path/to/mongo-php-driver);PHP_EXT_SRCDIR(mongodb)=/path/to/mongo-php-driver2. phpize — out-of-source
phpizeis run in the source directory to generateconfigure, thenconfigureis invoked from a separate build directory. This is the layout used by RHEL/RPM packaging and any packager that wants a clean source tree.PHP_EXT_BUILDDIR(mongodb)=.(resolves to/tmp/build);PHP_EXT_SRCDIR(mongodb)=/path/to/mongo-php-driver3. PHP in-tree — source = build
The extension is compiled statically into PHP (used by projects like
StaticPHP). PHP's
buildconfdiscovers the extension's
config.m4via a glob overext/*/config.m4, and./configureis run from the PHP source directory, which doubles as the builddirectory.
PHP_EXT_BUILDDIR(mongodb)=ext/mongodb(resolves to/path/to/php-src/ext/mongodb);PHP_EXT_SRCDIR(mongodb)=/path/to/php-src/ext/mongodb4. PHP in-tree — source ≠ build
Same as (3) but PHP itself is configured with a dedicated build directory.
PHP_EXT_BUILDDIR(mongodb)=ext/mongodb(resolves to/tmp/php-build/ext/mongodb);PHP_EXT_SRCDIR(mongodb)=/path/to/php-src/ext/mongodbHistory of the problem
PHPC-2647 (
a2bb085) changedAC_CONFIG_FILESfrom absolute source-treepaths to bare relative paths (e.g.
src/libmongoc/src/common/src/common-config.h).Relative paths in
AC_CONFIG_FILESare resolved relative to the directorywhere
./configurewas invoked:/source/source/src/...— in source tree/build/build/src/...— in build tree ✓/php-src/php-src/src/libmongoc/...— wrong location ✗/php-build/php-build/src/libmongoc/...— wrong location ✗For in-tree PHP builds (layouts 3 and 4), the configure invocation directory is
the PHP root, so bare relative paths like
src/libmongoc/...land at/php-root/src/libmongoc/...instead of underext/mongodb/.PHPC-2714 (
79b6416) fixed layouts 3 and 4 by using${php_mongodb_ext_builddir}/src/...wherephp_mongodb_ext_builddir = PHP_EXT_BUILDDIR(mongodb). That macro expands toext/mongodbfor in-tree builds and.for phpize builds, so the headers landin the right place relative to the build root in all cases. However, the fix
added build-tree include paths via
$abs_builddir/$php_mongodb_ext_builddir/...,which failed for phpize out-of-source builds (layout 2) due to how
abs_builddirinteracts with relative
PHP_EXT_BUILDDIRexpansion. The failure was not caughtbecause no CI job tested layout 2 at the time.
PHPC-2715 (
8f28ee4) added a CI job for out-of-source builds and fixed thefailure by reverting
AC_CONFIG_FILESto usePHP_EXT_SRCDIR(mongodb)(theabsolute source-tree path). This restores the pre-PHPC-2647 behaviour: headers
are always written to the source tree. The include paths, however, continued
to point into the build tree:
AC_CONFIG_FILESwrites to/source/src/...(srcdir)/source/src/...(builddir = srcdir)/source/src/...(srcdir)/build/src/...(builddir ≠ srcdir)/php-src/ext/mongodb/src/.../php-src/ext/mongodb/src/.../php-src/ext/mongodb/src/.../php-build/ext/mongodb/src/...PHPC-2715 works only when source dir = build dir (layouts 1 and 3), which
happened to cover all tested scenarios. Layouts 2 and 4 remained broken.
Additionally, using
PHP_EXT_SRCDIRalways writes generated files into thesource tree, abandoning the PHPC-2647 goal.
What this PR does
Three changes:
1. Add
PHP_MONGODB_ADD_BUILD_INCLUDEtoscripts/autotools/m4/php_mongodb.m4A new macro, parallel to the existing
PHP_MONGODB_ADD_INCLUDE(which usesPHP_EXT_SRCDIR) andPHP_MONGODB_ADD_BUILD_DIR(which usesPHP_EXT_BUILDDIR):PHP_ADD_INCLUDEcallsPHP_EXPAND_PATHinternally, which resolves a path toabsolute using
cd $path && pwd. This probe requires the target directory toexist, but the build subdirectories (e.g.
src/libmongoc/src/libbson/src/) areonly created by
PHP_ADD_BUILD_DIRlater inAC_CONFIG_COMMANDS_PRE. Passingthe full relative path (e.g.
./src/libmongoc/src/libbson/src/) would causePHP_EXPAND_PATHto silently discard it when thecdfails.To avoid this, we first expand only
PHP_EXT_BUILDDIR(mongodb)— which is.or
ext/mongodb, both of which exist at configure time — to get the absolutebuild root. We then append the subdirectory and pass the resulting absolute path
to
PHP_ADD_INCLUDE.PHP_EXPAND_PATHshort-circuits for paths starting with/and uses them as-is, so the subdirectory is not required to exist yet.2. Use
PHP_EXT_BUILDDIRforAC_CONFIG_FILESandPHP_MONGODB_ADD_BUILD_INCLUDEfor the compiler include paths inconfig.m4AC_CONFIG_FILESpaths now use${mongodb_builddir}wheremongodb_builddir = PHP_EXT_BUILDDIR(mongodb). APHP_MONGODB_ADD_BUILD_INCLUDEcall is added alongside each group of
AC_CONFIG_FILESentries so the compilerinclude paths mirror the write locations:
AC_CONFIG_FILESwrites toADD_BUILD_INCLUDEadds./src/...→/source/src/...-I/source/src/..../src/...→/build/src/...-I/build/src/...ext/mongodb/src/...→/php-src/ext/mongodb/src/...-I/php-src/ext/mongodb/src/...ext/mongodb/src/...→/php-build/ext/mongodb/src/...-I/php-build/ext/mongodb/src/...Write location and include path always agree. The source tree is only written to
when the build directory is the same as the source directory, which is
unavoidable by definition.
3. Extend
test-in-tree-buildin.github/workflows/tests.ymlwith anout-of-sourcemodeThe existing job (formerly
test-static-php-build, added in PHPC-2714) onlyran PHP's configure from the PHP source directory (layout 3). A
modematrix(
from-source,out-of-source) is added. Theout-of-sourcemode creates aseparate
/tmp/php-builddirectory and runs configure and make from there,exercising layout 4.
CI coverage
The
test-in-tree-buildjob (renamed fromtest-static-php-build, added in PHPC-2714) covers layouts 3 and 4 via amodematrix (from-sourceandout-of-source).The
test-out-of-source-buildjob (added in PHPC-2715) covers layout 2.Layout 1 is covered by the standard
linux-testjobs.