From 25c2def710bba4310ab62269e502241e96430664 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sat, 28 Jun 2025 16:47:19 +0800 Subject: [PATCH 1/5] Remove unnecessary SPC_MICRO_PATCHES --- config/env.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/env.ini b/config/env.ini index d80bc3e7..60f4a6d4 100644 --- a/config/env.ini +++ b/config/env.ini @@ -78,7 +78,7 @@ SPC_EXTRA_LIBS= ; upx executable path UPX_EXEC=${PKG_ROOT_PATH}/bin/upx ; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches -SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime140,win32,zend_stream +SPC_MICRO_PATCHES=cli_checks,disable_huge_page ; *** default build command for building php *** ; buildconf command @@ -118,7 +118,7 @@ SPC_DEFAULT_CXX_FLAGS="--target=${MAC_ARCH}-apple-darwin -Os" ; extra libs for building php executable, used in `make` command for building php (this value may changed by extension build process, space separated) SPC_EXTRA_LIBS= ; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches -SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime140,win32,zend_stream,macos_iconv +SPC_MICRO_PATCHES=cli_checks,macos_iconv ; *** default build command for building php *** ; buildconf command From ad080da02669d972b4a0dda38466a0661d0db884 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sat, 28 Jun 2025 17:06:51 +0800 Subject: [PATCH 2/5] Refactor micro patching logic in SourcePatcher --- src/SPC/builder/BuilderBase.php | 3 +++ src/SPC/store/SourcePatcher.php | 28 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index 88e827c5..184d88dc 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -14,6 +14,7 @@ use SPC\store\Config; use SPC\store\FileSystem; use SPC\store\LockFile; use SPC\store\SourceManager; +use SPC\store\SourcePatcher; use SPC\util\CustomExt; abstract class BuilderBase @@ -203,6 +204,8 @@ abstract class BuilderBase $this->emitPatchPoint('before-exts-extract'); SourceManager::initSource(exts: [...$static_extensions, ...$shared_extensions]); $this->emitPatchPoint('after-exts-extract'); + // patch micro + SourcePatcher::patchMicro(); } foreach ([...$static_extensions, ...$shared_extensions] as $extension) { diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index 69d3a649..5ea10577 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -17,7 +17,6 @@ class SourcePatcher public static function init(): void { // FileSystem::addSourceExtractHook('swow', [SourcePatcher::class, 'patchSwow']); - FileSystem::addSourceExtractHook('micro', [SourcePatcher::class, 'patchMicro']); FileSystem::addSourceExtractHook('openssl', [SourcePatcher::class, 'patchOpenssl11Darwin']); FileSystem::addSourceExtractHook('swoole', [SourcePatcher::class, 'patchSwoole']); FileSystem::addSourceExtractHook('php-src', [SourcePatcher::class, 'patchPhpLibxml212']); @@ -105,7 +104,7 @@ class SourcePatcher * @throws RuntimeException * @throws FileSystemException */ - public static function patchMicro(string $name = '', string $target = '', ?array $items = null): bool + public static function patchMicro(?array $items = null): bool { if (!file_exists(SOURCE_PATH . '/php-src/sapi/micro/php_micro.c')) { return false; @@ -152,11 +151,7 @@ class SourcePatcher foreach ($patches as $patch) { logger()->info("Patching micro with {$patch}"); - $patchesStr = str_replace('/', DIRECTORY_SEPARATOR, $patch); - f_passthru( - 'cd ' . SOURCE_PATH . '/php-src && ' . - (PHP_OS_FAMILY === 'Windows' ? 'type' : 'cat') . ' ' . $patchesStr . ' | patch -p1 ' - ); + self::patchFile(SOURCE_PATH . "/php-src{$patch}", SOURCE_PATH . '/php-src'); } return true; @@ -165,24 +160,29 @@ class SourcePatcher /** * Use existing patch file for patching * - * @param string $patch_name Patch file name in src/globals/patch/ + * @param string $patch_name Patch file name in src/globals/patch/ or absolute path * @param string $cwd Working directory for patch command * @param bool $reverse Reverse patches (default: False) * @throws RuntimeException */ public static function patchFile(string $patch_name, string $cwd, bool $reverse = false): bool { - if (!file_exists(ROOT_DIR . "/src/globals/patch/{$patch_name}")) { + if (FileSystem::isRelativePath($patch_name)) { + $patch_file = ROOT_DIR . "/src/globals/patch/{$patch_name}"; + } else { + $patch_file = $patch_name; + } + if (!file_exists($patch_file)) { return false; } - $patch_file = ROOT_DIR . "/src/globals/patch/{$patch_name}"; - $patch_str = str_replace('/', DIRECTORY_SEPARATOR, $patch_file); + $patch_str = FileSystem::convertPath($patch_file); // Copy patch from phar - if (\Phar::running() !== '') { - file_put_contents(SOURCE_PATH . '/' . $patch_name, file_get_contents($patch_file)); - $patch_str = str_replace('/', DIRECTORY_SEPARATOR, SOURCE_PATH . '/' . $patch_name); + if (str_starts_with($patch_str, 'phar://')) { + $filename = pathinfo($patch_file, PATHINFO_BASENAME); + file_put_contents(SOURCE_PATH . "{$filename}", file_get_contents($patch_file)); + $patch_str = FileSystem::convertPath(SOURCE_PATH . "/{$filename}"); } // detect From 88d99a7dea2eb99fcc764690c9a40e190c2479e0 Mon Sep 17 00:00:00 2001 From: Jerry Ma Date: Sat, 28 Jun 2025 18:04:45 +0800 Subject: [PATCH 3/5] Update src/SPC/store/SourcePatcher.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/SPC/store/SourcePatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index 5ea10577..029f77a8 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -181,7 +181,7 @@ class SourcePatcher // Copy patch from phar if (str_starts_with($patch_str, 'phar://')) { $filename = pathinfo($patch_file, PATHINFO_BASENAME); - file_put_contents(SOURCE_PATH . "{$filename}", file_get_contents($patch_file)); + file_put_contents(SOURCE_PATH . "/{$filename}", file_get_contents($patch_file)); $patch_str = FileSystem::convertPath(SOURCE_PATH . "/{$filename}"); } From 3965a899c7adc874901495987ee36ecee66feebf Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 30 Jun 2025 19:41:32 +0800 Subject: [PATCH 4/5] Add missing directory separator --- src/SPC/store/SourcePatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index 029f77a8..92af572c 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -151,7 +151,7 @@ class SourcePatcher foreach ($patches as $patch) { logger()->info("Patching micro with {$patch}"); - self::patchFile(SOURCE_PATH . "/php-src{$patch}", SOURCE_PATH . '/php-src'); + self::patchFile(SOURCE_PATH . "/php-src/{$patch}", SOURCE_PATH . '/php-src'); } return true; From d00a5223d3ec24f0d482792d565c8ef232d4f61e Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 30 Jun 2025 19:45:26 +0800 Subject: [PATCH 5/5] Add exception for checking patch file exist --- src/SPC/store/SourcePatcher.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index 92af572c..1e8be792 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -177,6 +177,9 @@ class SourcePatcher } $patch_str = FileSystem::convertPath($patch_file); + if (!file_exists($patch_str)) { + throw new RuntimeException("Patch file [{$patch_str}] does not exist"); + } // Copy patch from phar if (str_starts_with($patch_str, 'phar://')) {