Compare commits

...

7 Commits

Author SHA1 Message Date
Marc
8ff52e2e36 -lphp shared not static 2025-07-24 23:47:01 +07:00
DubbleClick
8c5dc91895 test gnu (test musl again later, jxl fails with avx shit again) 2025-07-24 22:53:19 +07:00
DubbleClick
155e22a9f9 with_dependencies was removed 2025-07-24 22:01:32 +07:00
DubbleClick
7177afd7f8 phpstan fix 2025-07-24 21:57:56 +07:00
DubbleClick
eca7a43a01 get rid of extra logic for shared and static libraries, rely on SPCConfigUtil 2025-07-24 21:42:31 +07:00
DubbleClick
dd99f258c1 do not pull it symbols from libpq during conftests... 2025-07-24 21:32:14 +07:00
DubbleClick
5c9a3e236b array_reverse again 2025-07-24 21:29:34 +07:00
7 changed files with 47 additions and 67 deletions

View File

@@ -738,8 +738,8 @@
"openssl": {
"source": "openssl",
"static-libs-unix": [
"libcrypto.a",
"libssl.a"
"libssl.a",
"libcrypto.a"
],
"static-libs-windows": [
"libssl.lib",

View File

@@ -9,6 +9,8 @@ use SPC\exception\RuntimeException;
use SPC\exception\WrongUsageException;
use SPC\store\Config;
use SPC\store\FileSystem;
use SPC\toolchain\ToolchainManager;
use SPC\toolchain\ZigToolchain;
use SPC\util\SPCConfigUtil;
use SPC\util\SPCTarget;
@@ -399,21 +401,18 @@ 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 ' : ' ';
$config = (new SPCConfigUtil($this->builder))->config([$this->getName()]);
[$staticLibs, $sharedLibs] = $this->getStaticAndSharedLibs($config['libs']);
$env = [
'CFLAGS' => $config['cflags'],
'CXXFLAGS' => $config['cflags'],
'LDFLAGS' => $config['ldflags'],
'LIBS' => $preStatic . $staticLibString . $postStatic . $sharedLibString,
'LIBS' => "-Wl,--start-group {$staticLibs} -Wl,--end-group {$sharedLibs}",
'LD_LIBRARY_PATH' => BUILD_LIB_PATH,
'SPC_COMPILER_EXTRA' => '-lstdc++',
];
if (ToolchainManager::getToolchainClass() === ZigToolchain::class) {
$env['SPC_COMPILER_EXTRA'] = '-lstdc++';
}
if ($this->patchBeforeSharedPhpize()) {
logger()->info("Extension [{$this->getName()}] patched before shared phpize");
@@ -442,7 +441,7 @@ class Extension
FileSystem::replaceFileRegex(
$this->source_dir . '/Makefile',
'/^(.*_SHARED_LIBADD\s*=.*)$/m',
'$1 ' . $staticLibString
'$1 ' . trim($staticLibs)
);
if ($this->patchBeforeSharedMake()) {
@@ -525,46 +524,27 @@ 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 [];
}
private function getStaticAndSharedLibs(string $allLibs): array
{
$staticLibString = '';
$sharedLibString = '';
$libs = explode(' ', $allLibs);
foreach ($libs as $lib) {
$staticLib = BUILD_LIB_PATH . '/lib' . str_replace('-l', '', $lib) . '.a';
if (!file_exists($staticLib) || $lib === '-lphp') {
$sharedLibString .= " {$lib}";
} else {
$staticLibString .= " {$lib}";
}
}
return [trim($staticLibString), trim($sharedLibString)];
}
private function getLibraryDependencies(bool $recursive = false): array
{
$ret = array_filter($this->dependencies, fn ($x) => $x instanceof LibraryBase);

View File

@@ -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];
}
}

View File

@@ -89,6 +89,10 @@ class LinuxBuilder extends UnixBuilderBase
// prepare build php envs
$config = (new SPCConfigUtil($this, ['libs_only_deps' => true]))->config($this->ext_list, $this->lib_list, $this->getOption('with-suggested-exts'), $this->getOption('with-suggested-libs'));
if (str_contains($config['libs'], ' -lpgport') && !$this->getExt('pgsql')?->isBuildStatic()) {
// -lpgport defines many glibc functions if they are missing, which leads to feature tests succeeding that aren't meant to succeed
$config['libs'] = str_replace(' -lpgport', '', $config['libs']);
}
$envs_build_php = SystemUtil::makeEnvVarString([
'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'),
'CPPFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS'),

View File

@@ -260,8 +260,7 @@ abstract class UnixBuilderBase extends BuilderBase
$staticFlags = '-static -static-pie';
}
$config = (new SPCConfigUtil($this))->config($this->ext_list, $this->lib_list, with_dependencies: true);
$config = (new SPCConfigUtil($this))->config($this->ext_list, $this->lib_list);
$env = [
'CGO_ENABLED' => '1',
'CGO_CFLAGS' => $config['cflags'],

View File

@@ -57,7 +57,7 @@ class SPCConfigUtil
* @throws WrongUsageException
* @throws \Throwable
*/
public function config(array $extensions = [], array $libraries = [], bool $include_suggest_ext = false, bool $include_suggest_lib = false, bool $with_dependencies = false): array
public function config(array $extensions = [], array $libraries = [], bool $include_suggest_ext = false, bool $include_suggest_lib = false): array
{
[$extensions, $libraries] = DependencyUtil::getExtsAndLibs($extensions, $libraries, $include_suggest_ext, $include_suggest_lib);
@@ -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('PATH'), 'rh/devtoolset-10')) {
str_replace('-lstdc++', '-l:stdc++.a', $libs);
}
}
if ($this->libs_only_deps) {
@@ -183,7 +189,7 @@ class SPCConfigUtil
$lib_names = [...$lib_names, ...$pc_libs];
}
// convert all static-libs to short names
$libs = Config::getLib($library, 'static-libs', []);
$libs = array_reverse(Config::getLib($library, 'static-libs', []));
foreach ($libs as $lib) {
// check file existence
if (!file_exists(BUILD_LIB_PATH . "/{$lib}")) {

View File

@@ -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
@@ -158,9 +158,11 @@ if ($shared_extensions) {
break;
case 'ubuntu-24.04':
case 'ubuntu-24.04-arm':
putenv('SPC_TARGET=native-native-musl -dynamic');
if (getenv('SPC_TARGET') && !str_contains(getenv('SPC_TARGET'), '-musl') || str_contains(getenv('SPC_TARGET'), '-dynamic')) {
putenv('SPC_TARGET=native-native-gnu');
if (getenv('SPC_TARGET') && !str_contains(getenv('SPC_TARGET'), '-musl')) {
exec('sudo apt install musl -y');
}
if (getenv('SPC_TARGET')) {
$shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' ';
}
break;