From 09f15742642359920c2ee574d236ae0590f9267e Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Wed, 10 May 2023 21:59:33 +0800 Subject: [PATCH] add macos external extension support --- ext-support.md | 1 + src/SPC/builder/BuilderBase.php | 14 ++++++++------ src/SPC/builder/extension/ffi.php | 3 +-- src/SPC/builder/macos/MacOSBuilder.php | 20 +++++++++++--------- src/SPC/builder/macos/library/libffi.php | 4 ++-- src/SPC/command/BuildCliCommand.php | 3 +++ 6 files changed, 26 insertions(+), 19 deletions(-) diff --git a/ext-support.md b/ext-support.md index a1c0d6ee..ee16ed96 100644 --- a/ext-support.md +++ b/ext-support.md @@ -19,6 +19,7 @@ | enchant | | | | | event | yes | yes | | | exif | yes | yes | | +| ffi | | yes, [docs]() | | | filter | yes | yes | | | fileinfo | yes | yes | | | ftp | yes | yes | | diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index 83097896..900bb4ed 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -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 库对应的源码,如果不存在,则抛出异常 * diff --git a/src/SPC/builder/extension/ffi.php b/src/SPC/builder/extension/ffi.php index 106f2a64..f0cf9fe6 100644 --- a/src/SPC/builder/extension/ffi.php +++ b/src/SPC/builder/extension/ffi.php @@ -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'; } } diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index 1eb13e05..296b8580 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -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); } } diff --git a/src/SPC/builder/macos/library/libffi.php b/src/SPC/builder/macos/library/libffi.php index 9fbabfb5..2c67cb46 100644 --- a/src/SPC/builder/macos/library/libffi.php +++ b/src/SPC/builder/macos/library/libffi.php @@ -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']); } } diff --git a/src/SPC/command/BuildCliCommand.php b/src/SPC/command/BuildCliCommand.php index 0c0cfa49..2da580e6 100644 --- a/src/SPC/command/BuildCliCommand.php +++ b/src/SPC/command/BuildCliCommand.php @@ -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')); // 统计时间