mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-15 21:05:35 +08:00
Add phpmicro win32 mode support
This commit is contained in:
@@ -460,7 +460,9 @@ abstract class BuilderBase
|
|||||||
'micro_ext_test' => [
|
'micro_ext_test' => [
|
||||||
'content' => ($this->getOption('without-micro-ext-test') ? '<?php echo "[micro-test-start][micro-test-end]";' : $this->generateMicroExtTests()),
|
'content' => ($this->getOption('without-micro-ext-test') ? '<?php echo "[micro-test-start][micro-test-end]";' : $this->generateMicroExtTests()),
|
||||||
'conditions' => [
|
'conditions' => [
|
||||||
|
// program success
|
||||||
function ($ret) { return $ret === 0; },
|
function ($ret) { return $ret === 0; },
|
||||||
|
// program returns expected output
|
||||||
function ($ret, $out) {
|
function ($ret, $out) {
|
||||||
$raw_out = trim(implode('', $out));
|
$raw_out = trim(implode('', $out));
|
||||||
return str_starts_with($raw_out, '[micro-test-start]') && str_ends_with($raw_out, '[micro-test-end]');
|
return str_starts_with($raw_out, '[micro-test-start]') && str_ends_with($raw_out, '[micro-test-end]');
|
||||||
@@ -470,6 +472,7 @@ abstract class BuilderBase
|
|||||||
'micro_zend_bug_test' => [
|
'micro_zend_bug_test' => [
|
||||||
'content' => ($this->getOption('without-micro-ext-test') ? '<?php echo "hello";' : file_get_contents(ROOT_DIR . '/src/globals/common-tests/micro_zend_mm_heap_corrupted.txt')),
|
'content' => ($this->getOption('without-micro-ext-test') ? '<?php echo "hello";' : file_get_contents(ROOT_DIR . '/src/globals/common-tests/micro_zend_mm_heap_corrupted.txt')),
|
||||||
'conditions' => [
|
'conditions' => [
|
||||||
|
// program success
|
||||||
function ($ret) { return $ret === 0; },
|
function ($ret) { return $ret === 0; },
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -102,6 +102,8 @@ class WindowsBuilder extends BuilderBase
|
|||||||
$micro_logo = '';
|
$micro_logo = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$micro_w32 = $this->getOption('enable-micro-win32') ? ' --enable-micro-win32=yes' : '';
|
||||||
|
|
||||||
cmd()->cd(SOURCE_PATH . '\php-src')
|
cmd()->cd(SOURCE_PATH . '\php-src')
|
||||||
->exec(
|
->exec(
|
||||||
"{$this->sdk_prefix} configure.bat --task-args \"" .
|
"{$this->sdk_prefix} configure.bat --task-args \"" .
|
||||||
@@ -111,7 +113,7 @@ class WindowsBuilder extends BuilderBase
|
|||||||
'--with-extra-includes=' . BUILD_INCLUDE_PATH . ' ' .
|
'--with-extra-includes=' . BUILD_INCLUDE_PATH . ' ' .
|
||||||
'--with-extra-libs=' . BUILD_LIB_PATH . ' ' .
|
'--with-extra-libs=' . BUILD_LIB_PATH . ' ' .
|
||||||
($enableCli ? '--enable-cli=yes ' : '--enable-cli=no ') .
|
($enableCli ? '--enable-cli=yes ' : '--enable-cli=no ') .
|
||||||
($enableMicro ? ('--enable-micro=yes ' . $micro_logo) : '--enable-micro=no ') .
|
($enableMicro ? ('--enable-micro=yes ' . $micro_logo . $micro_w32) : '--enable-micro=no ') .
|
||||||
($enableEmbed ? '--enable-embed=yes ' : '--enable-embed=no ') .
|
($enableEmbed ? '--enable-embed=yes ' : '--enable-embed=no ') .
|
||||||
"{$this->makeExtensionArgs()} " .
|
"{$this->makeExtensionArgs()} " .
|
||||||
$zts .
|
$zts .
|
||||||
@@ -132,6 +134,8 @@ class WindowsBuilder extends BuilderBase
|
|||||||
if ($enableMicro) {
|
if ($enableMicro) {
|
||||||
logger()->info('building micro');
|
logger()->info('building micro');
|
||||||
$this->buildMicro();
|
$this->buildMicro();
|
||||||
|
|
||||||
|
SourcePatcher::unpatchMicroWin32();
|
||||||
}
|
}
|
||||||
if ($enableEmbed) {
|
if ($enableEmbed) {
|
||||||
logger()->warning('Windows does not currently support embed SAPI.');
|
logger()->warning('Windows does not currently support embed SAPI.');
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ class BuildCliCommand extends BuildCommand
|
|||||||
$this->addOption('without-micro-ext-test', null, null, 'Disable phpmicro with extension test code');
|
$this->addOption('without-micro-ext-test', null, null, 'Disable phpmicro with extension test code');
|
||||||
$this->addOption('with-upx-pack', null, null, 'Compress / pack binary using UPX tool (linux/windows only)');
|
$this->addOption('with-upx-pack', null, null, 'Compress / pack binary using UPX tool (linux/windows only)');
|
||||||
$this->addOption('with-micro-logo', null, InputOption::VALUE_REQUIRED, 'Use custom .ico for micro.sfx (windows only)');
|
$this->addOption('with-micro-logo', null, InputOption::VALUE_REQUIRED, 'Use custom .ico for micro.sfx (windows only)');
|
||||||
|
$this->addOption('enable-micro-win32', null, null, 'Enable win32 mode for phpmicro (Windows only)');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(): int
|
public function handle(): int
|
||||||
|
|||||||
@@ -47,6 +47,12 @@ class SourcePatcher
|
|||||||
''
|
''
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($builder->getOption('enable-micro-win32')) {
|
||||||
|
SourcePatcher::patchMicroWin32();
|
||||||
|
} else {
|
||||||
|
SourcePatcher::unpatchMicroWin32();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -368,4 +374,20 @@ class SourcePatcher
|
|||||||
FileSystem::writeFile(SOURCE_PATH . '/php-src/main/main.c', $file);
|
FileSystem::writeFile(SOURCE_PATH . '/php-src/main/main.c', $file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function patchMicroWin32(): void
|
||||||
|
{
|
||||||
|
// patch micro win32
|
||||||
|
if (!file_exists(SOURCE_PATH . '\php-src\sapi\micro\php_micro.c.win32bak')) {
|
||||||
|
copy(SOURCE_PATH . '\php-src\sapi\micro\php_micro.c', SOURCE_PATH . '\php-src\sapi\micro\php_micro.c.win32bak');
|
||||||
|
FileSystem::replaceFileStr(SOURCE_PATH . '\php-src\sapi\micro\php_micro.c', '#include "php_variables.h"', '#include "php_variables.h"' . "\n#define PHP_MICRO_WIN32_NO_CONSOLE 1");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function unpatchMicroWin32(): void
|
||||||
|
{
|
||||||
|
if (file_exists(SOURCE_PATH . '\php-src\sapi\micro\php_micro.c.win32bak')) {
|
||||||
|
rename(SOURCE_PATH . '\php-src\sapi\micro\php_micro.c.win32bak', SOURCE_PATH . '\php-src\sapi\micro\php_micro.c');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user