Skip to content

fix(xlswriter): fix macOS build with modern Clang (C23)#1086

Merged
henderkes merged 3 commits intocrazywhalecc:mainfrom
dunglas:fix/xlswriter-macos-kr-declaration
Apr 9, 2026
Merged

fix(xlswriter): fix macOS build with modern Clang (C23)#1086
henderkes merged 3 commits intocrazywhalecc:mainfrom
dunglas:fix/xlswriter-macos-kr-declaration

Conversation

@dunglas
Copy link
Copy Markdown
Contributor

@dunglas dunglas commented Apr 8, 2026

Summary

  • 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 defaults to C23, which removed K&R function definitions from the standard — this causes a hard syntax error, not a suppressible warning
  • The upstream libxlsxwriter main branch already has the ANSI C fix; the PECL extension just pins an old release
  • This patch converts the K&R declaration to ANSI C in patchBeforeMake(), matching the upstream fix

Error

ext/xlswriter/library/libxlsxwriter/third_party/minizip/mztools.c:30:30: error: unknown type name 'file'
   30 | extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered)

Test plan

  • Verify the fix applies cleanly by checking the string replacement targets match the actual source from PECL xlswriter
  • macOS build should succeed with this patch

🤖 Generated with Claude Code

… 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) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 8, 2026 19:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the xlswriter extension build patching step to fix a macOS build failure with modern Clang/C23 by converting a K&R-style unzRepair declaration in bundled minizip to an ANSI C prototype.

Changes:

  • Add a patchBeforeMake() replacement targeting libxlsxwriter/third_party/minizip/mztools.c to rewrite the K&R-style unzRepair signature into an ANSI C declaration.
  • Import and use SPC\store\FileSystem to perform the in-file string replacement.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/SPC/builder/extension/xlswriter.php Outdated
@henderkes
Copy link
Copy Markdown
Collaborator

It sounds like it makes sense, but I'm building on Linux in C23 mode with Clang, too. I would like to understand why it only fails on mac.

@dunglas
Copy link
Copy Markdown
Contributor Author

dunglas commented Apr 9, 2026

It's an Apple-specific change: Apple Clang (shipped with Xcode 16 on the macos-15 runners) defaults to C23, while upstream LLVM Clang on Linux still defaults to -std=gnu17 even in recent versions.

@crazywhalecc
Copy link
Copy Markdown
Owner

Using main branch I have no build error on my machine (macOS 15) but only if I use -std=c23 explicitly, I got error message.

And looks like ext-xlswriter -> libxlswriter -> minizip -> ioapi.c have K&R C function declaration too, which also need to be patched.

@henderkes
Copy link
Copy Markdown
Collaborator

I think the better course of action here is to explicitly pin to std=c17 until it's fixed upstream: viest/php-ext-xlswriter#559

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>
@dunglas
Copy link
Copy Markdown
Contributor Author

dunglas commented Apr 9, 2026

@crazywhalecc @henderkes You're right, ioapi.c also has K&R declarations. I've updated the PR to use -std=gnu17 instead of patching individual files — this covers all K&R occurrences in the bundled minizip. Added via both SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS (for static builds) and getExtraEnv() (for shared/phpize builds).

I've also opened a PR upstream to update libxlsxwriter: viest/php-ext-xlswriter#560 — once that's merged, this -std=gnu17 workaround can be removed.

Comment thread src/SPC/builder/extension/xlswriter.php Outdated
Comment thread src/SPC/builder/extension/xlswriter.php
Co-authored-by: Marc <m@pyc.ac>

// 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');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use gnu17 here instead of c17?

Copy link
Copy Markdown
Owner

@crazywhalecc crazywhalecc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works fine on my mac.

@henderkes henderkes merged commit 20f95ef into crazywhalecc:main Apr 9, 2026
6 checks passed
crazywhalecc added a commit that referenced this pull request Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants