diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index f2ab2dd8..4f4a72f8 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -460,7 +460,9 @@ abstract class BuilderBase 'micro_ext_test' => [ 'content' => ($this->getOption('without-micro-ext-test') ? 'generateMicroExtTests()), 'conditions' => [ + // program success function ($ret) { return $ret === 0; }, + // program returns expected output function ($ret, $out) { $raw_out = trim(implode('', $out)); 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' => [ 'content' => ($this->getOption('without-micro-ext-test') ? ' [ + // program success function ($ret) { return $ret === 0; }, ], ], diff --git a/src/SPC/builder/windows/WindowsBuilder.php b/src/SPC/builder/windows/WindowsBuilder.php index 7c1f9ff7..f73b8cca 100644 --- a/src/SPC/builder/windows/WindowsBuilder.php +++ b/src/SPC/builder/windows/WindowsBuilder.php @@ -102,6 +102,8 @@ class WindowsBuilder extends BuilderBase $micro_logo = ''; } + $micro_w32 = $this->getOption('enable-micro-win32') ? ' --enable-micro-win32=yes' : ''; + cmd()->cd(SOURCE_PATH . '\php-src') ->exec( "{$this->sdk_prefix} configure.bat --task-args \"" . @@ -111,7 +113,7 @@ class WindowsBuilder extends BuilderBase '--with-extra-includes=' . BUILD_INCLUDE_PATH . ' ' . '--with-extra-libs=' . BUILD_LIB_PATH . ' ' . ($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 ') . "{$this->makeExtensionArgs()} " . $zts . @@ -132,6 +134,8 @@ class WindowsBuilder extends BuilderBase if ($enableMicro) { logger()->info('building micro'); $this->buildMicro(); + + SourcePatcher::unpatchMicroWin32(); } if ($enableEmbed) { logger()->warning('Windows does not currently support embed SAPI.'); diff --git a/src/SPC/command/BuildCliCommand.php b/src/SPC/command/BuildCliCommand.php index 3c6fb59f..ca689641 100644 --- a/src/SPC/command/BuildCliCommand.php +++ b/src/SPC/command/BuildCliCommand.php @@ -40,6 +40,7 @@ class BuildCliCommand extends BuildCommand $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-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 diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index 824c80f6..6750f899 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -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); } } + + 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'); + } + } }