From 681a70e7f9c21b0163507d7f2da53f220e474532 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Fri, 20 Jun 2025 19:08:16 +0800 Subject: [PATCH 01/10] Skip re-extract ext-imap source --- src/SPC/store/SourceManager.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/SPC/store/SourceManager.php b/src/SPC/store/SourceManager.php index 02d07263..78c7f3f0 100644 --- a/src/SPC/store/SourceManager.php +++ b/src/SPC/store/SourceManager.php @@ -85,6 +85,13 @@ public static function initSource(?array $sources = null, ?array $libs = null, ? continue; } + // ext imap was embeded in php <= 8.3, if php version < 8.4, we should not extract + // but since it's not simple to compare php version, for now we just skip it + if ($source === 'ext-imap') { + logger()->debug('Source [imap] already extracted in ' . $check . ', skip !'); + continue; + } + // if not, remove the source dir and extract again logger()->notice("Source [{$source}] hash mismatch, removing old source dir and extracting again ..."); FileSystem::removeDir($check); From e40c43ce474c8e8e680d910a6af89f6af907a548 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Fri, 20 Jun 2025 19:15:36 +0800 Subject: [PATCH 02/10] Add some tests --- src/globals/test-extensions.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 990cbdd9..f34c94be 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -23,8 +23,8 @@ $test_os = [ // 'macos-13', // 'macos-14', - // 'macos-15', - // 'ubuntu-latest', + 'macos-15', + 'ubuntu-latest', // 'ubuntu-22.04', // 'ubuntu-24.04', 'ubuntu-22.04-arm', @@ -33,7 +33,7 @@ ]; // whether enable thread safe -$zts = true; +$zts = false; $no_strip = false; @@ -48,13 +48,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' => 'apcu,ast,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,iconv,libxml,mbregex,mbstring,opcache,openssl,pcntl,phar,posix,readline,session,simplexml,sockets,sodium,tokenizer,xml,xmlreader,xmlwriter,zip,zlib', + 'Linux', 'Darwin' => 'openssl', 'Windows' => 'xlswriter,openssl', }; // If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`). $shared_extensions = match (PHP_OS_FAMILY) { - 'Linux' => 'uv', + 'Linux' => '', 'Darwin' => '', 'Windows' => '', }; @@ -72,7 +72,7 @@ // You can use `common`, `bulk`, `minimal` or `none`. // note: combination is only available for *nix platform. Windows must use `none` combination $base_combination = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'minimal', + 'Linux', 'Darwin' => 'bulk', 'Windows' => 'none', }; From b7317858d2e03f398b805efca58f4fd2259e7885 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Fri, 20 Jun 2025 19:19:07 +0800 Subject: [PATCH 03/10] Double quote --- src/SPC/store/SourceManager.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SPC/store/SourceManager.php b/src/SPC/store/SourceManager.php index 78c7f3f0..a7835d8c 100644 --- a/src/SPC/store/SourceManager.php +++ b/src/SPC/store/SourceManager.php @@ -66,7 +66,7 @@ public static function initSource(?array $sources = null, ?array $libs = null, ? $check = LockFile::getExtractPath($lock_name, SOURCE_PATH . '/' . $source); // $check = $lock[$lock_name]['move_path'] === null ? (SOURCE_PATH . '/' . $source) : (SOURCE_PATH . '/' . $lock[$lock_name]['move_path']); if (!is_dir($check)) { - logger()->debug('Extracting source [' . $source . '] to ' . $check . ' ...'); + logger()->debug("Extracting source [{$source}] to {$check} ..."); $filename = LockFile::getLockFullPath($lock_content); FileSystem::extractSource($source, $lock_content['source_type'], $filename, $check); LockFile::putLockSourceHash($lock_content, $check); @@ -81,14 +81,14 @@ public static function initSource(?array $sources = null, ?array $libs = null, ? // when source already extracted, detect if the extracted source hash is the same as the lock file one if (file_exists("{$check}/.spc-hash") && FileSystem::readFile("{$check}/.spc-hash") === $hash) { - logger()->debug('Source [' . $source . '] already extracted in ' . $check . ', skip !'); + logger()->debug("Source [{$source}] already extracted in {$check}, skip !"); continue; } // ext imap was embeded in php <= 8.3, if php version < 8.4, we should not extract // but since it's not simple to compare php version, for now we just skip it if ($source === 'ext-imap') { - logger()->debug('Source [imap] already extracted in ' . $check . ', skip !'); + logger()->debug("Source [ext-imap] already extracted in {$check}, skip !"); continue; } From dc0c98f7b9c1ee293b59e7c582bed58afc78795f Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Fri, 20 Jun 2025 19:48:04 +0800 Subject: [PATCH 04/10] Better comment --- src/SPC/store/SourceManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/store/SourceManager.php b/src/SPC/store/SourceManager.php index a7835d8c..251e2fa1 100644 --- a/src/SPC/store/SourceManager.php +++ b/src/SPC/store/SourceManager.php @@ -85,7 +85,7 @@ public static function initSource(?array $sources = null, ?array $libs = null, ? continue; } - // ext imap was embeded in php <= 8.3, if php version < 8.4, we should not extract + // ext imap was included in php < 8.4 which we should not extract, // but since it's not simple to compare php version, for now we just skip it if ($source === 'ext-imap') { logger()->debug("Source [ext-imap] already extracted in {$check}, skip !"); From e5fee25a78865afb4445dd7b4ee2d955a4d6595f Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 21 Jun 2025 15:23:39 +0700 Subject: [PATCH 05/10] imap client requires -lcrypto for php make --- src/SPC/builder/extension/imap.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/SPC/builder/extension/imap.php b/src/SPC/builder/extension/imap.php index 9cc9a87f..c5c67bc9 100644 --- a/src/SPC/builder/extension/imap.php +++ b/src/SPC/builder/extension/imap.php @@ -5,6 +5,7 @@ namespace SPC\builder\extension; use SPC\builder\Extension; +use SPC\builder\linux\SystemUtil; use SPC\exception\WrongUsageException; use SPC\store\FileSystem; use SPC\util\CustomExt; @@ -41,4 +42,16 @@ public function getUnixConfigureArg(bool $shared = false): string } return $arg; } + + public function patchBeforeMake(): bool + { + if (PHP_OS_FAMILY !== 'Linux' || SystemUtil::isMuslDist()) { + return false; + } + $extra_libs = trim(getenv('SPC_EXTRA_LIBS') . ' -lcrypt'); + f_putenv('SPC_EXTRA_LIBS=' . $extra_libs); + return true; + } + + } From 944421584ad356d258ac11b9596ec2fc4c891d96 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 21 Jun 2025 15:50:35 +0700 Subject: [PATCH 06/10] cs --- src/SPC/builder/extension/imap.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/SPC/builder/extension/imap.php b/src/SPC/builder/extension/imap.php index c5c67bc9..f36ffb1e 100644 --- a/src/SPC/builder/extension/imap.php +++ b/src/SPC/builder/extension/imap.php @@ -52,6 +52,4 @@ public function patchBeforeMake(): bool f_putenv('SPC_EXTRA_LIBS=' . $extra_libs); return true; } - - } From 75b6cc75ea66f76cc539c71bdb3f40567721fdc3 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 21 Jun 2025 15:59:12 +0700 Subject: [PATCH 07/10] patch for building on centos 7, of course --- src/SPC/builder/linux/library/imap.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/linux/library/imap.php b/src/SPC/builder/linux/library/imap.php index 781529c6..0d094829 100644 --- a/src/SPC/builder/linux/library/imap.php +++ b/src/SPC/builder/linux/library/imap.php @@ -4,6 +4,7 @@ namespace SPC\builder\linux\library; +use SPC\builder\linux\SystemUtil; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\store\FileSystem; @@ -44,6 +45,7 @@ protected function build(): void } else { $ssl_options = 'SSLTYPE=none'; } + $ldl = SystemUtil::getLibcVersionIfExists() <= '2.17' ? 'EXTRALDFLAGS="-ldl -lrt -lpthread"' : ''; shell()->cd($this->source_dir) ->exec('make clean') ->exec('touch ip6') @@ -51,9 +53,7 @@ protected function build(): void ->exec('chmod +x tools/ua') ->exec('chmod +x src/osdep/unix/drivers') ->exec('chmod +x src/osdep/unix/mkauths') - ->exec( - "yes | make slx {$ssl_options} EXTRACFLAGS='-fPIC -fpermissive'" - ); + ->exec("yes | make slx {$ssl_options} EXTRACFLAGS='-fPIC -fpermissive' $ldl"); try { shell() ->exec("cp -rf {$this->source_dir}/c-client/c-client.a " . BUILD_LIB_PATH . '/libc-client.a') From bb1091111db67566677b29efdd1fe40e1c2dc500 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 21 Jun 2025 16:00:55 +0700 Subject: [PATCH 08/10] cs fix --- src/SPC/builder/linux/library/imap.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/linux/library/imap.php b/src/SPC/builder/linux/library/imap.php index 0d094829..c1019acd 100644 --- a/src/SPC/builder/linux/library/imap.php +++ b/src/SPC/builder/linux/library/imap.php @@ -45,7 +45,7 @@ protected function build(): void } else { $ssl_options = 'SSLTYPE=none'; } - $ldl = SystemUtil::getLibcVersionIfExists() <= '2.17' ? 'EXTRALDFLAGS="-ldl -lrt -lpthread"' : ''; + $extraLibs = SystemUtil::getLibcVersionIfExists() <= '2.17' ? 'EXTRALDFLAGS="-ldl -lrt -lpthread"' : ''; shell()->cd($this->source_dir) ->exec('make clean') ->exec('touch ip6') @@ -53,7 +53,7 @@ protected function build(): void ->exec('chmod +x tools/ua') ->exec('chmod +x src/osdep/unix/drivers') ->exec('chmod +x src/osdep/unix/mkauths') - ->exec("yes | make slx {$ssl_options} EXTRACFLAGS='-fPIC -fpermissive' $ldl"); + ->exec("yes | make slx {$ssl_options} EXTRACFLAGS='-fPIC -fpermissive' {$extraLibs}"); try { shell() ->exec("cp -rf {$this->source_dir}/c-client/c-client.a " . BUILD_LIB_PATH . '/libc-client.a') From 4efa52cee92a42a34ffafd0c0c70d8490a51c7d4 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 21 Jun 2025 16:22:33 +0700 Subject: [PATCH 09/10] imap client needs -lcrypt on glibc --- src/SPC/util/SPCConfigUtil.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index 8e69e89c..f9266dbd 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -149,6 +149,9 @@ private function getLibsString(array $libraries, bool $withDependencies = false) if (in_array('imagemagick', $libraries) && PHP_OS_FAMILY === 'Linux' && !(getenv('SPC_LIBC') === 'glibc' && str_contains(getenv('CC'), 'devtoolset-10'))) { $short_name[] = '-lgomp'; } + if (in_array('imap', $libraries) && PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') === 'glibc') { + $short_name[] = '-lcrypt'; + } return implode(' ', $short_name); } From 02114c04ed9b1178d96cac4f89bbd5bfaf5aaa7c Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 21 Jun 2025 16:34:47 +0700 Subject: [PATCH 10/10] fix php-config libraries for imagemagick and imap --- src/SPC/builder/LibraryBase.php | 9 +++++++++ src/SPC/builder/linux/library/imagemagick.php | 11 +++++++++++ src/SPC/builder/linux/library/imap.php | 9 +++++++++ src/SPC/builder/unix/UnixBuilderBase.php | 5 +++++ 4 files changed, 34 insertions(+) diff --git a/src/SPC/builder/LibraryBase.php b/src/SPC/builder/LibraryBase.php index fc6adefc..ce017ea0 100644 --- a/src/SPC/builder/LibraryBase.php +++ b/src/SPC/builder/LibraryBase.php @@ -332,6 +332,15 @@ public function patchBeforeMake(): bool return false; } + /** + * Patch php-config after embed was built + * Example: imagemagick requires -lgomp, imap requires -lcrypt + */ + public function patchPhpConfig(): bool + { + return false; + } + /** * Build this library. * diff --git a/src/SPC/builder/linux/library/imagemagick.php b/src/SPC/builder/linux/library/imagemagick.php index 6006a222..ab51badb 100644 --- a/src/SPC/builder/linux/library/imagemagick.php +++ b/src/SPC/builder/linux/library/imagemagick.php @@ -4,6 +4,8 @@ namespace SPC\builder\linux\library; +use SPC\store\FileSystem; + /** * a template library class for unix */ @@ -12,4 +14,13 @@ class imagemagick extends LinuxLibraryBase use \SPC\builder\unix\library\imagemagick; public const NAME = 'imagemagick'; + + public function patchPhpConfig(): bool + { + if (getenv('SPC_LIBC') !== 'glibc' || !str_contains(getenv('CC'), 'devtoolset-10')) { + FileSystem::replaceFileRegex(BUILD_BIN_PATH . '/php-config', '/^libs="(.*)"$/m', 'libs="$1 -lgomp"'); + return true; + } + return false; + } } diff --git a/src/SPC/builder/linux/library/imap.php b/src/SPC/builder/linux/library/imap.php index c1019acd..d4b68f19 100644 --- a/src/SPC/builder/linux/library/imap.php +++ b/src/SPC/builder/linux/library/imap.php @@ -35,6 +35,15 @@ public function patchBeforeBuild(): bool return true; } + public function patchPhpConfig(): bool + { + if (getenv('SPC_LIBC') === 'glibc') { + FileSystem::replaceFileRegex(BUILD_BIN_PATH . '/php-config', '/^libs="(.*)"$/m', 'libs="$1 -lcrypt"'); + return true; + } + return false; + } + /** * @throws RuntimeException */ diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 0d56b0eb..b4c27079 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -293,6 +293,11 @@ protected function patchPhpScripts(): void $php_config_str = preg_replace('/(libs=")(.*?)\s*(-lstdc\+\+)\s*(.*?)"/', '$1$2 $4 $3"', $php_config_str); FileSystem::writeFile(BUILD_BIN_PATH . '/php-config', $php_config_str); } + foreach ($this->getLibs() as $lib) { + if ($lib->patchPhpConfig()) { + logger()->debug("Library {$lib->getName()} patched php-config"); + } + } } /**