Skip to content

PHPC-2714: Fix in-tree PHP builds#2005

Merged
alcaeus merged 3 commits intomongodb:v2.3from
alcaeus:fix-static-php-builds
Apr 30, 2026
Merged

PHPC-2714: Fix in-tree PHP builds#2005
alcaeus merged 3 commits intomongodb:v2.3from
alcaeus:fix-static-php-builds

Conversation

@alcaeus
Copy link
Copy Markdown
Member

@alcaeus alcaeus commented Apr 30, 2026

PHPC-2714, fixes #2003 and #2004

@alcaeus alcaeus changed the base branch from v2.x to v2.3 April 30, 2026 07:19
Downloads a PHP source tarball, symlinks the extension into php-src/ext/mongodb
(mirroring the StaticPHP in-tree build layout), and builds PHP with
--enable-mongodb (not =shared) so the extension is compiled directly into
the PHP binary. Verifies that the extension is present via --ri mongodb,
then runs the full test suite using PHP's own run-tests.php with -n to
avoid any system php.ini attempting to dlopen a mongodb.so that does not
exist in a static build.

--enable-mongodb-coverage is intentionally omitted: config.m4 rejects
that flag for static builds with AC_MSG_ERROR.
@alcaeus alcaeus force-pushed the fix-static-php-builds branch from 4e177c9 to bcb79c1 Compare April 30, 2026 07:35
PR mongodb#1893 (PHPC-2647) broke in-tree PHP builds (used by StaticPHP and
similar projects) in two ways:

1. Include paths used $PWD, which during in-tree PHP builds resolves to
   the PHP source root rather than the extension's subdirectory, so the
   compiler couldn't find generated headers under ext/mongodb/.

2. AC_CONFIG_FILES paths were bare relative paths (e.g.
   src/libmongoc/.../config.h), which config.status resolved relative to
   the configure invocation directory — the PHP source root for in-tree
   builds — writing headers to the wrong location.

Fix both by introducing ac_ext_builddir=PHP_EXT_BUILDDIR(mongodb), which
expands to "ext/mongodb" for in-tree PHP builds and "." for standalone
phpize builds.  Absolute include paths become
$abs_builddir/$ac_ext_builddir/src/..., and all AC_CONFIG_FILES paths
become ${ac_ext_builddir}/src/..., placing generated headers in the
extension's own build directory in every build layout while keeping the
original PHPC-2647 goal of not polluting the source tree during
standalone out-of-source builds.
@alcaeus alcaeus changed the title Fix PHP compilation with static MongoDB extension PHPC-2714: Fix in-tree PHP builds Apr 30, 2026
@alcaeus alcaeus marked this pull request as ready for review April 30, 2026 07:55
@alcaeus alcaeus requested a review from a team as a code owner April 30, 2026 07:55
@alcaeus alcaeus requested review from GromNaN and Copilot and removed request for a team April 30, 2026 07:55
@alcaeus
Copy link
Copy Markdown
Member Author

alcaeus commented Apr 30, 2026

@eramongodb This should theoretically keep the directory clean when configure is invoked from a different directory, but happy to take another shot at this separately now that we can confirm we don't accidentally break in-tree builds for PHP itself.

Copy link
Copy Markdown
Contributor

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

Fixes in-tree (static) PHP builds of the MongoDB extension by ensuring generated libmongoc/libbson config headers are written to—and included from—the extension’s build directory instead of the PHP build root, and adds CI coverage for that build mode.

Changes:

  • Adjust bundled libmongoc/libbson AC_CONFIG_FILES outputs and include paths to use the extension build dir (supports PHP in-tree builds).
  • Add a GitHub Actions job that builds PHP from source with --enable-mongodb (static/in-tree) and verifies the extension is compiled in.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
config.m4 Writes generated config headers under the extension build dir and updates include paths to match, fixing in-tree PHP builds.
.github/workflows/tests.yml Adds a CI job to build PHP statically with the extension in-tree to prevent regressions.

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

Comment thread config.m4 Outdated
Comment thread .github/workflows/tests.yml Outdated
Comment thread .github/workflows/tests.yml
Comment thread config.m4
- Rename ac_ext_builddir to php_mongodb_ext_builddir to avoid the ac_
  prefix reserved for autoconf internals
- Expand the TODO comment to explain why the block cannot move after
  PHP_NEW_EXTENSION (PHP_ADD_INCLUDE and source additions must precede it)
- Add bison and re2c to the static PHP build CI job's apt dependencies,
  as ./buildconf --force requires them
- Add a comment to the test-static-php-build job explaining its purpose
@alcaeus alcaeus enabled auto-merge (squash) April 30, 2026 08:15
@alcaeus alcaeus requested a review from GromNaN April 30, 2026 08:15
@alcaeus alcaeus merged commit 79b6416 into mongodb:v2.3 Apr 30, 2026
44 checks passed
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.

3 participants