From eca7a43a013bdcbe2356acf771f67c8daffd1bcb Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 24 Jul 2025 21:42:31 +0700 Subject: [PATCH] get rid of extra logic for shared and static libraries, rely on SPCConfigUtil --- src/SPC/builder/Extension.php | 42 +-------------------------- src/SPC/builder/extension/imagick.php | 11 ------- src/SPC/util/SPCConfigUtil.php | 8 ++++- src/globals/test-extensions.php | 4 +-- 4 files changed, 10 insertions(+), 55 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 79aed284..02193f58 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -400,17 +400,12 @@ class Extension public function buildUnixShared(): void { $config = (new SPCConfigUtil($this->builder))->config([$this->getName()], with_dependencies: true); - [$staticLibString, $sharedLibString] = $this->getStaticAndSharedLibs(); - // macOS ld64 doesn't understand these, while Linux and BSD do - // use them to make sure that all symbols are picked up, even if a library has already been visited before - $preStatic = PHP_OS_FAMILY !== 'Darwin' ? '-Wl,--start-group ' : ''; - $postStatic = PHP_OS_FAMILY !== 'Darwin' ? ' -Wl,--end-group ' : ' '; $env = [ 'CFLAGS' => $config['cflags'], 'CXXFLAGS' => $config['cflags'], 'LDFLAGS' => $config['ldflags'], - 'LIBS' => $preStatic . $staticLibString . $postStatic . $sharedLibString, + 'LIBS' => $config['libs'], 'LD_LIBRARY_PATH' => BUILD_LIB_PATH, 'SPC_COMPILER_EXTRA' => '-lstdc++', ]; @@ -525,41 +520,6 @@ class Extension } } - /** - * Get required static and shared libraries as a pair of strings in format -l{libname} -l{libname2} - * - * @return array [staticLibString, sharedLibString] - */ - protected function getStaticAndSharedLibs(): array - { - $config = (new SPCConfigUtil($this->builder))->config([$this->getName()], with_dependencies: true); - $sharedLibString = ''; - $staticLibString = ''; - $staticLibs = $this->getLibFilesString(); - $staticLibs = str_replace([BUILD_LIB_PATH . '/lib', '.a'], ['-l', ''], $staticLibs); - $staticLibs = explode('-l', $staticLibs . ' ' . $config['libs']); - foreach ($staticLibs as $lib) { - $lib = trim($lib); - if ($lib === '') { - continue; - } - $static_lib = 'lib' . $lib . '.a'; - if (file_exists(BUILD_LIB_PATH . '/' . $static_lib) && !str_contains($static_lib, 'libphp')) { - if (!str_contains($staticLibString, '-l' . $lib . ' ')) { - $staticLibString .= '-l' . $lib . ' '; - } - } elseif (!str_contains($sharedLibString, '-l' . $lib . ' ')) { - $sharedLibString .= '-l' . $lib . ' '; - } - } - // move -lstdc++ to static libraries because centos 7 the shared libstdc++ is incomplete - if (str_contains((string) getenv('PATH'), 'rh/devtoolset-10')) { - $staticLibString .= ' -lstdc++'; - $sharedLibString = str_replace('-lstdc++', '', $sharedLibString); - } - return [trim($staticLibString), trim($sharedLibString)]; - } - protected function getExtraEnv(): array { return []; diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php index 4067391a..514e79b3 100644 --- a/src/SPC/builder/extension/imagick.php +++ b/src/SPC/builder/extension/imagick.php @@ -6,7 +6,6 @@ namespace SPC\builder\extension; use SPC\builder\Extension; use SPC\util\CustomExt; -use SPC\util\SPCTarget; #[CustomExt('imagick')] class imagick extends Extension @@ -16,14 +15,4 @@ class imagick extends Extension $disable_omp = ' ac_cv_func_omp_pause_resource_all=no'; return '--with-imagick=' . ($shared ? 'shared,' : '') . BUILD_ROOT_PATH . $disable_omp; } - - protected function getStaticAndSharedLibs(): array - { - [$static, $shared] = parent::getStaticAndSharedLibs(); - if (SPCTarget::getLibc() === 'glibc' && version_compare(SPCTarget::getLibcVersion(), '2.17', '<=')) { - $static .= ' -lstdc++'; - $shared = str_replace('-lstdc++', '', $shared); - } - return [$static, $shared]; - } } diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index 918aac92..31242cc5 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -86,7 +86,13 @@ class SPCConfigUtil $libs .= " {$this->getFrameworksString($extensions)}"; } if ($this->builder->hasCpp()) { - $libs .= SPCTarget::getTargetOS() === 'Darwin' ? ' -lc++' : ' -lstdc++'; + $libcpp = SPCTarget::getTargetOS() === 'Darwin' ? '-lc++' : '-lstdc++'; + if (!str_contains($libs, $libcpp)) { + $libs .= " {$libcpp}"; + } + if (str_contains(getenv('OATH'), 'rh/devtoolset-10')) { + str_replace('-lstdc++', '-l:stdc++.a', $libs); + } } if ($this->libs_only_deps) { diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index f3d59190..d91817d6 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -21,9 +21,9 @@ $test_php_version = [ // 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 + // '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