mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-19 13:24:51 +08:00
strip libphp.so and frankenphp
This commit is contained in:
parent
96babd0939
commit
f5281535d9
@ -140,7 +140,7 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
|
||||
$embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static';
|
||||
if ($embed_type !== 'static' && getenv('SPC_LIBC') === 'musl') {
|
||||
throw new RuntimeException('Musl libc does not support dynamic linking of PHP embed!');
|
||||
throw new WrongUsageException('Musl libc does not support dynamic linking of PHP embed!');
|
||||
}
|
||||
shell()->cd(SOURCE_PATH . '/php-src')
|
||||
->exec(
|
||||
@ -300,6 +300,7 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . ' INSTALL_ROOT=' . BUILD_ROOT_PATH . " {$vars} install");
|
||||
|
||||
$ldflags = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS');
|
||||
$realLibName = 'libphp.so';
|
||||
if (preg_match('/-release\s+(\S+)/', $ldflags, $matches)) {
|
||||
$release = $matches[1];
|
||||
$realLibName = 'libphp-' . $release . '.so';
|
||||
@ -338,8 +339,8 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
}
|
||||
chdir($cwd);
|
||||
}
|
||||
if (!$this->getOption('no-strip', false)) {
|
||||
shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')->exec('strip --strip-all php');
|
||||
if (!$this->getOption('no-strip', false) && file_exists(BUILD_LIB_PATH . '/' . $realLibName)) {
|
||||
shell()->cd(BUILD_LIB_PATH)->exec("strip --strip-all $realLibName");
|
||||
}
|
||||
$this->patchPhpScripts();
|
||||
}
|
||||
|
||||
@ -209,7 +209,7 @@ abstract class UnixBuilderBase extends BuilderBase
|
||||
if ($ret !== 0) {
|
||||
throw new RuntimeException('embed failed sanity check: build failed. Error message: ' . implode("\n", $out));
|
||||
}
|
||||
// if someone changed to --enable-embed=shared, we need to add LD_LIBRARY_PATH
|
||||
// if someone changed to EMBED_TYPE=shared, we need to add LD_LIBRARY_PATH
|
||||
if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') {
|
||||
$ext_path = 'LD_LIBRARY_PATH=' . BUILD_ROOT_PATH . '/lib:$LD_LIBRARY_PATH ';
|
||||
FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '/lib/libphp.a');
|
||||
@ -357,5 +357,9 @@ abstract class UnixBuilderBase extends BuilderBase
|
||||
shell()->cd(BUILD_BIN_PATH)
|
||||
->setEnv($env)
|
||||
->exec("xcaddy build --output frankenphp {$xcaddyModules}");
|
||||
|
||||
if (!$this->getOption('no-strip', false) && file_exists(BUILD_BIN_PATH . '/frankenphp')) {
|
||||
shell()->cd(BUILD_BIN_PATH)->exec('strip --strip-all frankenphp');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +44,13 @@ class GlobalEnvManager
|
||||
// Define env vars for linux
|
||||
if (PHP_OS_FAMILY === 'Linux') {
|
||||
$arch = getenv('GNU_ARCH');
|
||||
if (SystemUtil::isMuslDist() || getenv('SPC_LIBC') === 'glibc') {
|
||||
|
||||
if (str_contains(getenv('CC'), 'zig')) {
|
||||
self::putenv('SPC_LINUX_DEFAULT_CC=zig-cc');
|
||||
self::putenv('SPC_LINUX_DEFAULT_CXX=zig-c++');
|
||||
self::putenv('SPC_LINUX_DEFAULT_AR=ar');
|
||||
self::putenv('SPC_LINUX_DEFAULT_LD=ld.lld');
|
||||
} elseif (SystemUtil::isMuslDist() || getenv('SPC_LIBC') === 'glibc') {
|
||||
self::putenv('SPC_LINUX_DEFAULT_CC=gcc');
|
||||
self::putenv('SPC_LINUX_DEFAULT_CXX=g++');
|
||||
self::putenv('SPC_LINUX_DEFAULT_AR=ar');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user