From 6c00f782b92a894d8d7e6a9a1f2a6d17c6477124 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Thu, 22 Oct 2026 10:34:48 +0800 Subject: [PATCH] fix(rar): keep the PHP Windows SDK WINVER for unrar os.hpp unrar/os.hpp unconditionally redefines WINVER/_WIN32_WINNT to Windows XP. The generated main/internal_functions.c includes it before urlmon.h, so the mixed SDK versions break urlmon.h parsing (C2059 around PARSEACTION) in every Windows spc-max build. Guard both defines so the values chosen by the PHP build are preserved. --- src/Package/Extension/rar.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Package/Extension/rar.php b/src/Package/Extension/rar.php index f260d79bd..70ea94174 100644 --- a/src/Package/Extension/rar.php +++ b/src/Package/Extension/rar.php @@ -61,4 +61,26 @@ public function patchUnrarCpuDetectionForZig(): void { SourcePatcher::patchFile('rar_unrar_get_cpuid.patch', $this->getBuildDir()); } + + #[BeforeStage('php', [php::class, 'makeForWindows'], 'ext-rar')] + #[PatchDescription('Keep the PHP Windows SDK WINVER/_WIN32_WINNT when unrar os.hpp is included')] + public function patchUnrarWindowsVersion(): void + { + $file = $this->getBuildDir() . '/unrar/os.hpp'; + if (!is_file($file)) { + return; + } + + // unrar/os.hpp unconditionally changes WINVER/_WIN32_WINNT to Windows XP. + // PHP's Windows build already defines them for the modern SDK, and the generated + // main/internal_functions.c includes this header before urlmon.h. Mixing SDK + // versions in one TU makes urlmon.h fail with C2059 around PARSEACTION, which + // breaks every spc-max build. Keep the values the build already selected. + FileSystem::replaceFileRegex( + $file, + '/^#define WINVER _WIN32_WINNT_WINXP\r?\n#define _WIN32_WINNT _WIN32_WINNT_WINXP/m', + "#ifndef WINVER\n#define WINVER _WIN32_WINNT_WINXP\n#endif\n" + . "#ifndef _WIN32_WINNT\n#define _WIN32_WINNT _WIN32_WINNT_WINXP\n#endif" + ); + } }