Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/env.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/SPC/builder/BuilderBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use SPC\store\FileSystem;
use SPC\store\LockFile;
use SPC\store\SourceManager;
use SPC\store\SourcePatcher;
use SPC\util\CustomExt;

abstract class BuilderBase
Expand Down Expand Up @@ -203,6 +204,8 @@ public function proveExts(array $static_extensions, array $shared_extensions = [
$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) {
Expand Down
28 changes: 14 additions & 14 deletions src/SPC/store/SourcePatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down Expand Up @@ -105,7 +104,7 @@ public static function patchBeforeConfigure(BuilderBase $builder): void
* @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;
Expand Down Expand Up @@ -152,11 +151,7 @@ public static function patchMicro(string $name = '', string $target = '', ?array

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;
Expand All @@ -165,24 +160,29 @@ public static function patchMicro(string $name = '', string $target = '', ?array
/**
* 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)) {
Copy link

Copilot AI Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The initial file_exists($patch_file) check makes the subsequent file_exists($patch_str) check redundant; consider removing one or consolidating the logic.

Copilot uses AI. Check for mistakes.
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://')) {
Copy link

Copilot AI Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking str_starts_with($patch_str, 'phar://') may never detect the PHAR context correctly since $patch_str is a filesystem path. Consider using \Phar::running() to detect runtime in a PHAR archive as before.

Suggested change
if (str_starts_with($patch_str, 'phar://')) {
if (\Phar::running() !== '') {

Copilot uses AI. Check for mistakes.
$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
Expand Down
Loading