Skip to content

[PHPC-2647] Out-of-source build: Don't necessarily generate flies in the source tree#1893

Open
vector-of-bool wants to merge 2 commits intomongodb:v2.xfrom
vector-of-bool:out-of-source-build.1
Open

[PHPC-2647] Out-of-source build: Don't necessarily generate flies in the source tree#1893
vector-of-bool wants to merge 2 commits intomongodb:v2.xfrom
vector-of-bool:out-of-source-build.1

Conversation

@vector-of-bool
Copy link

This changeset modifies an AC_CONFIG_FILES directive to configure some of mongoc's files using relative paths. IIUC, using relative paths (instead of absolute ones) will make it read the file relative to the configure script, but write the file with the same name relative to the $PWD of the configure execution. This allows the configure script to leave the source tree more pristine.

To support this, the directories that are (possibly) generated by AC_CONFIG_FILES needs to be added as #include search paths. (The search directories are added based on $PWD, which feels somewhat brittle (is there a better autotools/autoconf variable to be used here? I couldn't seem to make it work otherwise.).)

(I'm not sure if there is an existing relevant Jira ticket for out-of-source build support tasks, so I created PHPC-2647 for this.)

@vector-of-bool vector-of-bool requested a review from a team as a code owner October 30, 2025 22:24
@vector-of-bool vector-of-bool requested review from jmikola and removed request for a team October 30, 2025 22:24
When doing an out-of-source build, certain generated
headers are written into the build tree. The directories containing
these headers need to be added as #include search paths for the build
to succeed.
@alcaeus alcaeus force-pushed the out-of-source-build.1 branch from 5b36382 to d5197f7 Compare January 30, 2026 13:04
@alcaeus alcaeus requested review from alcaeus and removed request for jmikola January 30, 2026 13:05
@GromNaN GromNaN requested a review from Copilot January 30, 2026 13:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modifies the autoconf configuration to support out-of-source builds by changing how generated files are created. Instead of using absolute paths that write files into the source tree, it uses relative paths that write to the build directory.

Changes:

  • Changed AC_CONFIG_FILES to use relative paths instead of absolute paths based on ${ac_config_dir}
  • Added build directories as include paths using $PWD to ensure generated headers can be found

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@alcaeus
Copy link
Member

alcaeus commented Jan 30, 2026

Note: rebased to resolve conflicts.

I tested this by running phpize in the extension folder, then switching into scripts and running ../configure. Afterwards, I saw an src folder with the expected header files generated. From the scripts folder, I ran make -f ../Makefile, and was greeted by an error message:

make -f ../Makefile
/bin/sh /Users/alcaeus/Code/mongodb/mongo-php-driver/libtool --tag=CC --mode=compile cc -Isrc/libmongoc/src/common/src/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/common/src/ -I/opt/homebrew/Cellar/php@8.4/8.4.15/include/php -I/opt/homebrew/Cellar/php@8.4/8.4.15/include/php/main -I/opt/homebrew/Cellar/php@8.4/8.4.15/include/php/TSRM -I/opt/homebrew/Cellar/php@8.4/8.4.15/include/php/Zend -I/opt/homebrew/Cellar/php@8.4/8.4.15/include/php/ext -I/opt/homebrew/Cellar/php@8.4/8.4.15/include/php/ext/date/lib -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/common/src/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/uthash/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/libbson/src/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/libbson/src/jsonsl/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/libmongoc/src/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/utf8proc-2.8.0/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongocrypt/src/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongocrypt/kms-message/src/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongocrypt-compat/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/BSON/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/MongoDB/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/MongoDB/Exception/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/MongoDB/Monitoring/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/contrib/  -DHAVE_CONFIG_H  -I/opt/homebrew/include -D_GNU_SOURCE   -g -O0 -Wall -DBSON_COMPILATION -DMONGOC_COMPILATION -D_XOPEN_SOURCE=700 -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_DARWIN_C_SOURCE -pthread  -I/opt/homebrew/opt/zstd/include -I/opt/homebrew/Cellar/openssl@3/3.6.0/include -DKMS_MESSAGE_ENABLE_CRYPTO=1 -DKMS_MESSAGE_ENABLE_CRYPTO_LIBCRYPTO=1 -DKMS_MESSAGE_LITTLE_ENDIAN=1 -pthread -c /Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/common/src/common-atomic.c -o src/libmongoc/src/common/src/common-atomic.lo  -MMD -MF src/libmongoc/src/common/src/common-atomic.dep -MT src/libmongoc/src/common/src/common-atomic.lo
mkdir src/libmongoc/src/common/src/.libs
 cc -Isrc/libmongoc/src/common/src/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/common/src/ -I/opt/homebrew/Cellar/php@8.4/8.4.15/include/php -I/opt/homebrew/Cellar/php@8.4/8.4.15/include/php/main -I/opt/homebrew/Cellar/php@8.4/8.4.15/include/php/TSRM -I/opt/homebrew/Cellar/php@8.4/8.4.15/include/php/Zend -I/opt/homebrew/Cellar/php@8.4/8.4.15/include/php/ext -I/opt/homebrew/Cellar/php@8.4/8.4.15/include/php/ext/date/lib -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/common/src/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/uthash/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/libbson/src/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/libbson/src/jsonsl/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/libmongoc/src/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/utf8proc-2.8.0/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongocrypt/src/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongocrypt/kms-message/src/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongocrypt-compat/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/BSON/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/MongoDB/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/MongoDB/Exception/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/MongoDB/Monitoring/ -I/Users/alcaeus/Code/mongodb/mongo-php-driver/src/contrib/ -DHAVE_CONFIG_H -I/opt/homebrew/include -D_GNU_SOURCE -g -O0 -Wall -DBSON_COMPILATION -DMONGOC_COMPILATION -D_XOPEN_SOURCE=700 -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_DARWIN_C_SOURCE -pthread -I/opt/homebrew/opt/zstd/include -I/opt/homebrew/Cellar/openssl@3/3.6.0/include -DKMS_MESSAGE_ENABLE_CRYPTO=1 -DKMS_MESSAGE_ENABLE_CRYPTO_LIBCRYPTO=1 -DKMS_MESSAGE_LITTLE_ENDIAN=1 -pthread -c /Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/common/src/common-atomic.c -MMD -MF src/libmongoc/src/common/src/common-atomic.dep -MT src/libmongoc/src/common/src/common-atomic.lo  -fno-common -DPIC -o src/libmongoc/src/common/src/.libs/common-atomic.o
In file included from /Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/common/src/common-atomic.c:18:
In file included from /Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/common/src/common-atomic-private.h:24:
In file included from /Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/libbson/src/bson/bson.h:23:
In file included from /Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/libbson/src/bson/bson-bcon.h:27:
In file included from /Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/libbson/src/bson/bson-types.h:23:
In file included from /Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/libbson/src/bson/bson-endian.h:23:
/Users/alcaeus/Code/mongodb/mongo-php-driver/src/libmongoc/src/libbson/src/bson/compat.h:31:10: fatal error: 'bson/config.h' file not found
   31 | #include <bson/config.h> // IWYU pragma: export
      |          ^~~~~~~~~~~~~~~
1 error generated.                                                                                                                                                                                                                                                                                                          
make: *** [src/libmongoc/src/common/src/common-atomic.lo] Error 1

This leads me to believe that we'd need to add additional directories (e.g. src/libmongoc/src/libbson/src/bson) to the includes. Do you foresee this being a typical use case? I'm not sure it's worth the hassle, considering most installs of the extension will be run through pear/pie, where the installer runs configure and make from the temporary folder it extracts sources to, before then cleaning up those sources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants