From 404b2dca24c50dbdab71bcb0b94e942e96f63d40 Mon Sep 17 00:00:00 2001 From: henderkes Date: Tue, 21 Jul 2026 10:17:30 +0700 Subject: [PATCH] fix smth --- src/StaticPHP/Package/PhpExtensionPackage.php | 2 +- .../Runtime/Executor/UnixCMakeExecutor.php | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/StaticPHP/Package/PhpExtensionPackage.php b/src/StaticPHP/Package/PhpExtensionPackage.php index c638114d..8a6dc4bc 100644 --- a/src/StaticPHP/Package/PhpExtensionPackage.php +++ b/src/StaticPHP/Package/PhpExtensionPackage.php @@ -275,7 +275,7 @@ class PhpExtensionPackage extends Package $compiler_extra = trim($compiler_extra . ' -lcompiler_rt'); GlobalEnvManager::putenv("SPC_COMPILER_EXTRA={$compiler_extra}"); } - $config = (new SPCConfigUtil())->getExtensionConfig($this); + $config = new SPCConfigUtil(['no_php' => true])->getExtensionConfig($this); [$staticLibs, $sharedLibs] = $this->splitLibsIntoStaticAndShared($config['libs']); $preStatic = PHP_OS_FAMILY === 'Darwin' ? '' : '-Wl,--start-group '; $postStatic = PHP_OS_FAMILY === 'Darwin' ? '' : ' -Wl,--end-group '; diff --git a/src/StaticPHP/Runtime/Executor/UnixCMakeExecutor.php b/src/StaticPHP/Runtime/Executor/UnixCMakeExecutor.php index 9fc00840..bf60b687 100644 --- a/src/StaticPHP/Runtime/Executor/UnixCMakeExecutor.php +++ b/src/StaticPHP/Runtime/Executor/UnixCMakeExecutor.php @@ -228,8 +228,15 @@ class UnixCMakeExecutor extends Executor "-DCMAKE_TOOLCHAIN_FILE={$this->makeCmakeToolchainFile()}", ]; - // EXE linker flags: base system libs + framework flags for target packages - $exeLinkerFlags = SystemTarget::getRuntimeLibs(); + // EXE linker flags: framework flags for target packages (Darwin). On Linux the + // runtime libs (-ldl & co.) are NOT passed here: CMake puts EXE_LINKER_FLAGS before + // the objects/archives, where -Wl,--as-needed (Debian gcc default, and our own + // LDFLAGS) discards them and breaks try_compile probes linking static archives that + // need them (curl's SSL_set_quic_tls_cbs check vs libcrypto.a needing dlopen on + // glibc < 2.34). They go into the toolchain file as CMAKE__STANDARD_LIBRARIES + // instead, which cmake appends AFTER the objects — correct order, as-needed intact, + // and the toolchain file is re-evaluated inside every try_compile. + $exeLinkerFlags = SystemTarget::getTargetOS() === 'Linux' ? '' : SystemTarget::getRuntimeLibs(); if ($this->package instanceof TargetPackage && SystemTarget::getTargetOS() === 'Darwin') { $resolvedNames = array_keys($this->installer->getResolvedPackages()); $resolvedNames[] = $this->package->getName(); @@ -308,6 +315,14 @@ CMAKE; $ranlib = getenv('SPC_DEFAULT_RANLIB') ?: (getenv('RANLIB') ?: 'ranlib'); $toolchain .= "\nSET(CMAKE_AR \"{$ar}\")"; $toolchain .= "\nSET(CMAKE_RANLIB \"{$ranlib}\")"; + // Runtime libs as standard libraries: appended after objects/archives on every + // link line (incl. try_compile probes), so -Wl,--as-needed keeps the ones that + // are actually referenced. + $runtimeLibs = SystemTarget::getRuntimeLibs(); + if ($runtimeLibs !== '') { + $toolchain .= "\nset(CMAKE_C_STANDARD_LIBRARIES_INIT \"{$runtimeLibs}\")"; + $toolchain .= "\nset(CMAKE_CXX_STANDARD_LIBRARIES_INIT \"{$runtimeLibs}\")"; + } } FileSystem::writeFile(SOURCE_PATH . '/toolchain.cmake', $toolchain); return $created = realpath(SOURCE_PATH . '/toolchain.cmake');