Skip to content

Commit 4d2036f

Browse files
dunglasclaude
andcommitted
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) <noreply@anthropic.com>
1 parent 105f032 commit 4d2036f

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

src/SPC/builder/extension/xlswriter.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace SPC\builder\extension;
66

77
use SPC\builder\Extension;
8-
use SPC\store\FileSystem;
98
use SPC\store\SourcePatcher;
109
use SPC\util\CustomExt;
10+
use SPC\util\GlobalEnvManager;
1111

1212
#[CustomExt('xlswriter')]
1313
class xlswriter extends Extension
@@ -30,14 +30,9 @@ public function patchBeforeMake(): bool
3030
{
3131
$patched = parent::patchBeforeMake();
3232

33-
// Fix K&R C function declaration in bundled minizip rejected by modern Clang (C23 default)
34-
$mztools = $this->source_dir . '/library/libxlsxwriter/third_party/minizip/mztools.c';
35-
if (file_exists($mztools)) {
36-
FileSystem::replaceFileStr(
37-
$mztools,
38-
"extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered)\nconst char* file;\nconst char* fileOut;\nconst char* fileOutTmp;\nuLong* nRecovered;\nuLong* bytesRecovered;\n{",
39-
"extern int ZEXPORT unzRepair(const char* file, const char* fileOut, const char* fileOutTmp, uLong* nRecovered, uLong* bytesRecovered)\n{"
40-
);
33+
// Bundled minizip uses K&R C function declarations rejected by C23 (default on macOS with Xcode 16+)
34+
if (PHP_OS_FAMILY !== 'Windows') {
35+
GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS=' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') . ' -std=gnu17');
4136
$patched = true;
4237
}
4338

@@ -53,4 +48,9 @@ public function patchBeforeMake(): bool
5348
}
5449
return $patched;
5550
}
51+
52+
protected function getExtraEnv(): array
53+
{
54+
return ['CFLAGS' => '-std=gnu17'];
55+
}
5656
}

0 commit comments

Comments
 (0)