From 3966bd5f0ae90119335c4ea23a773dbe14136e2e Mon Sep 17 00:00:00 2001 From: henderkes Date: Mon, 6 Oct 2025 20:06:37 +0200 Subject: [PATCH 01/20] update pgsql version to 18.0 --- config/source.json | 2 +- src/SPC/builder/unix/library/postgresql.php | 39 +++++++-------------- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/config/source.json b/config/source.json index 4a0e0fdb5..450b7b3c6 100644 --- a/config/source.json +++ b/config/source.json @@ -880,7 +880,7 @@ "postgresql": { "type": "ghtagtar", "repo": "postgres/postgres", - "match": "REL_16_\\d+", + "match": "REL_18_\\d+", "license": { "type": "file", "path": "COPYRIGHT" diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index 3bc6835dd..0a3489a13 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -6,7 +6,6 @@ use SPC\builder\linux\library\LinuxLibraryBase; use SPC\exception\BuildFailureException; -use SPC\exception\FileSystemException; use SPC\store\FileSystem; use SPC\util\SPCTarget; @@ -65,17 +64,18 @@ protected function build(): void FileSystem::resetDir($this->source_dir . '/build'); - $version = $this->getVersion(); - // 16.1 workaround - if (version_compare($version, '16.1') >= 0) { - # 有静态链接配置 参考文件: src/interfaces/libpq/Makefile - shell()->cd($this->source_dir . '/build') - ->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 . ' !'); - } + # 有静态链接配置 参考文件: src/interfaces/libpq/Makefile + shell()->cd($this->source_dir . '/build') + ->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'); + + // php source relies on the non-private encoding functions in libpgcommon.a + FileSystem::replaceFileStr( + $this->source_dir . '/src/common/Makefile', + '$(OBJS_FRONTEND): CPPFLAGS += -DUSE_PRIVATE_ENCODING_FUNCS', + '$(OBJS_FRONTEND): CPPFLAGS += -UUSE_PRIVATE_ENCODING_FUNCS', + ); // configure shell()->cd($this->source_dir . '/build')->initializeEnv($this) @@ -83,14 +83,12 @@ protected function build(): void ->exec( "{$envs} ../configure " . "--prefix={$builddir} " . - ($this->builder->getOption('enable-zts') ? '--enable-thread-safety ' : '--disable-thread-safety ') . '--enable-coverage=no ' . '--with-ssl=openssl ' . '--with-readline ' . '--with-libxml ' . ($this->builder->getLib('icu') ? '--with-icu ' : '--without-icu ') . ($this->builder->getLib('ldap') ? '--with-ldap ' : '--without-ldap ') . - // '--without-ldap ' . ($this->builder->getLib('libxslt') ? '--with-libxslt ' : '--without-libxslt ') . ($this->builder->getLib('zstd') ? '--with-zstd ' : '--without-zstd ') . '--without-lz4 ' . @@ -114,17 +112,4 @@ protected function build(): void FileSystem::replaceFileStr(BUILD_LIB_PATH . '/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'; - } - } } From 8ae2755dbe8badcbb37b48bfea067060a97ed205 Mon Sep 17 00:00:00 2001 From: henderkes Date: Mon, 6 Oct 2025 20:14:52 +0200 Subject: [PATCH 02/20] update php 8.5 to rc1 --- src/SPC/store/source/PhpSource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/store/source/PhpSource.php b/src/SPC/store/source/PhpSource.php index c33e172f3..4df1d8884 100644 --- a/src/SPC/store/source/PhpSource.php +++ b/src/SPC/store/source/PhpSource.php @@ -16,7 +16,7 @@ public function fetch(bool $force = false, ?array $config = null, int $lock_as = { $major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.4'; if ($major === '8.5') { - Downloader::downloadSource('php-src', ['type' => 'url', 'url' => 'https://downloads.php.net/~edorian/php-8.5.0beta1.tar.xz'], $force); + Downloader::downloadSource('php-src', ['type' => 'url', 'url' => 'https://github.com/php/php-src/archive/refs/tags/php-8.5.0RC1.tar.gz'], $force); } elseif ($major === 'git') { Downloader::downloadSource('php-src', ['type' => 'git', 'url' => 'https://github.com/php/php-src.git', 'rev' => 'master'], $force); } else { From 0f2d2d573490984fd96fb40ad213536b3b1bfbcd Mon Sep 17 00:00:00 2001 From: henderkes Date: Mon, 6 Oct 2025 21:03:57 +0200 Subject: [PATCH 03/20] test pgsql without macos 13 --- src/globals/test-extensions.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 764cfc7d3..9a8924ee2 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -23,14 +23,14 @@ // test os (macos-13, macos-14, macos-15, ubuntu-latest, windows-latest are available) $test_os = [ - 'macos-13', // bin/spc for x86_64 + // 'macos-13', // bin/spc for x86_64 // 'macos-14', // bin/spc for arm64 'macos-15', // bin/spc for arm64 'ubuntu-latest', // bin/spc-alpine-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-24.04-arm', // bin/spc for arm64 + 'ubuntu-24.04-arm', // bin/spc for arm64 // 'windows-latest', // .\bin\spc.ps1 ]; @@ -50,13 +50,13 @@ // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'bcmath', + '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', }; // If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`). $shared_extensions = match (PHP_OS_FAMILY) { - 'Linux' => 'zip', + 'Linux' => '', 'Darwin' => '', 'Windows' => '', }; From c4440668bbc5786b3ed36a87953f40140c382b9e Mon Sep 17 00:00:00 2001 From: henderkes Date: Mon, 6 Oct 2025 21:28:57 +0200 Subject: [PATCH 04/20] make sure -DFRONTEND is used --- src/SPC/builder/unix/library/postgresql.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index 0a3489a13..ae5e35f30 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -56,7 +56,7 @@ protected function build(): void if ($this->builder->getLib('icu')) { $libcpp = $this instanceof LinuxLibraryBase ? ' -lstdc++' : ' -lc++'; } - $envs .= " LIBS=\"{$libs}{$libcpp}\" "; + $envs .= " LIBS=\"{$libs} {$libs}{$libcpp}\" "; // macOS doesn't understand how to link properly } if ($error_exec_cnt > 0) { throw new BuildFailureException('Failed to get pkg-config information!'); @@ -74,7 +74,7 @@ protected function build(): void FileSystem::replaceFileStr( $this->source_dir . '/src/common/Makefile', '$(OBJS_FRONTEND): CPPFLAGS += -DUSE_PRIVATE_ENCODING_FUNCS', - '$(OBJS_FRONTEND): CPPFLAGS += -UUSE_PRIVATE_ENCODING_FUNCS', + '$(OBJS_FRONTEND): CPPFLAGS += -UUSE_PRIVATE_ENCODING_FUNCS -DFRONTEND', ); // configure From 6c43fa55b10948b34dd50024c0f19c8d13af9eee Mon Sep 17 00:00:00 2001 From: henderkes Date: Mon, 6 Oct 2025 21:37:36 +0200 Subject: [PATCH 05/20] don't use -static, shared libraries cannot link against static musl libc and linking isn't done for static libraries yet --- src/SPC/builder/unix/library/postgresql.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index ae5e35f30..6d4cf804d 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -7,7 +7,6 @@ use SPC\builder\linux\library\LinuxLibraryBase; use SPC\exception\BuildFailureException; use SPC\store\FileSystem; -use SPC\util\SPCTarget; trait postgresql { @@ -46,7 +45,7 @@ protected function build(): void $error_exec_cnt += $output[0] === 0 ? 0 : 1; if (!empty($output[1][0])) { $ldflags = $output[1][0]; - $envs .= SPCTarget::isStatic() ? " LDFLAGS=\"{$ldflags} -static\" " : " LDFLAGS=\"{$ldflags}\" "; + $envs .= " LDFLAGS=\"{$ldflags}\" "; } $output = shell()->execWithResult("pkg-config --libs-only-l --static {$packages}"); $error_exec_cnt += $output[0] === 0 ? 0 : 1; From 781260f3fce28c82e6ff2cfe6963d867250e1972 Mon Sep 17 00:00:00 2001 From: henderkes Date: Mon, 6 Oct 2025 22:10:28 +0200 Subject: [PATCH 06/20] attempt fix for aarch64 --- src/SPC/builder/unix/library/postgresql.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index 6d4cf804d..1c492665e 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -7,9 +7,23 @@ use SPC\builder\linux\library\LinuxLibraryBase; use SPC\exception\BuildFailureException; use SPC\store\FileSystem; +use SPC\util\SPCTarget; trait postgresql { + public function patchBeforeBuild(): bool + { + if (SPCTarget::getLibcVersion() === '2.17' && GNU_ARCH === 'aarch64') { + 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)', + ); + return true; + } + return false; + } + protected function build(): void { $builddir = BUILD_ROOT_PATH; @@ -55,7 +69,7 @@ protected function build(): void if ($this->builder->getLib('icu')) { $libcpp = $this instanceof LinuxLibraryBase ? ' -lstdc++' : ' -lc++'; } - $envs .= " LIBS=\"{$libs} {$libs}{$libcpp}\" "; // macOS doesn't understand how to link properly + $envs .= " LIBS=\"{$libs}{$libcpp}\" "; } if ($error_exec_cnt > 0) { throw new BuildFailureException('Failed to get pkg-config information!'); From 17a25b44e280def78a2a5b23dfecf5c35754510f Mon Sep 17 00:00:00 2001 From: henderkes Date: Mon, 6 Oct 2025 22:26:00 +0200 Subject: [PATCH 07/20] attempt fix for aarch64 #2 --- src/SPC/builder/unix/library/postgresql.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index 1c492665e..476c055d2 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -14,6 +14,11 @@ 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', + 'value & HWCAP_SVE', + 'value & 0', + ); FileSystem::replaceFileStr( $this->source_dir . '/src/port/pg_crc32c_armv8_choose.c', '#if defined(__linux__) && !defined(__aarch64__) && !defined(HWCAP2_CRC32)', From d789b1a472b7f62473eb24bc79930fc0897ef71a Mon Sep 17 00:00:00 2001 From: henderkes Date: Mon, 6 Oct 2025 22:31:23 +0200 Subject: [PATCH 08/20] fix musl toolchain (needs LD_LIBRARY_PATH) --- src/SPC/builder/unix/library/postgresql.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index 476c055d2..adf047731 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -95,9 +95,16 @@ protected function build(): void '$(OBJS_FRONTEND): CPPFLAGS += -UUSE_PRIVATE_ENCODING_FUNCS -DFRONTEND', ); + $env = [ + 'CFLAGS' => $cflags, + ]; + if ($ldLibraryPath = getenv('SPC_LD_LIBRARY_PATH')) { + $env['LD_LIBRARY_PATH'] = $ldLibraryPath; + } + // configure shell()->cd($this->source_dir . '/build')->initializeEnv($this) - ->appendEnv(['CFLAGS' => $cflags]) + ->appendEnv($env) ->exec( "{$envs} ../configure " . "--prefix={$builddir} " . From 9ee623112d3baf9dccc992bc625c157d6b79714e Mon Sep 17 00:00:00 2001 From: henderkes Date: Mon, 6 Oct 2025 22:43:03 +0200 Subject: [PATCH 09/20] attempt to fix macOS? --- src/SPC/builder/unix/library/postgresql.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index adf047731..46973ef58 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -103,7 +103,7 @@ protected function build(): void } // configure - shell()->cd($this->source_dir . '/build')->initializeEnv($this) + $shell = shell()->cd($this->source_dir . '/build')->initializeEnv($this) ->appendEnv($env) ->exec( "{$envs} ../configure " . @@ -122,7 +122,13 @@ protected function build(): void '--without-pam ' . '--without-bonjour ' . '--without-tcl ' - ) + ); + + if (SPCTarget::getTargetOS() === 'Darwin') { + FileSystem::replaceFileStr($this->source_dir . '/build/src/Makefile.global', '-lldap', '-lldap -llber'); + } + + $shell ->exec($envs . ' make -C src/bin/pg_config install') ->exec($envs . ' make -C src/include install') ->exec($envs . ' make -C src/common install') From 864db0ebc5ee543640afda7d48fe373f2a3a99ff Mon Sep 17 00:00:00 2001 From: henderkes Date: Mon, 6 Oct 2025 22:48:14 +0200 Subject: [PATCH 10/20] fix macos finally I hope --- src/SPC/builder/unix/library/postgresql.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index 46973ef58..25d74cf0b 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -7,6 +7,7 @@ use SPC\builder\linux\library\LinuxLibraryBase; use SPC\exception\BuildFailureException; use SPC\store\FileSystem; +use SPC\util\PkgConfigUtil; use SPC\util\SPCTarget; trait postgresql @@ -124,9 +125,10 @@ protected function build(): void '--without-tcl ' ); - if (SPCTarget::getTargetOS() === 'Darwin') { - FileSystem::replaceFileStr($this->source_dir . '/build/src/Makefile.global', '-lldap', '-lldap -llber'); - } + $libs = PkgConfigUtil::getLibsArray('ldap'); + $libs = clean_spaces(implode(' ', $libs)); + FileSystem::replaceFileStr($this->source_dir . '/build/src/Makefile.global', '-lldap', $libs); + FileSystem::replaceFileStr($this->source_dir . '/build/Makefile.status', '-lldap', $libs); $shell ->exec($envs . ' make -C src/bin/pg_config install') From 15cd8543f154e30530d5ccb2dda9778751bfafa2 Mon Sep 17 00:00:00 2001 From: henderkes Date: Mon, 6 Oct 2025 22:50:37 +0200 Subject: [PATCH 11/20] arm64 fix --- src/SPC/builder/unix/library/postgresql.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index 25d74cf0b..4e3c4f7b0 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -17,8 +17,8 @@ public function patchBeforeBuild(): bool if (SPCTarget::getLibcVersion() === '2.17' && GNU_ARCH === 'aarch64') { FileSystem::replaceFileStr( $this->source_dir . '/src/port/pg_popcount_aarch64.c', - 'value & HWCAP_SVE', - 'value & 0', + 'HWCAP_SVE', + '0', ); FileSystem::replaceFileStr( $this->source_dir . '/src/port/pg_crc32c_armv8_choose.c', From 3467c9d2911991d3db4a714d03e2028ad606aa82 Mon Sep 17 00:00:00 2001 From: henderkes Date: Mon, 6 Oct 2025 22:53:41 +0200 Subject: [PATCH 12/20] patch correct file --- src/SPC/builder/unix/library/postgresql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index 4e3c4f7b0..3b7754663 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -127,8 +127,8 @@ protected function build(): void $libs = PkgConfigUtil::getLibsArray('ldap'); $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); - FileSystem::replaceFileStr($this->source_dir . '/build/Makefile.status', '-lldap', $libs); $shell ->exec($envs . ' make -C src/bin/pg_config install') From fa4d33671dc5f0e14e18f0d3fafb7a3a9f1bfa7f Mon Sep 17 00:00:00 2001 From: henderkes Date: Fri, 10 Oct 2025 18:35:15 +0200 Subject: [PATCH 13/20] update to RC2 --- src/SPC/store/source/PhpSource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/store/source/PhpSource.php b/src/SPC/store/source/PhpSource.php index 4df1d8884..38861427a 100644 --- a/src/SPC/store/source/PhpSource.php +++ b/src/SPC/store/source/PhpSource.php @@ -16,7 +16,7 @@ public function fetch(bool $force = false, ?array $config = null, int $lock_as = { $major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.4'; if ($major === '8.5') { - Downloader::downloadSource('php-src', ['type' => 'url', 'url' => 'https://github.com/php/php-src/archive/refs/tags/php-8.5.0RC1.tar.gz'], $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') { Downloader::downloadSource('php-src', ['type' => 'git', 'url' => 'https://github.com/php/php-src.git', 'rev' => 'master'], $force); } else { From 8a1689b79d4eded2e6b0c30f7ef1aa07a966ecf7 Mon Sep 17 00:00:00 2001 From: henderkes Date: Sat, 11 Oct 2025 13:20:08 +0200 Subject: [PATCH 14/20] don't fail build without ldap --- src/SPC/builder/unix/library/postgresql.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index 3b7754663..543963006 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -44,7 +44,7 @@ protected function build(): void $error_exec_cnt = 0; foreach ($optional_packages as $lib => $pkg) { - if ($this->getBuilder()->getLib($lib)) { + if ($this->builder->getLib($lib)) { $packages .= ' ' . $pkg; $output = shell()->execWithResult("pkg-config --static {$pkg}"); $error_exec_cnt += $output[0] === 0 ? 0 : 1; @@ -125,10 +125,12 @@ protected function build(): void '--without-tcl ' ); - $libs = PkgConfigUtil::getLibsArray('ldap'); - $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); + if ($this->builder->getLib('ldap')) { + $libs = PkgConfigUtil::getLibsArray('ldap'); + $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($envs . ' make -C src/bin/pg_config install') From 6bd3eea0fe5418ad2527548ea81dc6461128da1b Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 12 Oct 2025 23:54:59 +0800 Subject: [PATCH 15/20] Use SPCConfigUtil for postgresql build, refactor patches --- src/SPC/builder/unix/library/postgresql.php | 119 +++++++------------- 1 file changed, 43 insertions(+), 76 deletions(-) diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index 543963006..dfb990068 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -4,10 +4,9 @@ namespace SPC\builder\unix\library; -use SPC\builder\linux\library\LinuxLibraryBase; -use SPC\exception\BuildFailureException; use SPC\store\FileSystem; use SPC\util\PkgConfigUtil; +use SPC\util\SPCConfigUtil; use SPC\util\SPCTarget; trait postgresql @@ -25,90 +24,57 @@ public function patchBeforeBuild(): bool '#if defined(__linux__) && !defined(__aarch64__) && !defined(HWCAP2_CRC32)', '#if defined(__linux__) && !defined(HWCAP_CRC32)', ); - return true; } - return false; + // 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 { - $builddir = BUILD_ROOT_PATH; - $envs = ''; - $packages = 'zlib openssl readline libxml-2.0'; - $optional_packages = [ - 'zstd' => 'libzstd', - 'ldap' => 'ldap', - 'libxslt' => 'libxslt', - 'icu' => 'icu-i18n', - ]; - $error_exec_cnt = 0; - - foreach ($optional_packages as $lib => $pkg) { - if ($this->builder->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)); - } - } + $libs = array_map(fn ($x) => $x->getName(), $this->getDependencies()); + $spc = new SPCConfigUtil($this->getBuilder(), ['no_php' => true, 'libs_only_deps' => true]); + $config = $spc->config(libraries: $libs); - $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' : ''; - $cflags = ''; - if (!empty($output[1][0])) { - $cflags = $output[1][0]; - $envs .= ' CPPFLAGS="-DPIC"'; - $cflags = "{$cflags} -fno-ident{$macos_15_bug_cflags}"; - } - $output = shell()->execWithResult("pkg-config --libs-only-L --static {$packages}"); - $error_exec_cnt += $output[0] === 0 ? 0 : 1; - if (!empty($output[1][0])) { - $ldflags = $output[1][0]; - $envs .= " 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!'); + + $env_vars = [ + 'CFLAGS' => "{$config['cflags']} -fno-ident{$macos_15_bug_cflags}", + 'CPPFLAGS' => '-DPIC', + 'LDFLAGS' => $config['ldflags'], + 'LIBS' => $config['libs'], + ]; + + if ($ldLibraryPath = getenv('SPC_LD_LIBRARY_PATH')) { + $env_vars['LD_LIBRARY_PATH'] = $ldLibraryPath; } FileSystem::resetDir($this->source_dir . '/build'); - # 有静态链接配置 参考文件: src/interfaces/libpq/Makefile - shell()->cd($this->source_dir . '/build') - ->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'); - // php source relies on the non-private encoding functions in libpgcommon.a FileSystem::replaceFileStr( - $this->source_dir . '/src/common/Makefile', + "{$this->source_dir}/src/common/Makefile", '$(OBJS_FRONTEND): CPPFLAGS += -DUSE_PRIVATE_ENCODING_FUNCS', '$(OBJS_FRONTEND): CPPFLAGS += -UUSE_PRIVATE_ENCODING_FUNCS -DFRONTEND', ); - $env = [ - 'CFLAGS' => $cflags, - ]; - if ($ldLibraryPath = getenv('SPC_LD_LIBRARY_PATH')) { - $env['LD_LIBRARY_PATH'] = $ldLibraryPath; - } - // configure - $shell = shell()->cd($this->source_dir . '/build')->initializeEnv($this) - ->appendEnv($env) + $shell = shell()->cd("{$this->source_dir}/build")->initializeEnv($this) + ->appendEnv($env_vars) ->exec( - "{$envs} ../configure " . - "--prefix={$builddir} " . + '../configure ' . + "--prefix={$this->getBuildRootPath()} " . '--enable-coverage=no ' . '--with-ssl=openssl ' . '--with-readline ' . @@ -125,6 +91,7 @@ protected function build(): void '--without-tcl ' ); + // patch ldap lib if ($this->builder->getLib('ldap')) { $libs = PkgConfigUtil::getLibsArray('ldap'); $libs = clean_spaces(implode(' ', $libs)); @@ -133,18 +100,18 @@ protected function build(): void } $shell - ->exec($envs . ' make -C src/bin/pg_config install') - ->exec($envs . ' make -C src/include install') - ->exec($envs . ' make -C src/common install') - ->exec($envs . ' make -C src/port install') - ->exec($envs . ' make -C src/interfaces/libpq install'); + ->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 shell()->cd($this->source_dir . '/build') - ->exec("rm -rf {$builddir}/lib/*.so.*") - ->exec("rm -rf {$builddir}/lib/*.so") - ->exec("rm -rf {$builddir}/lib/*.dylib"); + ->exec("rm -rf {$this->getBuildRootPath()}/lib/*.so.*") + ->exec("rm -rf {$this->getBuildRootPath()}/lib/*.so") + ->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'); } } From 903036f1c0138fc5afe14ac753c496e9b4b0b80c Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 13 Oct 2025 00:00:31 +0800 Subject: [PATCH 16/20] Bump version --- src/SPC/ConsoleApplication.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/ConsoleApplication.php b/src/SPC/ConsoleApplication.php index 023b541e6..ba2d38e0b 100644 --- a/src/SPC/ConsoleApplication.php +++ b/src/SPC/ConsoleApplication.php @@ -34,7 +34,7 @@ */ final class ConsoleApplication extends Application { - public const string VERSION = '2.7.4'; + public const string VERSION = '2.7.5'; public function __construct() { From 6e79401ab5c8668eea7d1056640bab0bfe9659f8 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 13 Oct 2025 00:21:13 +0800 Subject: [PATCH 17/20] Add missing libs for suggested option defined --- src/SPC/builder/unix/library/postgresql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index dfb990068..f7781be06 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -45,7 +45,7 @@ protected function build(): void { $libs = array_map(fn ($x) => $x->getName(), $this->getDependencies()); $spc = new SPCConfigUtil($this->getBuilder(), ['no_php' => true, 'libs_only_deps' => true]); - $config = $spc->config(libraries: $libs); + $config = $spc->config(libraries: $libs, include_suggest_lib: $this->builder->getOption('with-suggested-libs')); $macos_15_bug_cflags = PHP_OS_FAMILY === 'Darwin' ? ' -Wno-unguarded-availability-new' : ''; From 19be5263b5f848fb76b2010b01aa386ed641e4d9 Mon Sep 17 00:00:00 2001 From: henderkes Date: Sun, 12 Oct 2025 22:26:06 +0200 Subject: [PATCH 18/20] add error --- src/SPC/builder/linux/LinuxBuilder.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 1abda58da..93c28b324 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -156,6 +156,9 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void } $shared_extensions = array_map('trim', array_filter(explode(',', $this->getOption('build-shared')))); if (!empty($shared_extensions)) { + if (SPCTarget::isStatic()) { + throw new WrongUsageException("You're building against musl libc statically, but you're trying to build shared extensions. Musl libc does not implement `dlopen`, so your php binary is not able to load shared extensions."); + } logger()->info('Building shared extensions ...'); $this->buildSharedExts(); } From 5333a04e1ccf2813a3e32e536df2ae093e248b71 Mon Sep 17 00:00:00 2001 From: henderkes Date: Sun, 12 Oct 2025 22:27:38 +0200 Subject: [PATCH 19/20] clarification --- src/SPC/builder/linux/LinuxBuilder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 93c28b324..0ddb20818 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -157,9 +157,9 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $shared_extensions = array_map('trim', array_filter(explode(',', $this->getOption('build-shared')))); if (!empty($shared_extensions)) { if (SPCTarget::isStatic()) { - throw new WrongUsageException("You're building against musl libc statically, but you're trying to build shared extensions. Musl libc does not implement `dlopen`, so your php binary is not able to load shared extensions."); + throw new WrongUsageException("You're building against musl libc statically, but you're trying to build shared extensions. Static musl libc does not implement `dlopen`, so your php binary is not able to load shared extensions."); } - logger()->info('Building shared extensions ...'); + logger()->info('Building shared extensions...'); $this->buildSharedExts(); } } From 995187d258edf48e573a5462cdcfe6430a109f6e Mon Sep 17 00:00:00 2001 From: henderkes Date: Sun, 12 Oct 2025 22:32:27 +0200 Subject: [PATCH 20/20] extra information for steps --- src/SPC/builder/linux/LinuxBuilder.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 0ddb20818..299cdb644 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -157,7 +157,11 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $shared_extensions = array_map('trim', array_filter(explode(',', $this->getOption('build-shared')))); if (!empty($shared_extensions)) { if (SPCTarget::isStatic()) { - throw new WrongUsageException("You're building against musl libc statically, but you're trying to build shared extensions. Static musl libc does not implement `dlopen`, so your php binary is not able to load shared extensions."); + 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();