From 105f0328e6405735e1adf27dadb5788375d2ff74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Wed, 8 Apr 2026 21:33:59 +0200 Subject: [PATCH 1/3] fix(xlswriter): convert K&R function declaration to ANSI C in bundled minizip The bundled minizip in xlswriter (pinned at libxlsxwriter RELEASE_1.0.0) uses a K&R-style function declaration in mztools.c. Modern Clang on macOS (defaulting to C23) rejects this as a hard syntax error since K&R declarations were removed from the C23 standard. The upstream libxlsxwriter has already fixed this on their main branch. This patch applies the same fix during the build process. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/SPC/builder/extension/xlswriter.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/SPC/builder/extension/xlswriter.php b/src/SPC/builder/extension/xlswriter.php index 24d32d947..7d0350fcc 100644 --- a/src/SPC/builder/extension/xlswriter.php +++ b/src/SPC/builder/extension/xlswriter.php @@ -5,6 +5,7 @@ namespace SPC\builder\extension; use SPC\builder\Extension; +use SPC\store\FileSystem; use SPC\store\SourcePatcher; use SPC\util\CustomExt; @@ -28,6 +29,18 @@ public function getWindowsConfigureArg(bool $shared = false): string public function patchBeforeMake(): bool { $patched = parent::patchBeforeMake(); + + // Fix K&R C function declaration in bundled minizip rejected by modern Clang (C23 default) + $mztools = $this->source_dir . '/library/libxlsxwriter/third_party/minizip/mztools.c'; + if (file_exists($mztools)) { + FileSystem::replaceFileStr( + $mztools, + "extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered)\nconst char* file;\nconst char* fileOut;\nconst char* fileOutTmp;\nuLong* nRecovered;\nuLong* bytesRecovered;\n{", + "extern int ZEXPORT unzRepair(const char* file, const char* fileOut, const char* fileOutTmp, uLong* nRecovered, uLong* bytesRecovered)\n{" + ); + $patched = true; + } + if (PHP_OS_FAMILY === 'Windows') { // fix windows build with openssl extension duplicate symbol bug SourcePatcher::patchFile('spc_fix_xlswriter_win32.patch', $this->source_dir); From 4d2036f20ea693f34f667421793fb1f66d200ee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Thu, 9 Apr 2026 08:49:49 +0200 Subject: [PATCH 2/3] fix(xlswriter): use -std=gnu17 to fix K&R declarations rejected by C23 The bundled minizip in xlswriter has K&R C function declarations in multiple files (mztools.c, ioapi.c). Apple Clang (Xcode 16+) defaults to C23, which removed K&R from the standard, causing hard build errors. Instead of patching individual files, downgrade the C standard to gnu17 for the whole build when xlswriter is enabled. This covers all K&R occurrences in the bundled code. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/SPC/builder/extension/xlswriter.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/SPC/builder/extension/xlswriter.php b/src/SPC/builder/extension/xlswriter.php index 7d0350fcc..cb5c82bc1 100644 --- a/src/SPC/builder/extension/xlswriter.php +++ b/src/SPC/builder/extension/xlswriter.php @@ -5,9 +5,9 @@ namespace SPC\builder\extension; use SPC\builder\Extension; -use SPC\store\FileSystem; use SPC\store\SourcePatcher; use SPC\util\CustomExt; +use SPC\util\GlobalEnvManager; #[CustomExt('xlswriter')] class xlswriter extends Extension @@ -30,14 +30,9 @@ public function patchBeforeMake(): bool { $patched = parent::patchBeforeMake(); - // Fix K&R C function declaration in bundled minizip rejected by modern Clang (C23 default) - $mztools = $this->source_dir . '/library/libxlsxwriter/third_party/minizip/mztools.c'; - if (file_exists($mztools)) { - FileSystem::replaceFileStr( - $mztools, - "extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered)\nconst char* file;\nconst char* fileOut;\nconst char* fileOutTmp;\nuLong* nRecovered;\nuLong* bytesRecovered;\n{", - "extern int ZEXPORT unzRepair(const char* file, const char* fileOut, const char* fileOutTmp, uLong* nRecovered, uLong* bytesRecovered)\n{" - ); + // Bundled minizip uses K&R C function declarations rejected by C23 (default on macOS with Xcode 16+) + if (PHP_OS_FAMILY !== 'Windows') { + GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS=' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') . ' -std=gnu17'); $patched = true; } @@ -53,4 +48,9 @@ public function patchBeforeMake(): bool } return $patched; } + + protected function getExtraEnv(): array + { + return ['CFLAGS' => '-std=gnu17']; + } } From fb7730989c08119326f23ea2d338042f782860c4 Mon Sep 17 00:00:00 2001 From: Marc Date: Thu, 9 Apr 2026 14:00:10 +0700 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Marc --- src/SPC/builder/extension/xlswriter.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/extension/xlswriter.php b/src/SPC/builder/extension/xlswriter.php index cb5c82bc1..8ef826d00 100644 --- a/src/SPC/builder/extension/xlswriter.php +++ b/src/SPC/builder/extension/xlswriter.php @@ -30,7 +30,7 @@ public function patchBeforeMake(): bool { $patched = parent::patchBeforeMake(); - // Bundled minizip uses K&R C function declarations rejected by C23 (default on macOS with Xcode 16+) + // Remove when https://github.com/viest/php-ext-xlswriter/pull/560 is merged if (PHP_OS_FAMILY !== 'Windows') { GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS=' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') . ' -std=gnu17'); $patched = true; @@ -49,6 +49,7 @@ public function patchBeforeMake(): bool return $patched; } + // Remove when https://github.com/viest/php-ext-xlswriter/pull/560 is merged protected function getExtraEnv(): array { return ['CFLAGS' => '-std=gnu17'];