From bd815d4ea2ac70d6e6822f55b0647b70a56276fc Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 7 Sep 2025 14:10:28 +0800 Subject: [PATCH 1/3] Fix static linux cli `-a` not working issue --- src/SPC/builder/unix/library/ncurses.php | 2 +- src/SPC/store/SourcePatcher.php | 7 ++++++ src/globals/patch/musl_static_readline.patch | 26 ++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/globals/patch/musl_static_readline.patch diff --git a/src/SPC/builder/unix/library/ncurses.php b/src/SPC/builder/unix/library/ncurses.php index 3899e5597..27725c3d5 100644 --- a/src/SPC/builder/unix/library/ncurses.php +++ b/src/SPC/builder/unix/library/ncurses.php @@ -38,7 +38,7 @@ protected function build(): void ->make(); $final = FileSystem::scanDirFiles(BUILD_BIN_PATH, relative: true); // Remove the new files - $new_files = array_diff($final, $filelist); + $new_files = array_diff($final, $filelist ?: []); foreach ($new_files as $file) { @unlink(BUILD_BIN_PATH . '/' . $file); } diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index c08204f5d..eef786549 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -23,6 +23,7 @@ public static function init(): void FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchPhpLibxml212']); FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchGDWin32']); FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchFfiCentos7FixO3strncmp']); + FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchStaticReadline']); FileSystem::addSourceExtractHook('sqlsrv', [__CLASS__, 'patchSQLSRVWin32']); FileSystem::addSourceExtractHook('pdo_sqlsrv', [__CLASS__, 'patchSQLSRVWin32']); FileSystem::addSourceExtractHook('yaml', [__CLASS__, 'patchYamlWin32']); @@ -500,6 +501,12 @@ public static function patchFfiCentos7FixO3strncmp(): bool return true; } + public static function patchStaticReadline(): bool + { + self::patchFile('musl_static_readline.patch', SOURCE_PATH . '/php-src'); + return true; + } + public static function patchPkgConfigForGcc15(): bool { self::patchFile('pkg-config_gcc15.patch', SOURCE_PATH . '/pkg-config'); diff --git a/src/globals/patch/musl_static_readline.patch b/src/globals/patch/musl_static_readline.patch new file mode 100644 index 000000000..196116217 --- /dev/null +++ b/src/globals/patch/musl_static_readline.patch @@ -0,0 +1,26 @@ +diff --git a/ext/readline/readline_cli.c b/ext/readline/readline_cli.c +index 31212999..d80a21c3 100644 +--- a/ext/readline/readline_cli.c ++++ b/ext/readline/readline_cli.c +@@ -739,8 +739,8 @@ typedef cli_shell_callbacks_t *(__cdecl *get_cli_shell_callbacks)(void); + } while(0) + + #else +-/* + #ifdef COMPILE_DL_READLINE ++/* + This dlsym() is always used as even the CGI SAPI is linked against "CLI"-only + extensions. If that is being changed dlsym() should only be used when building + this extension sharedto offer compatibility. +@@ -754,9 +754,9 @@ this extension sharedto offer compatibility. + (cb) = get_callbacks(); \ + } \ + } while(0) +-/*#else ++#else + #define GET_SHELL_CB(cb) (cb) = php_cli_get_shell_callbacks() +-#endif*/ ++#endif + #endif + + PHP_MINIT_FUNCTION(cli_readline) From e621e4a5a1686dfa6f507cfcf012022d83ca2614 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 7 Sep 2025 15:38:38 +0800 Subject: [PATCH 2/3] test --- src/globals/test-extensions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 764cfc7d3..8358d26fe 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -50,7 +50,7 @@ // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'bcmath', + 'Linux', 'Darwin' => 'readline', 'Windows' => 'bcmath,bz2,calendar,ctype,curl,dom,exif,fileinfo,filter,ftp,iconv,xml,mbstring,mbregex,mysqlnd,openssl,pdo,pdo_mysql,pdo_sqlite,phar,session,simplexml,soap,sockets,sqlite3,tokenizer,xmlwriter,xmlreader,zlib,zip', }; From be7c0028698431766428ba61103ecfae10efa5ec Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 7 Sep 2025 16:10:50 +0800 Subject: [PATCH 3/3] Patch only when building cli --- src/SPC/builder/linux/LinuxBuilder.php | 7 +++++++ src/SPC/store/SourcePatcher.php | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 3525ffb7e..91910f7f3 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -170,12 +170,19 @@ public function testPHP(int $build_target = BUILD_TARGET_NONE) */ protected function buildCli(): void { + if ($this->getExt('readline')) { + SourcePatcher::patchFile('musl_static_readline.patch', SOURCE_PATH . '/php-src'); + } $vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars()); $SPC_CMD_PREFIX_PHP_MAKE = getenv('SPC_CMD_PREFIX_PHP_MAKE') ?: 'make'; shell()->cd(SOURCE_PATH . '/php-src') ->exec('sed -i "s|//lib|/lib|g" Makefile') ->exec("{$SPC_CMD_PREFIX_PHP_MAKE} {$vars} cli"); + if ($this->getExt('readline')) { + SourcePatcher::patchFile('musl_static_readline.patch', SOURCE_PATH . '/php-src', true); + } + if (!$this->getOption('no-strip', false)) { shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')->exec('strip --strip-unneeded php'); } diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index eef786549..c08204f5d 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -23,7 +23,6 @@ public static function init(): void FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchPhpLibxml212']); FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchGDWin32']); FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchFfiCentos7FixO3strncmp']); - FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchStaticReadline']); FileSystem::addSourceExtractHook('sqlsrv', [__CLASS__, 'patchSQLSRVWin32']); FileSystem::addSourceExtractHook('pdo_sqlsrv', [__CLASS__, 'patchSQLSRVWin32']); FileSystem::addSourceExtractHook('yaml', [__CLASS__, 'patchYamlWin32']); @@ -501,12 +500,6 @@ public static function patchFfiCentos7FixO3strncmp(): bool return true; } - public static function patchStaticReadline(): bool - { - self::patchFile('musl_static_readline.patch', SOURCE_PATH . '/php-src'); - return true; - } - public static function patchPkgConfigForGcc15(): bool { self::patchFile('pkg-config_gcc15.patch', SOURCE_PATH . '/pkg-config');