mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-09 01:45:36 +08:00
strip all may strip things needed for relocation on musl
This commit is contained in:
@@ -210,7 +210,7 @@ class BSDBuilder extends UnixBuilderBase
|
|||||||
->exec("make -j{$this->concurrency} {$vars} micro");
|
->exec("make -j{$this->concurrency} {$vars} micro");
|
||||||
|
|
||||||
if (!$this->getOption('no-strip', false)) {
|
if (!$this->getOption('no-strip', false)) {
|
||||||
shell()->cd(SOURCE_PATH . '/php-src/sapi/micro')->exec('strip --strip-all micro.sfx');
|
shell()->cd(SOURCE_PATH . '/php-src/sapi/micro')->exec('strip --strip-unneeded micro.sfx');
|
||||||
}
|
}
|
||||||
$this->deployBinary(BUILD_TARGET_MICRO);
|
$this->deployBinary(BUILD_TARGET_MICRO);
|
||||||
|
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ class LinuxBuilder extends UnixBuilderBase
|
|||||||
->exec("{$SPC_CMD_PREFIX_PHP_MAKE} {$vars} cli");
|
->exec("{$SPC_CMD_PREFIX_PHP_MAKE} {$vars} cli");
|
||||||
|
|
||||||
if (!$this->getOption('no-strip', false)) {
|
if (!$this->getOption('no-strip', false)) {
|
||||||
shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')->exec('strip --strip-all php');
|
shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')->exec('strip --strip-unneeded php');
|
||||||
}
|
}
|
||||||
if ($this->getOption('with-upx-pack')) {
|
if ($this->getOption('with-upx-pack')) {
|
||||||
shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')
|
shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')
|
||||||
@@ -256,7 +256,7 @@ class LinuxBuilder extends UnixBuilderBase
|
|||||||
->exec("{$SPC_CMD_PREFIX_PHP_MAKE} {$vars} fpm");
|
->exec("{$SPC_CMD_PREFIX_PHP_MAKE} {$vars} fpm");
|
||||||
|
|
||||||
if (!$this->getOption('no-strip', false)) {
|
if (!$this->getOption('no-strip', false)) {
|
||||||
shell()->cd(SOURCE_PATH . '/php-src/sapi/fpm')->exec('strip --strip-all php-fpm');
|
shell()->cd(SOURCE_PATH . '/php-src/sapi/fpm')->exec('strip --strip-unneeded php-fpm');
|
||||||
}
|
}
|
||||||
if ($this->getOption('with-upx-pack')) {
|
if ($this->getOption('with-upx-pack')) {
|
||||||
shell()->cd(SOURCE_PATH . '/php-src/sapi/fpm')
|
shell()->cd(SOURCE_PATH . '/php-src/sapi/fpm')
|
||||||
@@ -280,25 +280,32 @@ class LinuxBuilder extends UnixBuilderBase
|
|||||||
->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . ' INSTALL_ROOT=' . BUILD_ROOT_PATH . " {$vars} install");
|
->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . ' INSTALL_ROOT=' . BUILD_ROOT_PATH . " {$vars} install");
|
||||||
|
|
||||||
$ldflags = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS');
|
$ldflags = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS');
|
||||||
|
$libDir = BUILD_LIB_PATH;
|
||||||
|
$modulesDir = BUILD_MODULES_PATH;
|
||||||
|
$libphpSo = "{$libDir}/libphp.so";
|
||||||
$realLibName = 'libphp.so';
|
$realLibName = 'libphp.so';
|
||||||
|
|
||||||
if (preg_match('/-release\s+(\S+)/', $ldflags, $matches)) {
|
if (preg_match('/-release\s+(\S+)/', $ldflags, $matches)) {
|
||||||
$release = $matches[1];
|
$release = $matches[1];
|
||||||
$realLibName = 'libphp-' . $release . '.so';
|
$realLibName = "libphp-{$release}.so";
|
||||||
$cwd = getcwd();
|
$libphpRelease = "{$libDir}/{$realLibName}";
|
||||||
$libphpPath = BUILD_LIB_PATH . '/libphp.so';
|
if (!file_exists($libphpRelease) && file_exists($libphpSo)) {
|
||||||
$libphpRelease = BUILD_LIB_PATH . '/' . $realLibName;
|
rename($libphpSo, $libphpRelease);
|
||||||
if (!file_exists($libphpRelease) && file_exists($libphpPath)) {
|
|
||||||
rename($libphpPath, $libphpRelease);
|
|
||||||
}
|
}
|
||||||
if (file_exists($libphpRelease)) {
|
if (file_exists($libphpRelease)) {
|
||||||
chdir(BUILD_LIB_PATH);
|
chdir($libDir);
|
||||||
if (file_exists($libphpPath)) {
|
if (file_exists($libphpSo)) {
|
||||||
unlink($libphpPath);
|
unlink($libphpSo);
|
||||||
}
|
}
|
||||||
symlink($realLibName, 'libphp.so');
|
symlink($realLibName, 'libphp.so');
|
||||||
|
shell()->exec(sprintf(
|
||||||
|
'patchelf --set-soname %s %s',
|
||||||
|
escapeshellarg($realLibName),
|
||||||
|
escapeshellarg($libphpRelease)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
if (is_dir(BUILD_MODULES_PATH)) {
|
if (is_dir($modulesDir)) {
|
||||||
chdir(BUILD_MODULES_PATH);
|
chdir($modulesDir);
|
||||||
foreach ($this->getExts() as $ext) {
|
foreach ($this->getExts() as $ext) {
|
||||||
if (!$ext->isBuildShared()) {
|
if (!$ext->isBuildShared()) {
|
||||||
continue;
|
continue;
|
||||||
@@ -306,21 +313,39 @@ class LinuxBuilder extends UnixBuilderBase
|
|||||||
$name = $ext->getName();
|
$name = $ext->getName();
|
||||||
$versioned = "{$name}-{$release}.so";
|
$versioned = "{$name}-{$release}.so";
|
||||||
$unversioned = "{$name}.so";
|
$unversioned = "{$name}.so";
|
||||||
if (is_file(BUILD_MODULES_PATH . "/{$versioned}")) {
|
$src = "{$modulesDir}/{$versioned}";
|
||||||
rename(BUILD_MODULES_PATH . "/{$versioned}", BUILD_MODULES_PATH . "/{$unversioned}");
|
$dst = "{$modulesDir}/{$unversioned}";
|
||||||
shell()->cd(BUILD_MODULES_PATH)
|
if (is_file($src)) {
|
||||||
->exec(sprintf(
|
rename($src, $dst);
|
||||||
'patchelf --set-soname %s %s',
|
shell()->exec(sprintf(
|
||||||
escapeshellarg($unversioned),
|
'patchelf --set-soname %s %s',
|
||||||
escapeshellarg($unversioned)
|
escapeshellarg($unversioned),
|
||||||
));
|
escapeshellarg($dst)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
chdir($cwd);
|
chdir(getcwd());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$target = "{$libDir}/{$realLibName}";
|
||||||
|
if (file_exists($target)) {
|
||||||
|
[, $output] = shell()->execWithResult("readelf -d " . escapeshellarg($target));
|
||||||
|
$output = join("\n", $output);
|
||||||
|
if (preg_match('/SONAME.*\[(.+)\]/', $output, $sonameMatch)) {
|
||||||
|
$currentSoname = $sonameMatch[1];
|
||||||
|
if ($currentSoname !== basename($target)) {
|
||||||
|
shell()->exec(sprintf(
|
||||||
|
'patchelf --set-soname %s %s',
|
||||||
|
escapeshellarg(basename($target)),
|
||||||
|
escapeshellarg($target)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!$this->getOption('no-strip', false) && file_exists(BUILD_LIB_PATH . '/' . $realLibName)) {
|
if (!$this->getOption('no-strip', false) && file_exists(BUILD_LIB_PATH . '/' . $realLibName)) {
|
||||||
shell()->cd(BUILD_LIB_PATH)->exec("strip --strip-all {$realLibName}");
|
shell()->cd(BUILD_LIB_PATH)->exec("strip --strip-unneeded {$realLibName}");
|
||||||
}
|
}
|
||||||
$this->patchPhpScripts();
|
$this->patchPhpScripts();
|
||||||
}
|
}
|
||||||
@@ -382,7 +407,7 @@ class LinuxBuilder extends UnixBuilderBase
|
|||||||
private function processMicroUPX(): void
|
private function processMicroUPX(): void
|
||||||
{
|
{
|
||||||
if (version_compare($this->getMicroVersion(), '0.2.0') >= 0 && !$this->getOption('no-strip', false)) {
|
if (version_compare($this->getMicroVersion(), '0.2.0') >= 0 && !$this->getOption('no-strip', false)) {
|
||||||
shell()->exec('strip --strip-all ' . SOURCE_PATH . '/php-src/sapi/micro/micro.sfx');
|
shell()->exec('strip --strip-unneeded ' . SOURCE_PATH . '/php-src/sapi/micro/micro.sfx');
|
||||||
|
|
||||||
if ($this->getOption('with-upx-pack')) {
|
if ($this->getOption('with-upx-pack')) {
|
||||||
// strip first
|
// strip first
|
||||||
|
|||||||
@@ -363,8 +363,8 @@ abstract class UnixBuilderBase extends BuilderBase
|
|||||||
|
|
||||||
if (!$this->getOption('no-strip', false) && file_exists(BUILD_BIN_PATH . '/frankenphp')) {
|
if (!$this->getOption('no-strip', false) && file_exists(BUILD_BIN_PATH . '/frankenphp')) {
|
||||||
if (PHP_OS_FAMILY === 'Linux') {
|
if (PHP_OS_FAMILY === 'Linux') {
|
||||||
shell()->cd(BUILD_BIN_PATH)->exec('strip --strip-all frankenphp');
|
shell()->cd(BUILD_BIN_PATH)->exec('strip --strip-unneeded frankenphp');
|
||||||
} else { // macOS doesn't understand strip-all
|
} else { // macOS doesn't understand strip-unneeded
|
||||||
shell()->cd(BUILD_BIN_PATH)->exec('strip -S frankenphp');
|
shell()->cd(BUILD_BIN_PATH)->exec('strip -S frankenphp');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user