From 7177afd7f82276418c4aaf4dd5fb7fd6a80cf3bb Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 24 Jul 2025 21:57:56 +0700 Subject: [PATCH] phpstan fix --- src/SPC/builder/Extension.php | 20 ++++++++++++++++---- src/SPC/util/SPCConfigUtil.php | 4 ++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 02193f58..6c18222d 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -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,16 +401,17 @@ class Extension */ public function buildUnixShared(): void { - $config = (new SPCConfigUtil($this->builder))->config([$this->getName()], with_dependencies: true); - + $config = (new SPCConfigUtil($this->builder))->config([$this->getName()]); $env = [ 'CFLAGS' => $config['cflags'], 'CXXFLAGS' => $config['cflags'], 'LDFLAGS' => $config['ldflags'], 'LIBS' => $config['libs'], '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"); @@ -433,11 +436,20 @@ class Extension '--enable-shared --disable-static' ); + $staticLibString = ''; + $libs = explode(' ', $config['libs']); + foreach ($libs as $lib) { + $staticLib = BUILD_LIB_PATH . '/' . str_replace('-l', '', $lib) . '.a'; + if (file_exists($staticLib)) { + $staticLibString .= " {$lib}"; + } + } + // some extensions don't define their dependencies well, this patch is only needed for a few FileSystem::replaceFileRegex( $this->source_dir . '/Makefile', '/^(.*_SHARED_LIBADD\s*=.*)$/m', - '$1 ' . $staticLibString + '$1 ' . trim($staticLibString) ); if ($this->patchBeforeSharedMake()) { diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index 31242cc5..83c33fa7 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -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); @@ -90,7 +90,7 @@ class SPCConfigUtil if (!str_contains($libs, $libcpp)) { $libs .= " {$libcpp}"; } - if (str_contains(getenv('OATH'), 'rh/devtoolset-10')) { + if (str_contains(getenv('PATH'), 'rh/devtoolset-10')) { str_replace('-lstdc++', '-l:stdc++.a', $libs); } }