mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-19 13:24:51 +08:00
get rid of extra logic for shared and static libraries, rely on SPCConfigUtil
This commit is contained in:
parent
dd99f258c1
commit
eca7a43a01
@ -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 [];
|
||||
|
||||
@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user