Closed
Description
Bug Report
I'm trying to statically compile mongodb with PHP, with following steps:
- Download
php-src
andmongo-php-driver
- Extract
mongo-php-driver
tophp-src/ext/mongodb
./buildconf --force
./configure --disable-shared --enable-static --disable-phpdbg --enable-cli --enable-mongodb --with-mongodb-system-libs=no --with-mongodb-client-side-encryption=no --with-mongodb-sasl=no --without-iconv
And it shows error:
checking whether to enable MongoDB support... yes
checking for pkg-config... (cached) /opt/homebrew/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking PHP version... configure: error: php-config not found
From mongo source, I found it uses php-config
directly to get PHP version, and inline build (static compilation) apparently have no any dev command. So I tried to patch config.m4
like this:
// replaceFileStr is just `file_get_contents`, `str_replace`, `file_put_contents`
// getPHPVersion() assume it `8.2.18`
// getPHPVersionID assume it `80218`
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/mongodb/config.m4', 'if test -z "$PHP_CONFIG"; then', 'if false; then');
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/mongodb/config.m4', 'PHP_MONGODB_PHP_VERSION=`${PHP_CONFIG} --version`', 'PHP_MONGODB_PHP_VERSION=' . $this->builder->getPHPVersion());
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/mongodb/config.m4', 'PHP_MONGODB_PHP_VERSION_ID=`${PHP_CONFIG} --vernum`', 'PHP_MONGODB_PHP_VERSION_ID=' . $this->builder->getPHPVersionID());
And in order to add and test other flags more easily, I directly use static-php-cli to compile it. The main compilation methods and commands have not changed. In short, it uses commands below:
[06:02:15] [INFO] Extension [mongodb] patched before buildconf
[06:02:15] [INFO] Entering dir: /Users/jerry/project/git-project/static-php-cli/source/php-src
[06:02:15] [INFO] [EXEC] ./buildconf --force
[06:02:17] [INFO] Entering dir: /Users/jerry/project/git-project/static-php-cli/source/php-src
[06:02:17] [INFO] mongodb is using --enable-mongodb --with-mongodb-system-libs=no --with-mongodb-client-side-encryption=no --with-mongodb-sasl=no --with-mongodb-icu=no --with-mongodb-zstd=no --with-mongodb-zlib=bundled
[06:02:17] [INFO] [EXEC] ./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbg --enable-cli --disable-fpm --disable-embed --disable-micro --enable-mongodb --with-mongodb-system-libs=no --with-mongodb-client-side-encryption=no --with-mongodb-sasl=no --with-mongodb-icu=no --with-mongodb-zstd=no --with-mongodb-zlib=bundled CFLAGS='--target=arm64-apple-darwin -Werror=unknown-warning-option' CPPFLAGS='-I/Users/jerry/project/git-project/static-php-cli/buildroot/include' LDFLAGS='-L/Users/jerry/project/git-project/static-php-cli/buildroot/lib'
[06:02:35] [INFO] [EXEC] make clean
[06:02:36] [INFO] building cli
[06:02:36] [INFO] Entering dir: /Users/jerry/project/git-project/static-php-cli/source/php-src
[06:02:36] [INFO] [EXEC] make EXTRA_CFLAGS='-g -Os -Wimplicit-function-declaration' EXTRA_LIBS=' -lresolv' cli
And finally got this strange error from standard ext:
/Users/jerry/project/git-project/static-php-cli/source/php-src/ext/standard/dir.c:283:8: error: call to undeclared function 'chroot'; ISO C99 and later do
not support implicit function declarations [-Wimplicit-function-declaration]
ret = chroot(str);
^
1 error generated.
make: *** [Makefile:1615: ext/standard/dir.lo] Error 1
I actually have no idea, this build procedure works well on Linux. It would be better if someone could provide more clues 🕵️
Environment
Item | Value |
---|---|
OS | macOS Sonoma 14.4.1 |
Arch | arm64 |
CC | clang (Apple clang version 15.0.0) |
CXX | clang++ |
PHP Source Version | 8.2.18 |
mongodb-php-driver Version | 1.18.0 (release tarball) |
static-php-cli Version | main branch |
Debug Log
Related Issue
Metadata
Metadata
Assignees
Labels
No labels