add macos external extension support

This commit is contained in:
crazywhalecc 2023-05-10 21:59:33 +08:00
parent b7f64e46c2
commit 09f1574264
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680
6 changed files with 26 additions and 19 deletions

View File

@ -19,6 +19,7 @@
| enchant | | | |
| event | yes | yes | |
| exif | yes | yes | |
| ffi | | yes, [docs]() | |
| filter | yes | yes | |
| fileinfo | yes | yes | |
| ftp | yes | yes | |

View File

@ -38,6 +38,9 @@ abstract class BuilderBase
/** @var bool 本次编译是否只编译 libs不编译 PHP */
protected bool $libs_only = false;
/** @var bool 是否 strip 最终的二进制 */
protected bool $strip = true;
/**
* 构建指定列表的 libs
*
@ -70,12 +73,6 @@ abstract class BuilderBase
// 排序 libs根据依赖计算一个新的列表出来
$libraries = DependencyUtil::getLibsByDeps($libraries);
// 这里筛选 libraries比如纯静态模式排除掉ffi
if (defined('BUILD_ALL_STATIC') && BUILD_ALL_STATIC) {
$k = array_search('libffi', $libraries, true);
$k !== false && array_splice($libraries, $k, 1);
}
// 过滤不支持的库后添加
foreach ($libraries as $library) {
if (!isset($support_lib_list[$library])) {
@ -237,6 +234,11 @@ abstract class BuilderBase
return implode(', ', $ls);
}
public function setStrip(bool $strip): void
{
$this->strip = $strip;
}
/**
* 检查是否存在 lib 库对应的源码,如果不存在,则抛出异常
*

View File

@ -12,7 +12,6 @@ class ffi extends Extension
{
public function getUnixConfigureArg(): string
{
return '--with-ffi FFI_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' .
'FFI_LIBS="' . $this->getLibFilesString() . '"';
return '--with-ffi --enable-zend-signals';
}
}

View File

@ -207,10 +207,11 @@ class MacOSBuilder extends BuilderBase
*/
public function buildCli(string $extra_libs): void
{
shell()->cd(SOURCE_PATH . '/php-src')
->exec("make -j{$this->concurrency} EXTRA_CFLAGS=\"-g -Os -fno-ident\" EXTRA_LIBS=\"{$extra_libs} -lresolv\" cli")
->exec('dsymutil -f sapi/cli/php')
->exec('strip sapi/cli/php');
$shell = shell()->cd(SOURCE_PATH . '/php-src');
$shell->exec("make -j{$this->concurrency} EXTRA_CFLAGS=\"-g -Os -fno-ident\" EXTRA_LIBS=\"{$extra_libs} -lresolv\" cli");
if ($this->strip) {
$shell->exec('dsymutil -f sapi/cli/php')->exec('strip sapi/cli/php');
}
$this->deployBinary(BUILD_TARGET_CLI);
}
@ -230,7 +231,7 @@ class MacOSBuilder extends BuilderBase
}
shell()->cd(SOURCE_PATH . '/php-src')
->exec("make -j{$this->concurrency} EXTRA_CFLAGS=\"-g -Os -fno-ident\" EXTRA_LIBS=\"{$extra_libs} -lresolv\" STRIP=\"dsymutil -f \" micro");
->exec("make -j{$this->concurrency} EXTRA_CFLAGS=\"-g -Os -fno-ident\" EXTRA_LIBS=\"{$extra_libs} -lresolv\" " . ($this->strip ? 'STRIP="dsymutil -f " ' : '') . 'micro');
$this->deployBinary(BUILD_TARGET_MICRO);
}
@ -242,10 +243,11 @@ class MacOSBuilder extends BuilderBase
*/
public function buildFpm(string $extra_libs): void
{
shell()->cd(SOURCE_PATH . '/php-src')
->exec("make -j{$this->concurrency} EXTRA_CFLAGS=\"-g -Os -fno-ident\" EXTRA_LIBS=\"{$extra_libs} -lresolv\" fpm")
->exec('dsymutil -f sapi/fpm/php-fpm')
->exec('strip sapi/fpm/php-fpm');
$shell = shell()->cd(SOURCE_PATH . '/php-src');
$shell->exec("make -j{$this->concurrency} EXTRA_CFLAGS=\"-g -Os -fno-ident\" EXTRA_LIBS=\"{$extra_libs} -lresolv\" fpm");
if ($this->strip) {
$shell->exec('dsymutil -f sapi/fpm/php-fpm')->exec('strip sapi/fpm/php-fpm');
}
$this->deployBinary(BUILD_TARGET_FPM);
}
}

View File

@ -34,11 +34,11 @@ class libffi extends MacOSLibraryBase
'--disable-shared ' .
"--host={$this->builder->arch}-apple-darwin " .
"--target={$this->builder->arch}-apple-darwin " .
'--prefix= ' . // use prefix=/
"--libdir={$lib}"
'--prefix= ' // use prefix=/
)
->exec('make clean')
->exec("make -j{$this->builder->concurrency}")
->exec("make install DESTDIR={$destdir}");
$this->patchPkgconfPrefix(['libffi.pc']);
}
}

View File

@ -25,6 +25,7 @@ class BuildCliCommand extends BuildCommand
$this->addOption('build-cli', null, null, 'build cli');
$this->addOption('build-fpm', null, null, 'build fpm');
$this->addOption('build-all', null, null, 'build cli, micro, fpm');
$this->addOption('no-strip', null, null, 'build without strip, in order to debug and load external extensions');
}
public function handle(): int
@ -68,6 +69,8 @@ class BuildCliCommand extends BuildCommand
$builder->buildLibs($libraries);
// 执行扩展检测
$builder->proveExts($extensions);
// strip
$builder->setStrip(false);
// 构建
$builder->buildPHP($rule, $this->getOption('bloat'));
// 统计时间