From 2d5abd31c1876410677578f3ec8c9d9109accd1f Mon Sep 17 00:00:00 2001 From: henderkes Date: Fri, 29 May 2026 23:15:53 +0700 Subject: [PATCH] micro patch for cross-arch 32 bit builds --- src/Package/Library/ncurses.php | 1 + src/Package/Target/php/unix.php | 9 +++++++++ src/StaticPHP/Util/SourcePatcher.php | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/src/Package/Library/ncurses.php b/src/Package/Library/ncurses.php index e27cefcd..74e3a30f 100644 --- a/src/Package/Library/ncurses.php +++ b/src/Package/Library/ncurses.php @@ -65,6 +65,7 @@ class ncurses '--without-tests', '--without-dlsym', '--without-debug', + '--disable-stripping', '--enable-symlinks', "--with-terminfo-dirs={$terminfo_dirs}", "--bindir={$package->getBinDir()}", diff --git a/src/Package/Target/php/unix.php b/src/Package/Target/php/unix.php index d6324209..2e6dcaa2 100644 --- a/src/Package/Target/php/unix.php +++ b/src/Package/Target/php/unix.php @@ -42,6 +42,15 @@ trait unix // php-src patches from micro (reads SPC_MICRO_PATCHES env var) SourcePatcher::patchPhpSrc(); + $microFileinfo = "{$package->getSourceDir()}/sapi/micro/php_micro_fileinfo.c"; + if (is_file($microFileinfo) && !str_contains((string) file_get_contents($microFileinfo), 'Elf32_Shdr')) { + FileSystem::replaceFileStr( + $microFileinfo, + 'typedef Elf32_Ehdr Elf_Ehdr;', + 'typedef Elf32_Ehdr Elf_Ehdr; typedef Elf32_Shdr Elf_Shdr;', + ); + } + // patch configure.ac for musl and musl-toolchain $musl = SystemTarget::getTargetOS() === 'Linux' && SystemTarget::getLibc() === 'musl'; FileSystem::backupFile(SOURCE_PATH . '/php-src/configure.ac'); diff --git a/src/StaticPHP/Util/SourcePatcher.php b/src/StaticPHP/Util/SourcePatcher.php index 70525e67..520ef3a8 100644 --- a/src/StaticPHP/Util/SourcePatcher.php +++ b/src/StaticPHP/Util/SourcePatcher.php @@ -168,6 +168,9 @@ class SourcePatcher */ public static function patchMicroPhar(int $version_id): void { + if (file_exists(SOURCE_PATH . '/php-src/ext/phar/phar.c.bak')) { + return; + } FileSystem::backupFile(SOURCE_PATH . '/php-src/ext/phar/phar.c'); FileSystem::replaceFileStr( SOURCE_PATH . '/php-src/ext/phar/phar.c', @@ -193,6 +196,12 @@ class SourcePatcher public static function unpatchMicroPhar(): void { + // Tolerate a missing .bak: both drivers call this, and the first restore + // consumes the backup. Without this guard the second call throws + // "Cannot find bak file". No .bak means the source is already pristine. + if (!file_exists(SOURCE_PATH . '/php-src/ext/phar/phar.c.bak')) { + return; + } FileSystem::restoreBackupFile(SOURCE_PATH . '/php-src/ext/phar/phar.c'); }