diff --git a/config/ext.json b/config/ext.json index cc6b067d..16920649 100644 --- a/config/ext.json +++ b/config/ext.json @@ -138,6 +138,7 @@ }, "intl": { "type": "builtin", + "cpp-extension": true, "lib-depends": [ "icu" ] @@ -327,6 +328,7 @@ "type": "external", "source": "swoole", "arg-type": "custom", + "cpp-extension": true, "lib-depends": [ "openssl" ], diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index 900bb4ed..fd1a2844 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -140,6 +140,37 @@ abstract class BuilderBase return $this->exts[$name] ?? null; } + /** + * 获取所有要编译的扩展对象 + * + * @return Extension[] + */ + public function getExts(): array + { + return $this->exts; + } + + /** + * 检查 C++ 扩展是否存在 + * + * @throws FileSystemException + * @throws RuntimeException + * @throws WrongUsageException + */ + public function hasCppExtension(): bool + { + // judge cpp-extension + $exts = array_keys($this->getExts()); + $cpp = false; + foreach ($exts as $ext) { + if (Config::getExt($ext, 'cpp-extension', false) === true) { + $cpp = true; + break; + } + } + return $cpp; + } + /** * 设置本次 Builder 是否为仅编译库的模式 */ diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 486d5afb..b0237de8 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -139,7 +139,8 @@ class LinuxBuilder extends BuilderBase ) ); } - if ($this->getExt('swoole') || $this->getExt('intl')) { + + if ($this->hasCppExtension()) { $extra_libs .= ' -lstdc++'; } if ($this->getExt('imagick')) { diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index 65b1a7f6..ed780691 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -118,12 +118,15 @@ class MacOSBuilder extends BuilderBase } /** - * @throws RuntimeException + * @param int $build_target build target + * @param bool $bloat just raw add all lib files * @throws FileSystemException + * @throws RuntimeException + * @throws WrongUsageException */ public function buildPHP(int $build_target = BUILD_TARGET_NONE, bool $bloat = false): void { - $extra_libs = $this->getFrameworks(true) . ' ' . ($this->getExt('swoole') || $this->getExt('intl') ? '-lc++ ' : ''); + $extra_libs = $this->getFrameworks(true) . ' ' . ($this->hasCppExtension() ? '-lc++' : ''); if (!$bloat) { $extra_libs .= implode(' ', $this->getAllStaticLibFiles()); } else {