rework building of shared extensions so that builtin extensions are built at php-src/configure -> make time

This commit is contained in:
DubbleClick 2025-05-21 12:01:00 +07:00
parent c43423a7d0
commit 95a2f4600b
21 changed files with 53 additions and 42 deletions

View File

@ -81,7 +81,7 @@ SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime
; buildconf command
SPC_CMD_PREFIX_PHP_BUILDCONF="./buildconf --force"
; configure command
SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbg --with-pic"
SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --enable-shared=yes --enable-static=no --disable-all --disable-cgi --disable-phpdbg --with-pic"
; make command
SPC_CMD_PREFIX_PHP_MAKE="make -j${CPU_COUNT}"
; embed type for php, static (libphp.a) or shared (libphp.so)

View File

@ -256,6 +256,10 @@ abstract class BuilderBase
if (!$ext->isBuildShared()) {
continue;
}
if (Config::getExt($ext->getName(), 'type') === 'builtin') {
logger()->info('Shared extension [' . $ext->getName() . '] was already built by php-src/configure (' . $ext->getName() . '.so)');
continue;
}
logger()->info('Building extension [' . $ext->getName() . '] as shared extension (' . $ext->getName() . '.so)');
$ext->buildShared();
}
@ -272,9 +276,17 @@ abstract class BuilderBase
public function makeStaticExtensionArgs(): string
{
$ret = [];
foreach ($this->getExts(false) as $ext) {
logger()->info($ext->getName() . ' is using ' . $ext->getConfigureArg());
$ret[] = trim($ext->getConfigureArg());
foreach ($this->getExts() as $ext) {
$arg = $ext->getConfigureArg();
if ($ext->isBuildShared()) {
if (Config::getExt($ext->getName(), 'type') === 'builtin') {
$arg = $ext->getConfigureArg(true);
} else {
continue;
}
}
logger()->info($ext->getName() . ' is using ' . $arg);
$ret[] = trim($arg);
}
logger()->debug('Using configure: ' . implode(' ', $ret));
return implode(' ', $ret);

View File

@ -9,7 +9,6 @@ use SPC\exception\RuntimeException;
use SPC\exception\WrongUsageException;
use SPC\store\Config;
use SPC\store\FileSystem;
use SPC\store\SourcePatcher;
use SPC\util\SPCConfigUtil;
class Extension
@ -60,20 +59,15 @@ class Extension
* @throws FileSystemException
* @throws WrongUsageException
*/
public function getConfigureArg(): string
public function getConfigureArg(bool $shared = false): string
{
$arg = $this->getEnableArg();
switch (PHP_OS_FAMILY) {
case 'Windows':
$arg .= $this->getWindowsConfigureArg();
break;
case 'Darwin':
case 'Linux':
case 'BSD':
$arg .= $this->getUnixConfigureArg();
break;
}
return $arg;
return match (PHP_OS_FAMILY) {
'Windows' => $this->getWindowsConfigureArg($shared),
'Darwin',
'Linux',
'BSD' => $this->getUnixConfigureArg($shared),
default => throw new WrongUsageException(PHP_OS_FAMILY . ' build is not supported yet'),
};
}
/**
@ -82,13 +76,13 @@ class Extension
* @throws FileSystemException
* @throws WrongUsageException
*/
public function getEnableArg(): string
public function getEnableArg(bool $shared = false): string
{
$_name = str_replace('_', '-', $this->name);
return match ($arg_type = Config::getExt($this->name, 'arg-type', 'enable')) {
'enable' => '--enable-' . $_name . ' ',
'with' => '--with-' . $_name . ' ',
'with-prefix' => '--with-' . $_name . '="' . BUILD_ROOT_PATH . '" ',
'with' => '--with-' . $_name . ($shared ? '=shared' : '') . ' ',
'with-prefix' => '--with-' . $_name . '=' . ($shared ? 'shared,' : '') . '"' . BUILD_ROOT_PATH . '" ',
'none', 'custom' => '',
default => throw new WrongUsageException("argType does not accept {$arg_type}, use [enable/with/with-prefix] ."),
};
@ -151,15 +145,15 @@ class Extension
return $this->name;
}
public function getWindowsConfigureArg(): string
public function getWindowsConfigureArg(bool $shared = false): string
{
return '';
return $this->getEnableArg();
// Windows is not supported yet
}
public function getUnixConfigureArg(bool $shared = false): string
{
return '';
return $this->getEnableArg($shared);
}
/**
@ -345,7 +339,7 @@ class Extension
shell()->cd($this->source_dir)
->setEnv($env)
->execWithEnv('./configure ' . $this->getUnixConfigureArg(true) . ' --with-php-config=' . BUILD_BIN_PATH . '/php-config --enable-shared --disable-static --with-pic')
->execWithEnv('./configure ' . $this->getUnixConfigureArg(true) . ' --with-php-config=' . BUILD_BIN_PATH . '/php-config --with-pic')
->execWithEnv('make clean')
->execWithEnv('make -j' . $this->builder->concurrency)
->execWithEnv('make install');

View File

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

View File

@ -16,7 +16,7 @@ class dba extends Extension
return '--enable-dba' . $qdbm;
}
public function getWindowsConfigureArg(): string
public function getWindowsConfigureArg(bool $shared = false): string
{
$qdbm = $this->builder->getLib('qdbm') ? ' --with-qdbm' : '';
return '--with-dba' . $qdbm;

View File

@ -30,7 +30,7 @@ class dom extends Extension
return true;
}
public function getWindowsConfigureArg(): string
public function getWindowsConfigureArg($shared = false): string
{
return '--with-dom --with-libxml';
}

View File

@ -15,7 +15,7 @@ class ffi extends Extension
return '--with-ffi --enable-zend-signals';
}
public function getWindowsConfigureArg(): string
public function getWindowsConfigureArg(bool $shared = false): string
{
return '--with-ffi';
}

View File

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

View File

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

View File

@ -16,7 +16,7 @@ class mbregex extends Extension
return 'mbstring';
}
public function getConfigureArg(): string
public function getConfigureArg(bool $shared = false): string
{
return '';
}

View File

@ -10,7 +10,7 @@ use SPC\util\CustomExt;
#[CustomExt('mbstring')]
class mbstring extends Extension
{
public function getConfigureArg(): string
public function getConfigureArg(bool $shared = false): string
{
$arg = '--enable-mbstring';
if ($this->builder->getExt('mbregex') === null) {

View File

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

View File

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

View File

@ -10,7 +10,7 @@ use SPC\util\CustomExt;
#[CustomExt('pdo_pgsql')]
class pdo_pgsql extends Extension
{
public function getWindowsConfigureArg(): string
public function getWindowsConfigureArg(bool $shared = false): string
{
return '--with-pdo-pgsql=yes';
}

View File

@ -45,7 +45,7 @@ class pgsql extends Extension
* @throws WrongUsageException
* @throws RuntimeException
*/
public function getWindowsConfigureArg(): string
public function getWindowsConfigureArg(bool $shared = false): string
{
if ($this->builder->getPHPVersionID() >= 80400) {
return '--with-pgsql';

View File

@ -27,7 +27,7 @@ class rdkafka extends Extension
return true;
}
public function getConfigureArg(): string
public function getConfigureArg(bool $shared = false): string
{
$pkgconf_libs = shell()->execWithResult('pkg-config --libs --static rdkafka')[1];
$pkgconf_libs = trim(implode('', $pkgconf_libs));

View File

@ -24,7 +24,7 @@ class redis extends Extension
return $arg;
}
public function getWindowsConfigureArg(): string
public function getWindowsConfigureArg(bool $shared = false): string
{
$arg = '--enable-redis';
$arg .= $this->builder->getExt('session') ? ' --enable-redis-session' : ' --disable-redis-session';

View File

@ -18,7 +18,7 @@ class swow extends Extension
}
}
public function getConfigureArg(): string
public function getConfigureArg(bool $shared = false): string
{
$arg = '--enable-swow';
$arg .= $this->builder->getLib('openssl') ? ' --enable-swow-ssl' : ' --disable-swow-ssl';

View File

@ -20,7 +20,7 @@ class xlswriter extends Extension
return $arg;
}
public function getWindowsConfigureArg(): string
public function getWindowsConfigureArg(bool $shared = false): string
{
return '--with-xlswriter';
}

View File

@ -41,7 +41,7 @@ class xml extends Extension
return true;
}
public function getWindowsConfigureArg(): string
public function getWindowsConfigureArg(bool $shared = false): string
{
$arg = match ($this->name) {
'xml' => '--with-xml',

View File

@ -184,7 +184,6 @@ class LinuxBuilder extends UnixBuilderBase
shell()->cd(SOURCE_PATH . '/php-src')
->exec(
getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' .
'--prefix=' . BUILD_ROOT_PATH . ' ' .
($enable_cli ? '--enable-cli ' : '--disable-cli ') .
($enable_fpm ? '--enable-fpm ' . ($this->getLib('libacl') !== null ? '--with-fpm-acl ' : '') : '--disable-fpm ') .
($enable_embed ? "--enable-embed={$embed_type} " : '--disable-embed ') .
@ -323,6 +322,7 @@ class LinuxBuilder extends UnixBuilderBase
shell()->cd(SOURCE_PATH . '/php-src')
->exec('sed -i "s|//lib|/lib|g" Makefile')
->exec('sed -i "s|^EXTENSION_DIR = .*|EXTENSION_DIR = ' . BUILD_MODULES_PATH . '|" Makefile')
->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . ' INSTALL_ROOT=' . BUILD_ROOT_PATH . " {$vars} install");
$this->patchPhpScripts();
}