unixconfigurearg needs to know if currently building shared or static

This commit is contained in:
DubbleClick
2025-03-27 11:12:19 +07:00
parent acdec64144
commit 48f257f85a
38 changed files with 61 additions and 45 deletions

View File

@@ -99,7 +99,7 @@ SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lpthread -lm"
; EXTRA_CFLAGS for `make` php ; EXTRA_CFLAGS for `make` php
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fpic -fpie -Os -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -fno-ident -fPIE -fPIC" SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fpic -fpie -Os -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -fno-ident -fPIE -fPIC"
; EXTRA_LIBS for `make` php ; EXTRA_LIBS for `make` php
SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="" SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm"
; EXTRA_LDFLAGS_PROGRAM for `make` php ; EXTRA_LDFLAGS_PROGRAM for `make` php
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-all-static -Wl,-O1 -pie" SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-all-static -Wl,-O1 -pie"

View File

@@ -771,6 +771,10 @@
"Windows": "no", "Windows": "no",
"BSD": "wip" "BSD": "wip"
}, },
"target": [
"static",
"shared"
],
"notes": true, "notes": true,
"type": "external", "type": "external",
"source": "swoole", "source": "swoole",
@@ -1043,6 +1047,10 @@
"support": { "support": {
"BSD": "wip" "BSD": "wip"
}, },
"target": [
"static",
"shared"
],
"type": "builtin", "type": "builtin",
"arg-type": "with-prefix", "arg-type": "with-prefix",
"arg-type-windows": "enable", "arg-type-windows": "enable",

View File

@@ -198,7 +198,7 @@ abstract class BuilderBase
$this->emitPatchPoint('after-micro-extract'); $this->emitPatchPoint('after-micro-extract');
} }
$this->emitPatchPoint('before-exts-extract'); $this->emitPatchPoint('before-exts-extract');
SourceManager::initSource(exts: $static_extensions); SourceManager::initSource(exts: [...$static_extensions, ...$shared_extensions]);
$this->emitPatchPoint('after-exts-extract'); $this->emitPatchPoint('after-exts-extract');
foreach ([...$static_extensions, ...$shared_extensions] as $extension) { foreach ([...$static_extensions, ...$shared_extensions] as $extension) {
$class = CustomExt::getExtClass($extension); $class = CustomExt::getExtClass($extension);

View File

@@ -150,7 +150,7 @@ class Extension
// Windows is not supported yet // Windows is not supported yet
} }
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
return ''; return '';
} }
@@ -188,7 +188,13 @@ class Extension
/** /**
* Run shared extension check when cli is enabled * Run shared extension check when cli is enabled
*/ */
public function runSharedExtensionCheckUnix(): void {} public function runSharedExtensionCheckUnix(): void
{
[$ret] = shell()->execWithResult(BUILD_BIN_PATH . '/php -n -d "extension=' . BUILD_LIB_PATH . '/' . $this->getName() . '.so" --ri ' . $this->getName());
if ($ret !== 0) {
throw new RuntimeException($this->getName() . '.so failed to load');
}
}
/** /**
* @throws RuntimeException * @throws RuntimeException
@@ -279,7 +285,7 @@ class Extension
shell()->cd($this->source_dir) shell()->cd($this->source_dir)
->setEnv(['CFLAGS' => $this->builder->arch_c_flags ?? '']) ->setEnv(['CFLAGS' => $this->builder->arch_c_flags ?? ''])
->execWithEnv(BUILD_BIN_PATH . '/phpize') ->execWithEnv(BUILD_BIN_PATH . '/phpize')
->execWithEnv('./configure ' . $this->getUnixConfigureArg() . ' --with-php-config=' . BUILD_BIN_PATH . '/php-config --enable-shared --disable-static') ->execWithEnv('./configure ' . $this->getUnixConfigureArg(true) . ' --with-php-config=' . BUILD_BIN_PATH . '/php-config --enable-shared --disable-static')
->execWithEnv('make clean') ->execWithEnv('make clean')
->execWithEnv('make -j' . $this->builder->concurrency); ->execWithEnv('make -j' . $this->builder->concurrency);
@@ -304,15 +310,15 @@ class Extension
public function setBuildStatic(): void public function setBuildStatic(): void
{ {
if (!in_array('static', Config::getExtTarget($this->name))) { if (!in_array('static', Config::getExtTarget($this->name))) {
throw new WrongUsageException("Extension [{$this->name}] does not support static build !"); throw new WrongUsageException("Extension [{$this->name}] does not support static build!");
} }
$this->build_static = true; $this->build_static = true;
} }
public function setBuildShared(): void public function setBuildShared(): void
{ {
if (!in_array('shared', Config::getExtTarget($this->name)) || Config::getExt($this->name, 'type') === 'builtin') { if (!in_array('shared', Config::getExtTarget($this->name))) {
throw new WrongUsageException("Extension [{$this->name}] does not support shared build !"); throw new WrongUsageException("Extension [{$this->name}] does not support shared build!");
} }
$this->build_shared = true; $this->build_shared = true;
} }

View File

@@ -23,7 +23,7 @@ class amqp extends Extension
return false; return false;
} }
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
return '--with-amqp --with-librabbitmq-dir=' . BUILD_ROOT_PATH; return '--with-amqp --with-librabbitmq-dir=' . BUILD_ROOT_PATH;
} }

View File

@@ -10,7 +10,7 @@ use SPC\util\CustomExt;
#[CustomExt('dba')] #[CustomExt('dba')]
class dba extends Extension class dba extends Extension
{ {
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
$qdbm = $this->builder->getLib('qdbm') ? (' --with-qdbm=' . BUILD_ROOT_PATH) : ''; $qdbm = $this->builder->getLib('qdbm') ? (' --with-qdbm=' . BUILD_ROOT_PATH) : '';
return '--enable-dba' . $qdbm; return '--enable-dba' . $qdbm;

View File

@@ -10,7 +10,7 @@ use SPC\util\CustomExt;
#[CustomExt('enchant')] #[CustomExt('enchant')]
class enchant extends Extension class enchant extends Extension
{ {
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
$glibs = [ $glibs = [
'/Users/jerry/project/git-project/static-php-cli/buildroot/lib/libgio-2.0.a', '/Users/jerry/project/git-project/static-php-cli/buildroot/lib/libgio-2.0.a',

View File

@@ -13,7 +13,7 @@ use SPC\util\CustomExt;
#[CustomExt('event')] #[CustomExt('event')]
class event extends Extension class event extends Extension
{ {
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
$arg = '--with-event-core --with-event-extra --with-event-libevent-dir=' . BUILD_ROOT_PATH; $arg = '--with-event-core --with-event-extra --with-event-libevent-dir=' . BUILD_ROOT_PATH;
if ($this->builder->getLib('openssl')) { if ($this->builder->getLib('openssl')) {

View File

@@ -10,7 +10,7 @@ use SPC\util\CustomExt;
#[CustomExt('ffi')] #[CustomExt('ffi')]
class ffi extends Extension class ffi extends Extension
{ {
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
return '--with-ffi --enable-zend-signals'; return '--with-ffi --enable-zend-signals';
} }

View File

@@ -10,7 +10,7 @@ use SPC\util\CustomExt;
#[CustomExt('gd')] #[CustomExt('gd')]
class gd extends Extension class gd extends Extension
{ {
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
$arg = '--enable-gd'; $arg = '--enable-gd';
$arg .= $this->builder->getLib('freetype') ? ' --with-freetype' : ''; $arg .= $this->builder->getLib('freetype') ? ' --with-freetype' : '';

View File

@@ -30,7 +30,7 @@ class glfw extends Extension
return true; return true;
} }
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
return '--enable-glfw --with-glfw-dir=' . BUILD_ROOT_PATH; return '--enable-glfw --with-glfw-dir=' . BUILD_ROOT_PATH;
} }

View File

@@ -44,7 +44,7 @@ class grpc extends Extension
return true; return true;
} }
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
return '--enable-grpc=' . BUILD_ROOT_PATH . '/grpc GRPC_LIB_SUBDIR=' . BUILD_LIB_PATH; return '--enable-grpc=' . BUILD_ROOT_PATH . '/grpc GRPC_LIB_SUBDIR=' . BUILD_LIB_PATH;
} }

View File

@@ -22,7 +22,7 @@ class imagick extends Extension
return true; return true;
} }
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
return '--with-imagick=' . BUILD_ROOT_PATH; return '--with-imagick=' . BUILD_ROOT_PATH;
} }

View File

@@ -33,7 +33,7 @@ class imap extends Extension
} }
} }
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
$arg = '--with-imap=' . BUILD_ROOT_PATH; $arg = '--with-imap=' . BUILD_ROOT_PATH;
if ($this->builder->getLib('openssl') !== null) { if ($this->builder->getLib('openssl') !== null) {

View File

@@ -12,7 +12,7 @@ use SPC\util\CustomExt;
#[CustomExt('memcache')] #[CustomExt('memcache')]
class memcache extends Extension class memcache extends Extension
{ {
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
return '--enable-memcache --with-zlib-dir=' . BUILD_ROOT_PATH; return '--enable-memcache --with-zlib-dir=' . BUILD_ROOT_PATH;
} }

View File

@@ -10,7 +10,7 @@ use SPC\util\CustomExt;
#[CustomExt('memcached')] #[CustomExt('memcached')]
class memcached extends Extension class memcached extends Extension
{ {
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
$rootdir = BUILD_ROOT_PATH; $rootdir = BUILD_ROOT_PATH;
$zlib_dir = $this->builder->getPHPVersionID() >= 80400 ? '' : "--with-zlib-dir={$rootdir}"; $zlib_dir = $this->builder->getPHPVersionID() >= 80400 ? '' : "--with-zlib-dir={$rootdir}";

View File

@@ -10,7 +10,7 @@ use SPC\util\CustomExt;
#[CustomExt('mongodb')] #[CustomExt('mongodb')]
class mongodb extends Extension class mongodb extends Extension
{ {
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
$arg = ' --enable-mongodb '; $arg = ' --enable-mongodb ';
$arg .= ' --with-mongodb-system-libs=no --with-mongodb-client-side-encryption=no '; $arg .= ' --with-mongodb-system-libs=no --with-mongodb-client-side-encryption=no ';

View File

@@ -10,7 +10,7 @@ use SPC\util\CustomExt;
#[CustomExt('odbc')] #[CustomExt('odbc')]
class odbc extends Extension class odbc extends Extension
{ {
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
return '--with-unixODBC=' . BUILD_ROOT_PATH; return '--with-unixODBC=' . BUILD_ROOT_PATH;
} }

View File

@@ -42,7 +42,7 @@ class opcache extends Extension
return file_put_contents(SOURCE_PATH . '/php-src/.opcache_patched', '1') !== false; return file_put_contents(SOURCE_PATH . '/php-src/.opcache_patched', '1') !== false;
} }
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
return '--enable-opcache'; return '--enable-opcache';
} }

View File

@@ -23,7 +23,7 @@ class openssl extends Extension
return false; return false;
} }
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
$openssl_dir = $this->builder->getPHPVersionID() >= 80400 ? '' : ' --with-openssl-dir=' . BUILD_ROOT_PATH; $openssl_dir = $this->builder->getPHPVersionID() >= 80400 ? '' : ' --with-openssl-dir=' . BUILD_ROOT_PATH;
return '--with-openssl=' . BUILD_ROOT_PATH . $openssl_dir; return '--with-openssl=' . BUILD_ROOT_PATH . $openssl_dir;

View File

@@ -17,7 +17,7 @@ class pdo_odbc extends Extension
return true; return true;
} }
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
return '--with-pdo-odbc=unixODBC,' . BUILD_ROOT_PATH; return '--with-pdo-odbc=unixODBC,' . BUILD_ROOT_PATH;
} }

View File

@@ -33,7 +33,7 @@ class pgsql extends Extension
* @throws WrongUsageException * @throws WrongUsageException
* @throws RuntimeException * @throws RuntimeException
*/ */
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
if ($this->builder->getPHPVersionID() >= 80400) { if ($this->builder->getPHPVersionID() >= 80400) {
return '--with-pgsql PGSQL_CFLAGS=-I' . BUILD_INCLUDE_PATH . ' PGSQL_LIBS="-L' . BUILD_LIB_PATH . ' -lpq -lpgport -lpgcommon"'; return '--with-pgsql PGSQL_CFLAGS=-I' . BUILD_INCLUDE_PATH . ' PGSQL_LIBS="-L' . BUILD_LIB_PATH . ' -lpq -lpgport -lpgcommon"';

View File

@@ -10,7 +10,7 @@ use SPC\util\CustomExt;
#[CustomExt('redis')] #[CustomExt('redis')]
class redis extends Extension class redis extends Extension
{ {
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
$arg = '--enable-redis'; $arg = '--enable-redis';
$arg .= $this->builder->getExt('session') ? ' --enable-redis-session' : ' --disable-redis-session'; $arg .= $this->builder->getExt('session') ? ' --enable-redis-session' : ' --disable-redis-session';

View File

@@ -26,7 +26,7 @@ class snappy extends Extension
return true; return true;
} }
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
return '--enable-snappy --with-snappy-includedir="' . BUILD_ROOT_PATH . '"'; return '--enable-snappy --with-snappy-includedir="' . BUILD_ROOT_PATH . '"';
} }

View File

@@ -21,7 +21,7 @@ class spx extends Extension
} }
} }
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
$arg = '--enable-spx'; $arg = '--enable-spx';
if ($this->builder->getExt('zlib') === null) { if ($this->builder->getExt('zlib') === null) {

View File

@@ -35,7 +35,7 @@ class swoole extends Extension
return null; return null;
} }
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
// enable swoole // enable swoole
$arg = '--enable-swoole'; $arg = '--enable-swoole';
@@ -49,7 +49,9 @@ class swoole extends Extension
// additional feature: c-ares, brotli, nghttp2 (can be disabled, but we enable it by default in config to support full network feature) // additional feature: c-ares, brotli, nghttp2 (can be disabled, but we enable it by default in config to support full network feature)
$arg .= $this->builder->getLib('libcares') ? ' --enable-cares' : ''; $arg .= $this->builder->getLib('libcares') ? ' --enable-cares' : '';
$arg .= $this->builder->getLib('brotli') ? (' --enable-brotli --with-brotli-dir=' . BUILD_ROOT_PATH) : ''; if (!$shared) {
$arg .= $this->builder->getLib('brotli') ? (' --enable-brotli --with-brotli-dir=' . BUILD_ROOT_PATH) : '';
}
$arg .= $this->builder->getLib('nghttp2') ? (' --with-nghttp2-dir=' . BUILD_ROOT_PATH) : ''; $arg .= $this->builder->getLib('nghttp2') ? (' --with-nghttp2-dir=' . BUILD_ROOT_PATH) : '';
// additional feature: swoole-pgsql, it should depend on lib [postgresql], but it will lack of CFLAGS etc. // additional feature: swoole-pgsql, it should depend on lib [postgresql], but it will lack of CFLAGS etc.

View File

@@ -16,7 +16,7 @@ class swoole_hook_mysql extends Extension
return 'swoole'; return 'swoole';
} }
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
// pdo_mysql doesn't need to be disabled // pdo_mysql doesn't need to be disabled
// enable swoole-hook-mysql will enable mysqli, pdo, pdo_mysql, we don't need to add any additional options // enable swoole-hook-mysql will enable mysqli, pdo, pdo_mysql, we don't need to add any additional options

View File

@@ -25,7 +25,7 @@ class swoole_hook_pgsql extends Extension
} }
} }
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
// enable swoole pgsql hook // enable swoole pgsql hook
return '--enable-swoole-pgsql'; return '--enable-swoole-pgsql';

View File

@@ -25,7 +25,7 @@ class swoole_hook_sqlite extends Extension
} }
} }
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
// enable swoole pgsql hook // enable swoole pgsql hook
return '--enable-swoole-sqlite'; return '--enable-swoole-sqlite';

View File

@@ -15,7 +15,7 @@ class xdebug extends Extension
{ {
[$ret] = shell()->execWithResult(BUILD_BIN_PATH . '/php -n -d "zend_extension=' . BUILD_LIB_PATH . '/xdebug.so" --ri xdebug'); [$ret] = shell()->execWithResult(BUILD_BIN_PATH . '/php -n -d "zend_extension=' . BUILD_LIB_PATH . '/xdebug.so" --ri xdebug');
if ($ret !== 0) { if ($ret !== 0) {
throw new RuntimeException('xdebug.so not found'); throw new RuntimeException('xdebug.so failed to load.');
} }
} }
} }

View File

@@ -10,7 +10,7 @@ use SPC\util\CustomExt;
#[CustomExt('xlswriter')] #[CustomExt('xlswriter')]
class xlswriter extends Extension class xlswriter extends Extension
{ {
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
$arg = '--with-xlswriter --enable-reader'; $arg = '--with-xlswriter --enable-reader';
if ($this->builder->getLib('openssl')) { if ($this->builder->getLib('openssl')) {

View File

@@ -20,7 +20,7 @@ class xml extends Extension
/** /**
* @throws RuntimeException * @throws RuntimeException
*/ */
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
$arg = match ($this->name) { $arg = match ($this->name) {
'xml' => '--enable-xml', 'xml' => '--enable-xml',

View File

@@ -19,7 +19,7 @@ class yac extends Extension
return true; return true;
} }
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
return '--enable-yac --enable-igbinary --enable-json'; return '--enable-yac --enable-igbinary --enable-json';
} }

View File

@@ -10,7 +10,7 @@ use SPC\util\CustomExt;
#[CustomExt('zlib')] #[CustomExt('zlib')]
class zlib extends Extension class zlib extends Extension
{ {
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
$zlib_dir = $this->builder->getPHPVersionID() >= 80400 ? '' : ' --with-zlib-dir=' . BUILD_ROOT_PATH; $zlib_dir = $this->builder->getPHPVersionID() >= 80400 ? '' : ' --with-zlib-dir=' . BUILD_ROOT_PATH;
return '--with-zlib' . $zlib_dir; return '--with-zlib' . $zlib_dir;

View File

@@ -10,7 +10,7 @@ use SPC\util\CustomExt;
#[CustomExt('zstd')] #[CustomExt('zstd')]
class zstd extends Extension class zstd extends Extension
{ {
public function getUnixConfigureArg(): string public function getUnixConfigureArg(bool $shared = false): string
{ {
return '--enable-zstd --with-libzstd="' . BUILD_ROOT_PATH . '"'; return '--enable-zstd --with-libzstd="' . BUILD_ROOT_PATH . '"';
} }

View File

@@ -171,7 +171,7 @@ class BuildPHPCommand extends BuildCommand
// compile libraries // compile libraries
$builder->proveLibs($libraries); $builder->proveLibs($libraries);
// check extensions // check extensions
$builder->proveExts($extensions, shared_extensions: $shared_extensions); $builder->proveExts($static_extensions, $shared_extensions);
// validate libs and extensions // validate libs and extensions
$builder->validateLibsAndExts(); $builder->validateLibsAndExts();

View File

@@ -118,7 +118,7 @@ class Config
if (!isset(self::$ext[$name])) { if (!isset(self::$ext[$name])) {
throw new WrongUsageException('ext [' . $name . '] is not supported yet'); throw new WrongUsageException('ext [' . $name . '] is not supported yet');
} }
return self::$ext[$name]['target'] ?? ['static', 'shared']; return self::$ext[$name]['target'] ?? ['static'];
} }
/** /**

View File

@@ -51,9 +51,9 @@ class SPCConfigUtil
$libs = BUILD_LIB_PATH . '/mimalloc.o ' . str_replace(BUILD_LIB_PATH . '/mimalloc.o', '', $libs); $libs = BUILD_LIB_PATH . '/mimalloc.o ' . str_replace(BUILD_LIB_PATH . '/mimalloc.o', '', $libs);
} }
return [ return [
'cflags' => $cflags, 'cflags' => trim(getenv('CFLAGS') . ' ' . $cflags),
'ldflags' => $ldflags, 'ldflags' => trim(getenv('LDFLAGS') . ' ' . $ldflags),
'libs' => $libs, 'libs' => trim(getenv('LIBS') . ' ' . $libs),
]; ];
} }