Merge branch 'main' into feature/shared-exts

This commit is contained in:
Marc 2025-10-12 23:23:25 +02:00 committed by GitHub
commit 762a768969
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 90 additions and 96 deletions

View File

@ -890,7 +890,7 @@
"postgresql": { "postgresql": {
"type": "ghtagtar", "type": "ghtagtar",
"repo": "postgres/postgres", "repo": "postgres/postgres",
"match": "REL_16_\\d+", "match": "REL_18_\\d+",
"license": { "license": {
"type": "file", "type": "file",
"path": "COPYRIGHT" "path": "COPYRIGHT"

View File

@ -34,7 +34,7 @@ use Symfony\Component\Console\Application;
*/ */
final class ConsoleApplication extends Application final class ConsoleApplication extends Application
{ {
public const string VERSION = '2.7.4'; public const string VERSION = '2.7.5';
public function __construct() public function __construct()
{ {

View File

@ -156,7 +156,14 @@ class LinuxBuilder extends UnixBuilderBase
} }
$shared_extensions = array_map('trim', array_filter(explode(',', $this->getOption('build-shared')))); $shared_extensions = array_map('trim', array_filter(explode(',', $this->getOption('build-shared'))));
if (!empty($shared_extensions)) { if (!empty($shared_extensions)) {
logger()->info('Building shared extensions ...'); if (SPCTarget::isStatic()) {
throw new WrongUsageException(
"You're building against musl libc statically (the default on Linux), but you're trying to build shared extensions.\n" .
'Static musl libc does not implement `dlopen`, so your php binary is not able to load shared extensions.' . "\n" .
'Either use SPC_LIBC=glibc to link against glibc on a glibc OS, or use SPC_TARGET="native-native-musl -dynamic" to link against musl libc dynamically using `zig cc`.'
);
}
logger()->info('Building shared extensions...');
$this->buildSharedExts(); $this->buildSharedExts();
} }
} }

View File

@ -4,93 +4,83 @@ declare(strict_types=1);
namespace SPC\builder\unix\library; namespace SPC\builder\unix\library;
use SPC\builder\linux\library\LinuxLibraryBase;
use SPC\exception\BuildFailureException;
use SPC\exception\FileSystemException;
use SPC\store\FileSystem; use SPC\store\FileSystem;
use SPC\util\PkgConfigUtil;
use SPC\util\SPCConfigUtil;
use SPC\util\SPCTarget; use SPC\util\SPCTarget;
trait postgresql trait postgresql
{ {
public function patchBeforeBuild(): bool
{
if (SPCTarget::getLibcVersion() === '2.17' && GNU_ARCH === 'aarch64') {
FileSystem::replaceFileStr(
$this->source_dir . '/src/port/pg_popcount_aarch64.c',
'HWCAP_SVE',
'0',
);
FileSystem::replaceFileStr(
$this->source_dir . '/src/port/pg_crc32c_armv8_choose.c',
'#if defined(__linux__) && !defined(__aarch64__) && !defined(HWCAP2_CRC32)',
'#if defined(__linux__) && !defined(HWCAP_CRC32)',
);
}
// skip the test on platforms where libpq infrastructure may be provided by statically-linked libraries
FileSystem::replaceFileStr("{$this->source_dir}/src/interfaces/libpq/Makefile", 'invokes exit\'; exit 1;', 'invokes exit\';');
// disable shared libs build
FileSystem::replaceFileStr(
"{$this->source_dir}/src/Makefile.shlib",
[
'$(LINK.shared) -o $@ $(OBJS) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK)',
'$(INSTALL_SHLIB) $< \'$(DESTDIR)$(pkglibdir)/$(shlib)\'',
'$(INSTALL_SHLIB) $< \'$(DESTDIR)$(libdir)/$(shlib)\'',
'$(INSTALL_SHLIB) $< \'$(DESTDIR)$(bindir)/$(shlib)\'',
],
''
);
return true;
}
protected function build(): void protected function build(): void
{ {
$builddir = BUILD_ROOT_PATH; $libs = array_map(fn ($x) => $x->getName(), $this->getDependencies());
$envs = ''; $spc = new SPCConfigUtil($this->getBuilder(), ['no_php' => true, 'libs_only_deps' => true]);
$packages = 'zlib openssl readline libxml-2.0'; $config = $spc->config(libraries: $libs, include_suggest_lib: $this->builder->getOption('with-suggested-libs'));
$optional_packages = [
'zstd' => 'libzstd',
'ldap' => 'ldap',
'libxslt' => 'libxslt',
'icu' => 'icu-i18n',
];
$error_exec_cnt = 0;
foreach ($optional_packages as $lib => $pkg) {
if ($this->getBuilder()->getLib($lib)) {
$packages .= ' ' . $pkg;
$output = shell()->execWithResult("pkg-config --static {$pkg}");
$error_exec_cnt += $output[0] === 0 ? 0 : 1;
logger()->info(var_export($output[1], true));
}
}
$output = shell()->execWithResult("pkg-config --cflags-only-I --static {$packages}");
$error_exec_cnt += $output[0] === 0 ? 0 : 1;
$macos_15_bug_cflags = PHP_OS_FAMILY === 'Darwin' ? ' -Wno-unguarded-availability-new' : ''; $macos_15_bug_cflags = PHP_OS_FAMILY === 'Darwin' ? ' -Wno-unguarded-availability-new' : '';
$cflags = '';
if (!empty($output[1][0])) { $env_vars = [
$cflags = $output[1][0]; 'CFLAGS' => "{$config['cflags']} -fno-ident{$macos_15_bug_cflags}",
$envs .= ' CPPFLAGS="-DPIC"'; 'CPPFLAGS' => '-DPIC',
$cflags = "{$cflags} -fno-ident{$macos_15_bug_cflags}"; 'LDFLAGS' => $config['ldflags'],
} 'LIBS' => $config['libs'],
$output = shell()->execWithResult("pkg-config --libs-only-L --static {$packages}"); ];
$error_exec_cnt += $output[0] === 0 ? 0 : 1;
if (!empty($output[1][0])) { if ($ldLibraryPath = getenv('SPC_LD_LIBRARY_PATH')) {
$ldflags = $output[1][0]; $env_vars['LD_LIBRARY_PATH'] = $ldLibraryPath;
$envs .= SPCTarget::isStatic() ? " LDFLAGS=\"{$ldflags} -static\" " : " LDFLAGS=\"{$ldflags}\" ";
}
$output = shell()->execWithResult("pkg-config --libs-only-l --static {$packages}");
$error_exec_cnt += $output[0] === 0 ? 0 : 1;
if (!empty($output[1][0])) {
$libs = $output[1][0];
$libcpp = '';
if ($this->builder->getLib('icu')) {
$libcpp = $this instanceof LinuxLibraryBase ? ' -lstdc++' : ' -lc++';
}
$envs .= " LIBS=\"{$libs}{$libcpp}\" ";
}
if ($error_exec_cnt > 0) {
throw new BuildFailureException('Failed to get pkg-config information!');
} }
FileSystem::resetDir($this->source_dir . '/build'); FileSystem::resetDir($this->source_dir . '/build');
$version = $this->getVersion(); // php source relies on the non-private encoding functions in libpgcommon.a
// 16.1 workaround FileSystem::replaceFileStr(
if (version_compare($version, '16.1') >= 0) { "{$this->source_dir}/src/common/Makefile",
# 有静态链接配置 参考文件: src/interfaces/libpq/Makefile '$(OBJS_FRONTEND): CPPFLAGS += -DUSE_PRIVATE_ENCODING_FUNCS',
shell()->cd($this->source_dir . '/build') '$(OBJS_FRONTEND): CPPFLAGS += -UUSE_PRIVATE_ENCODING_FUNCS -DFRONTEND',
->exec('sed -i.backup "s/invokes exit\'; exit 1;/invokes exit\';/" ../src/interfaces/libpq/Makefile') );
->exec('sed -i.backup "278 s/^/# /" ../src/Makefile.shlib')
->exec('sed -i.backup "402 s/^/# /" ../src/Makefile.shlib');
} else {
throw new BuildFailureException('Unsupported version for postgresql: ' . $version . ' !');
}
// configure // configure
shell()->cd($this->source_dir . '/build')->initializeEnv($this) $shell = shell()->cd("{$this->source_dir}/build")->initializeEnv($this)
->appendEnv(['CFLAGS' => $cflags]) ->appendEnv($env_vars)
->exec( ->exec(
"{$envs} ../configure " . '../configure ' .
"--prefix={$builddir} " . "--prefix={$this->getBuildRootPath()} " .
($this->builder->getOption('enable-zts') ? '--enable-thread-safety ' : '--disable-thread-safety ') .
'--enable-coverage=no ' . '--enable-coverage=no ' .
'--with-ssl=openssl ' . '--with-ssl=openssl ' .
'--with-readline ' . '--with-readline ' .
'--with-libxml ' . '--with-libxml ' .
($this->builder->getLib('icu') ? '--with-icu ' : '--without-icu ') . ($this->builder->getLib('icu') ? '--with-icu ' : '--without-icu ') .
($this->builder->getLib('ldap') ? '--with-ldap ' : '--without-ldap ') . ($this->builder->getLib('ldap') ? '--with-ldap ' : '--without-ldap ') .
// '--without-ldap ' .
($this->builder->getLib('libxslt') ? '--with-libxslt ' : '--without-libxslt ') . ($this->builder->getLib('libxslt') ? '--with-libxslt ' : '--without-libxslt ') .
($this->builder->getLib('zstd') ? '--with-zstd ' : '--without-zstd ') . ($this->builder->getLib('zstd') ? '--with-zstd ' : '--without-zstd ') .
'--without-lz4 ' . '--without-lz4 ' .
@ -99,32 +89,29 @@ trait postgresql
'--without-pam ' . '--without-pam ' .
'--without-bonjour ' . '--without-bonjour ' .
'--without-tcl ' '--without-tcl '
) );
->exec($envs . ' make -C src/bin/pg_config install')
->exec($envs . ' make -C src/include install') // patch ldap lib
->exec($envs . ' make -C src/common install') if ($this->builder->getLib('ldap')) {
->exec($envs . ' make -C src/port install') $libs = PkgConfigUtil::getLibsArray('ldap');
->exec($envs . ' make -C src/interfaces/libpq install'); $libs = clean_spaces(implode(' ', $libs));
FileSystem::replaceFileStr($this->source_dir . '/build/config.status', '-lldap', $libs);
FileSystem::replaceFileStr($this->source_dir . '/build/src/Makefile.global', '-lldap', $libs);
}
$shell
->exec('make -C src/bin/pg_config install')
->exec('make -C src/include install')
->exec('make -C src/common install')
->exec('make -C src/port install')
->exec('make -C src/interfaces/libpq install');
// remove dynamic libs // remove dynamic libs
shell()->cd($this->source_dir . '/build') shell()->cd($this->source_dir . '/build')
->exec("rm -rf {$builddir}/lib/*.so.*") ->exec("rm -rf {$this->getBuildRootPath()}/lib/*.so.*")
->exec("rm -rf {$builddir}/lib/*.so") ->exec("rm -rf {$this->getBuildRootPath()}/lib/*.so")
->exec("rm -rf {$builddir}/lib/*.dylib"); ->exec("rm -rf {$this->getBuildRootPath()}/lib/*.dylib");
FileSystem::replaceFileStr(BUILD_LIB_PATH . '/pkgconfig/libpq.pc', '-lldap', '-lldap -llber'); FileSystem::replaceFileStr("{$this->getLibDir()}/pkgconfig/libpq.pc", '-lldap', '-lldap -llber');
}
private function getVersion(): string
{
try {
$file = FileSystem::readFile($this->source_dir . '/meson.build');
if (preg_match("/^\\s+version:\\s?'(.*)'/m", $file, $match)) {
return $match[1];
}
return 'unknown';
} catch (FileSystemException) {
return 'unknown';
}
} }
} }

View File

@ -16,7 +16,7 @@ class PhpSource extends CustomSourceBase
{ {
$major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.4'; $major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.4';
if ($major === '8.5') { if ($major === '8.5') {
Downloader::downloadSource('php-src', ['type' => 'url', 'url' => 'https://downloads.php.net/~edorian/php-8.5.0beta3.tar.xz'], $force); Downloader::downloadSource('php-src', ['type' => 'url', 'url' => 'https://github.com/php/php-src/archive/refs/tags/php-8.5.0RC2.tar.gz'], $force);
} elseif ($major === 'git') { } elseif ($major === 'git') {
Downloader::downloadSource('php-src', ['type' => 'git', 'url' => 'https://github.com/php/php-src.git', 'rev' => 'master'], $force); Downloader::downloadSource('php-src', ['type' => 'git', 'url' => 'https://github.com/php/php-src.git', 'rev' => 'master'], $force);
} else { } else {

View File

@ -28,9 +28,9 @@ $test_os = [
'macos-15', // bin/spc for arm64 'macos-15', // bin/spc for arm64
// 'ubuntu-latest', // bin/spc-alpine-docker for x86_64 // 'ubuntu-latest', // bin/spc-alpine-docker for x86_64
'ubuntu-22.04', // bin/spc-gnu-docker for x86_64 'ubuntu-22.04', // bin/spc-gnu-docker for x86_64
// 'ubuntu-24.04', // bin/spc for x86_64 'ubuntu-24.04', // bin/spc for x86_64
'ubuntu-22.04-arm', // bin/spc-gnu-docker for arm64 'ubuntu-22.04-arm', // bin/spc-gnu-docker for arm64
// 'ubuntu-24.04-arm', // bin/spc for arm64 'ubuntu-24.04-arm', // bin/spc for arm64
// 'windows-latest', // .\bin\spc.ps1 // 'windows-latest', // .\bin\spc.ps1
]; ];
@ -50,13 +50,13 @@ $prefer_pre_built = false;
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
$extensions = match (PHP_OS_FAMILY) { $extensions = match (PHP_OS_FAMILY) {
'Linux', 'Darwin' => 'readline', 'Linux', 'Darwin' => 'pgsql',
'Windows' => 'bcmath,bz2,calendar,ctype,curl,dom,exif,fileinfo,filter,ftp,iconv,xml,mbstring,mbregex,mysqlnd,openssl,pdo,pdo_mysql,pdo_sqlite,phar,session,simplexml,soap,sockets,sqlite3,tokenizer,xmlwriter,xmlreader,zlib,zip', 'Windows' => 'bcmath,bz2,calendar,ctype,curl,dom,exif,fileinfo,filter,ftp,iconv,xml,mbstring,mbregex,mysqlnd,openssl,pdo,pdo_mysql,pdo_sqlite,phar,session,simplexml,soap,sockets,sqlite3,tokenizer,xmlwriter,xmlreader,zlib,zip',
}; };
// If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`). // If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`).
$shared_extensions = match (PHP_OS_FAMILY) { $shared_extensions = match (PHP_OS_FAMILY) {
'Linux' => 'grpc,imagick', 'Linux' => '',
'Darwin' => '', 'Darwin' => '',
'Windows' => '', 'Windows' => '',
}; };