add hasCppExtension check

This commit is contained in:
crazywhalecc 2023-07-24 23:49:52 +08:00
parent 0e024a8c43
commit b8e6f9d1be
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680
4 changed files with 40 additions and 3 deletions

View File

@ -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"
],

View File

@ -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 是否为仅编译库的模式
*/

View File

@ -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')) {

View File

@ -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 {