mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-08 17:35:36 +08:00
Merge remote-tracking branch 'origin/v3-docs/readme' into v3-docs/readme
This commit is contained in:
@@ -266,43 +266,32 @@ trait unix
|
|||||||
#[PatchDescription('Patch phar extension for micro SAPI to support compressed phar')]
|
#[PatchDescription('Patch phar extension for micro SAPI to support compressed phar')]
|
||||||
public function makeMicroForUnix(TargetPackage $package, PackageInstaller $installer, PackageBuilder $builder): void
|
public function makeMicroForUnix(TargetPackage $package, PackageInstaller $installer, PackageBuilder $builder): void
|
||||||
{
|
{
|
||||||
$phar_patched = false;
|
InteractiveTerm::setMessage('Building php: ' . ConsoleColor::yellow('make micro'));
|
||||||
try {
|
// apply --with-micro-fake-cli option
|
||||||
if ($installer->isPackageResolved('ext-phar')) {
|
$vars = $this->makeVars($installer);
|
||||||
$phar_patched = true;
|
$vars['EXTRA_CFLAGS'] .= $package->getBuildOption('with-micro-fake-cli', false) ? ' -DPHP_MICRO_FAKE_CLI' : '';
|
||||||
SourcePatcher::patchMicroPhar(self::getPHPVersionID());
|
$makeArgs = $this->makeVarsToArgs($vars);
|
||||||
}
|
// build
|
||||||
InteractiveTerm::setMessage('Building php: ' . ConsoleColor::yellow('make micro'));
|
shell()->cd($package->getSourceDir())
|
||||||
// apply --with-micro-fake-cli option
|
->setEnv($vars)
|
||||||
$vars = $this->makeVars($installer);
|
->exec("make -j{$builder->concurrency} {$makeArgs} micro");
|
||||||
$vars['EXTRA_CFLAGS'] .= $package->getBuildOption('with-micro-fake-cli', false) ? ' -DPHP_MICRO_FAKE_CLI' : '';
|
|
||||||
$makeArgs = $this->makeVarsToArgs($vars);
|
|
||||||
// build
|
|
||||||
shell()->cd($package->getSourceDir())
|
|
||||||
->setEnv($vars)
|
|
||||||
->exec("make -j{$builder->concurrency} {$makeArgs} micro");
|
|
||||||
|
|
||||||
$dst = BUILD_BIN_PATH . '/micro.sfx';
|
$dst = BUILD_BIN_PATH . '/micro.sfx';
|
||||||
$builder->deployBinary($package->getSourceDir() . '/sapi/micro/micro.sfx', $dst);
|
$builder->deployBinary($package->getSourceDir() . '/sapi/micro/micro.sfx', $dst);
|
||||||
// patch after UPX-ed micro.sfx (Linux only)
|
// patch after UPX-ed micro.sfx (Linux only)
|
||||||
if (SystemTarget::getTargetOS() === 'Linux' && $builder->getOption('with-upx-pack')) {
|
if (SystemTarget::getTargetOS() === 'Linux' && $builder->getOption('with-upx-pack')) {
|
||||||
// cut binary with readelf to remove UPX extra segment
|
// cut binary with readelf to remove UPX extra segment
|
||||||
[$ret, $out] = shell()->execWithResult("readelf -l {$dst} | awk '/LOAD|GNU_STACK/ {getline; print \\$1, \\$2, \\$3, \\$4, \\$6, \\$7}'");
|
[$ret, $out] = shell()->execWithResult("readelf -l {$dst} | awk '/LOAD|GNU_STACK/ {getline; print \\$1, \\$2, \\$3, \\$4, \\$6, \\$7}'");
|
||||||
$out[1] = explode(' ', $out[1]);
|
$out[1] = explode(' ', $out[1]);
|
||||||
$offset = $out[1][0];
|
$offset = $out[1][0];
|
||||||
if ($ret !== 0 || !str_starts_with($offset, '0x')) {
|
if ($ret !== 0 || !str_starts_with($offset, '0x')) {
|
||||||
throw new PatchException('phpmicro UPX patcher', 'Cannot find offset in readelf output');
|
throw new PatchException('phpmicro UPX patcher', 'Cannot find offset in readelf output');
|
||||||
}
|
|
||||||
$offset = hexdec($offset);
|
|
||||||
// remove upx extra wastes
|
|
||||||
file_put_contents($dst, substr(file_get_contents($dst), 0, $offset));
|
|
||||||
}
|
|
||||||
$package->setOutput('Binary path for micro SAPI', $dst);
|
|
||||||
} finally {
|
|
||||||
if ($phar_patched) {
|
|
||||||
SourcePatcher::unpatchMicroPhar();
|
|
||||||
}
|
}
|
||||||
|
$offset = hexdec($offset);
|
||||||
|
// remove upx extra wastes
|
||||||
|
file_put_contents($dst, substr(file_get_contents($dst), 0, $offset));
|
||||||
}
|
}
|
||||||
|
$package->setOutput('Binary path for micro SAPI', $dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Stage]
|
#[Stage]
|
||||||
|
|||||||
@@ -293,21 +293,8 @@ trait windows
|
|||||||
|
|
||||||
$fake_cli = $package->getBuildOption('with-micro-fake-cli', false) ? ' /DPHP_MICRO_FAKE_CLI' : '';
|
$fake_cli = $package->getBuildOption('with-micro-fake-cli', false) ? ' /DPHP_MICRO_FAKE_CLI' : '';
|
||||||
|
|
||||||
// phar patch for micro
|
cmd()->cd($package->getSourceDir())
|
||||||
$phar_patched = false;
|
->exec("nmake /nologo {$debug_overrides}LIBS_MICRO=\"ws2_32.lib shell32.lib {$extra_libs}\" CFLAGS_MICRO=\"/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1{$fake_cli}\" EXTRA_LD_FLAGS_PROGRAM= micro");
|
||||||
if ($installer->isPackageResolved('ext-phar')) {
|
|
||||||
$phar_patched = true;
|
|
||||||
SourcePatcher::patchMicroPhar(self::getPHPVersionID());
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
cmd()->cd($package->getSourceDir())
|
|
||||||
->exec("nmake /nologo {$debug_overrides}LIBS_MICRO=\"ws2_32.lib shell32.lib {$extra_libs}\" CFLAGS_MICRO=\"/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1{$fake_cli}\" EXTRA_LD_FLAGS_PROGRAM= micro");
|
|
||||||
} finally {
|
|
||||||
if ($phar_patched) {
|
|
||||||
SourcePatcher::unpatchMicroPhar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->deployWindowsBinary($builder, $package, 'php-micro');
|
$this->deployWindowsBinary($builder, $package, 'php-micro');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ class DefaultShell extends Shell
|
|||||||
$cmd = SPC_CURL_EXEC . " -sfSL --max-time 3600 {$retry_arg} {$compressed_arg} {$method_arg} {$header_arg} {$url_arg}";
|
$cmd = SPC_CURL_EXEC . " -sfSL --max-time 3600 {$retry_arg} {$compressed_arg} {$method_arg} {$header_arg} {$url_arg}";
|
||||||
|
|
||||||
$this->logCommandInfo($cmd);
|
$this->logCommandInfo($cmd);
|
||||||
|
logger()->debug("[CURL EXECUTE] {$cmd}");
|
||||||
$result = $this->passthru($cmd, capture_output: true, throw_on_error: false);
|
$result = $this->passthru($cmd, capture_output: true, throw_on_error: false);
|
||||||
$ret = $result['code'];
|
$ret = $result['code'];
|
||||||
$output = $result['output'];
|
$output = $result['output'];
|
||||||
|
|||||||
Reference in New Issue
Block a user