Skip to content

Fix macOS/unix desktop build with newer Clang (17+)#103

Merged
ThomasFarstrike merged 2 commits into
MicroPythonOS:mainfrom
bitcoin3us:fix/macos-clang-build-warnings
Mar 31, 2026
Merged

Fix macOS/unix desktop build with newer Clang (17+)#103
ThomasFarstrike merged 2 commits into
MicroPythonOS:mainfrom
bitcoin3us:fix/macos-clang-build-warnings

Conversation

@bitcoin3us
Copy link
Copy Markdown
Contributor

Summary

  • Modern Clang (17+, shipped with Xcode 15+) treats -Wgnu-folding-constant and -Wmissing-field-initializers as errors under -Werror, breaking the desktop build
  • build_mpos.sh now temporarily patches the unix Makefile CWARN to suppress these warnings, then restores after build
  • Follows the same pattern already used for the @micropython.viper decorator

Errors fixed

py/emitnative.c: error: variable length array folded to constant array [-Werror,-Wgnu-folding-constant]
lcd_bus/modlcd_bus.c: error: missing field 'defval' initializer [-Werror,-Wmissing-field-initializers]

Test plan

  • Run scripts/build_mpos.sh macOS on macOS with Xcode 15+ (Clang 17+)
  • Verify build completes successfully
  • Verify Makefile is restored after build

🤖 Generated with Claude Code

Modern Clang treats -Wgnu-folding-constant and
-Wmissing-field-initializers as errors under -Werror, breaking
the desktop build. Temporarily suppress these warnings during
the build, matching the existing pattern for the viper decorator.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@ThomasFarstrike
Copy link
Copy Markdown
Contributor

Awesome!

I guess the only thing to do is make sure the fix is not applied for the Linux builds, or somehow limit it, because now those failed with:

cc1: note: unrecognized command-line option ‘-Wno-unused-command-line-argument’ may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option ‘-Wno-bitwise-instead-of-logical’ may have been intended to silence earlier diagnostics
cc1: error: ‘-Wno-error=gnu-folding-constant’: no option ‘-Wgnu-folding-constant’
cc1: note: unrecognized command-line option ‘-Wno-unused-command-line-argument’ may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option ‘-Wno-bitwise-instead-of-logical’ may have been intended to silence earlier diagnostics
cc1: error: ‘-Wno-error=gnu-folding-constant’: no option ‘-Wgnu-folding-constant’
cc1: note: unrecognized command-line option ‘-Wno-unused-command-line-argument’ may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option ‘-Wno-bitwise-instead-of-logical’ may have been intended to silence earlier diagnostics
cc1: error: ‘-Wno-error=gnu-folding-constant’: no option ‘-Wgnu-folding-constant’
cc1: note: unrecognized command-line option ‘-Wno-unused-command-line-argument’ may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option ‘-Wno-bitwise-instead-of-logical’ may have been intended to silence earlier diagnostics
make: *** [../../py/mkrules.mk:133: build-standard/genhdr/qstr.i.last] Error 1

GCC on Linux doesn't have -Wgnu-folding-constant, so applying
these flags breaks the Linux build. Guard the Makefile patch
with a Darwin check so it only runs on macOS.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@bitcoin3us
Copy link
Copy Markdown
Contributor Author

Good catch — GCC doesn't have -Wgnu-folding-constant. Updated to only apply the warning suppression on macOS (uname -s = Darwin), leaving Linux builds untouched.

@ThomasFarstrike ThomasFarstrike merged commit 8a6ff0f into MicroPythonOS:main Mar 31, 2026
4 checks passed
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.

2 participants