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/extension/imap.php b/src/SPC/builder/extension/imap.php index 9cc9a87f..f36ffb1e 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,14 @@ 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; + } } 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 781529c6..d4b68f19 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; @@ -34,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 */ @@ -44,6 +54,7 @@ protected function build(): void } else { $ssl_options = 'SSLTYPE=none'; } + $extraLibs = SystemUtil::getLibcVersionIfExists() <= '2.17' ? 'EXTRALDFLAGS="-ldl -lrt -lpthread"' : ''; shell()->cd($this->source_dir) ->exec('make clean') ->exec('touch ip6') @@ -51,9 +62,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' {$extraLibs}"); try { shell() ->exec("cp -rf {$this->source_dir}/c-client/c-client.a " . BUILD_LIB_PATH . '/libc-client.a') 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"); + } + } } /** diff --git a/src/SPC/store/SourceManager.php b/src/SPC/store/SourceManager.php index 02d07263..251e2fa1 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,7 +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 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 !"); continue; } 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); } 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', };