From 24231f793af156f601ba482936f6f87084a5ddef Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 12 Apr 2026 16:05:06 +0800 Subject: [PATCH 1/2] Enhance debug flag handling in Makefile for release builds --- src/Package/Target/php/windows.php | 50 +++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/src/Package/Target/php/windows.php b/src/Package/Target/php/windows.php index 561628f0..cffe04dc 100644 --- a/src/Package/Target/php/windows.php +++ b/src/Package/Target/php/windows.php @@ -140,14 +140,19 @@ trait windows // We need to modify CFLAGS to replace /Ox with /Zi and add /DEBUG to LDFLAGS $debug_overrides = ''; if ($package->getBuildOption('no-strip', false)) { - // Read current CFLAGS from Makefile and replace optimization flags + // Read current CFLAGS and LDFLAGS from Makefile $makefile_content = file_get_contents("{$package->getSourceDir()}\\Makefile"); if (preg_match('/^CFLAGS=(.+?)$/m', $makefile_content, $matches)) { $cflags = $matches[1]; // Replace /Ox (full optimization) with /Zi (debug info) and /Od (disable optimization) // Keep optimization for speed: /O2 /Zi instead of /Od /Zi $cflags = str_replace('/Ox ', '/O2 /Zi ', $cflags); - $debug_overrides = '"CFLAGS=' . $cflags . '" "LDFLAGS=/DEBUG /LTCG /INCREMENTAL:NO" "LDFLAGS_CLI=/DEBUG" '; + // Append debug flags to existing LDFLAGS to preserve /libpath entries set by configure + $ldflags = ''; + if (preg_match('/^LDFLAGS=(.+?)$/m', $makefile_content, $lm)) { + $ldflags = trim($lm[1]) . ' '; + } + $debug_overrides = '"CFLAGS=' . $cflags . '" "LDFLAGS=' . $ldflags . '/DEBUG /LTCG /INCREMENTAL:NO" "LDFLAGS_CLI=/DEBUG" '; } } @@ -209,7 +214,12 @@ trait windows if (preg_match('/^CFLAGS=(.+?)$/m', $makefile_content, $matches)) { $cflags = $matches[1]; $cflags = str_replace('/Ox ', '/O2 /Zi ', $cflags); - $debug_overrides = '"CFLAGS=' . $cflags . '" "LDFLAGS=/DEBUG /LTCG /INCREMENTAL:NO" "LDFLAGS_CGI=/DEBUG" '; + // Append debug flags to existing LDFLAGS to preserve /libpath entries set by configure + $ldflags = ''; + if (preg_match('/^LDFLAGS=(.+?)$/m', $makefile_content, $lm)) { + $ldflags = trim($lm[1]) . ' '; + } + $debug_overrides = '"CFLAGS=' . $cflags . '" "LDFLAGS=' . $ldflags . '/DEBUG /LTCG /INCREMENTAL:NO" "LDFLAGS_CGI=/DEBUG" '; } } @@ -247,6 +257,23 @@ trait windows // workaround for fiber (originally from https://github.com/dixyes/lwmbs/blob/master/windows/MicroBuild.php) $makefile = FileSystem::readFile("{$package->getSourceDir()}\\Makefile"); + + // Add debug symbols for release build if --no-strip is specified. + // Extract CFLAGS/LDFLAGS here, before fiber content is appended, to ensure the regex works on clean content. + $debug_overrides = ''; + if ($package->getBuildOption('no-strip', false)) { + if (preg_match('/^CFLAGS=(.+?)$/m', $makefile, $matches)) { + $cflags = $matches[1]; + $cflags = str_replace('/Ox ', '/O2 /Zi ', $cflags); + // Append debug flags to existing LDFLAGS to preserve /libpath entries set by configure + $ldflags = ''; + if (preg_match('/^LDFLAGS=(.+?)$/m', $makefile, $lm)) { + $ldflags = trim($lm[1]) . ' '; + } + $debug_overrides = '"CFLAGS=' . $cflags . '" "LDFLAGS=' . $ldflags . '/DEBUG /LTCG /INCREMENTAL:NO" "LDFLAGS_MICRO=/DEBUG" '; + } + } + if ($this->getPHPVersionID() >= 80200 && str_contains($makefile, 'FIBER_ASM_ARCH')) { $makefile .= "\r\n" . '$(MICRO_SFX): $(BUILD_DIR)\Zend\jump_$(FIBER_ASM_ARCH)_ms_pe_masm.obj $(BUILD_DIR)\Zend\make_$(FIBER_ASM_ARCH)_ms_pe_masm.obj' . "\r\n\r\n"; } elseif ($this->getPHPVersionID() >= 80400 && str_contains($makefile, 'FIBER_ASM_ABI')) { @@ -267,16 +294,6 @@ trait windows // extra lib $extra_libs = trim((getenv('SPC_EXTRA_LIBS') ?: '') . ' ' . implode(' ', $resolved_libs)); - // Add debug symbols for release build if --no-strip is specified - $debug_overrides = ''; - if ($package->getBuildOption('no-strip', false)) { - $makefile_content = file_get_contents("{$package->getSourceDir()}\\Makefile"); - if (preg_match('/^CFLAGS=(.+?)$/m', $makefile_content, $matches)) { - $cflags = $matches[1]; - $cflags = str_replace('/Ox ', '/O2 /Zi ', $cflags); - $debug_overrides = '"CFLAGS=' . $cflags . '" "LDFLAGS=/DEBUG /LTCG /INCREMENTAL:NO" "LDFLAGS_MICRO=/DEBUG" '; - } - } $fake_cli = $package->getBuildOption('with-micro-fake-cli', false) ? ' /DPHP_MICRO_FAKE_CLI' : ''; @@ -387,7 +404,12 @@ trait windows if (preg_match('/^CFLAGS=(.+?)$/m', $makefile_content, $matches)) { $cflags = $matches[1]; $cflags = str_replace('/Ox ', '/O2 /Zi ', $cflags); - $debug_overrides = '"CFLAGS=' . $cflags . '" "LDFLAGS=/DEBUG /LTCG /INCREMENTAL:NO" '; + // Append debug flags to existing LDFLAGS to preserve /libpath entries set by configure + $ldflags = ''; + if (preg_match('/^LDFLAGS=(.+?)$/m', $makefile_content, $lm)) { + $ldflags = trim($lm[1]) . ' '; + } + $debug_overrides = '"CFLAGS=' . $cflags . '" "LDFLAGS=' . $ldflags . '/DEBUG /LTCG /INCREMENTAL:NO" '; } } From 75a7b21a6ff15ccbbe3dea5abf43af141f25dc59 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 12 Apr 2026 16:05:20 +0800 Subject: [PATCH 2/2] Add patch to ensure ext/json MINIT runs before ext/decimal on Windows static builds --- src/Package/Extension/decimal.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Package/Extension/decimal.php b/src/Package/Extension/decimal.php index 147f7388..c5059e2e 100644 --- a/src/Package/Extension/decimal.php +++ b/src/Package/Extension/decimal.php @@ -26,4 +26,16 @@ class decimal extends PhpExtensionPackage 'zend_module_entry php_decimal_module_entry' ); } + + #[BeforeStage('php', [php::class, 'buildconfForWindows'], 'ext-decimal')] + #[PatchDescription('Ensure ext/json MINIT runs before ext/decimal on Windows static builds')] + public function patchConfigW32(): void + { + FileSystem::replaceFileStr( + $this->getSourceDir() . '/config.w32', + 'ARG_WITH("decimal", "for decimal support", "no");', + 'ARG_WITH("decimal", "for decimal support", "no");' . "\n" . + 'ADD_EXTENSION_DEP("decimal", "json");' + ); + } }