Use append_cflags for GCC-specific warning flags - #236
Open
hsbt wants to merge 1 commit into
Open
Conversation
cl.exe rejects -Wno-declaration-after-statement with command line error D8021, breaking source builds on x64-mswin64. append_cflags keeps only the flags the compiler actually accepts, so GCC and clang builds are unaffected. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR aims to make the native extension build portable across compilers by avoiding unconditional GCC/clang-only warning flags in extconf.rb, which currently break MSVC builds on Windows.
Changes:
- Replaces a direct
$CFLAGSappend of GCC/clang flags withappend_cflags(...)to (intended) probe and apply only supported flags.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| require 'rbconfig' | ||
|
|
||
| $CFLAGS << ' -Wall -funroll-loops -Wno-declaration-after-statement' | ||
| append_cflags(%w[-Wall -funroll-loops -Wno-declaration-after-statement]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The extconf.rb unconditionally appended -Wall -funroll-loops -Wno-declaration-after-statement to $CFLAGS. These are GCC and clang flags, so building the gem from source on x64-mswin64 with MSVC failed with command line error D8021 because cl.exe cannot parse -Wno-declaration-after-statement.
This switches to append_cflags, which probes each flag and keeps only the ones the active compiler accepts. On GCC and clang all three flags are still applied, so those builds are unchanged. On MSVC only -Wall survives and the source build succeeds. The vendored yajl C sources themselves need no MSVC changes.
now builds with nmake and cl, and Yajl::Parser.parse(Yajl::Encoder.encode({"a" => 1})) works on the resulting install.