mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-17 20:34:51 +08:00
add macos external extension support
This commit is contained in:
parent
b7f64e46c2
commit
09f1574264
@ -19,6 +19,7 @@
|
||||
| enchant | | | |
|
||||
| event | yes | yes | |
|
||||
| exif | yes | yes | |
|
||||
| ffi | | yes, [docs]() | |
|
||||
| filter | yes | yes | |
|
||||
| fileinfo | yes | yes | |
|
||||
| ftp | yes | yes | |
|
||||
|
||||
@ -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 库对应的源码,如果不存在,则抛出异常
|
||||
*
|
||||
|
||||
@ -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';
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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']);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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'));
|
||||
// 统计时间
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user