Fix C++ standard probe to match actual build environment (ICU 76+)#204
Open
nielsonrolim wants to merge 1 commit into
Open
Fix C++ standard probe to match actual build environment (ICU 76+)#204nielsonrolim wants to merge 1 commit into
nielsonrolim wants to merge 1 commit into
Conversation
The auto-detect added in e6bf734 used `try_compile` with `gcc -x c++`, which on modern GCC defaults to a newer C++ standard than the `-std=gnu++11` that Ruby's RbConfig bakes into `CXX`. On Fedora 44 with GCC 15 and ICU 77 the probe silently passed while the real .cpp build still failed with hundreds of errors out of ICU's headers (`std::u16string_view`, `std::enable_if_t`, `auto` non-type template parameters, etc.). Mirror the `-std=` from `CXX` into the probe so it reflects what `.cpp` files will actually be compiled with, and append the discovered standard to `$CXXFLAGS` instead of `$CPPFLAGS` so it only applies to C++ sources (a later `-std=` overrides the one baked into `CXX` on gcc/clang). Fixes brianmario#203. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Fixes #203 —
charlock_holmesfails to build against ICU 76+ on systems where the compiler's "raw" C++ default is newer thang++ -std=gnu++11.The C++-standard auto-detect added in e6bf734 probes with
try_compileplus-x c++, which on modern GCC (e.g. GCC 15 on Fedora 44) defaults to a C++17+ standard. The real.cppbuild, however, usesRbConfig::CONFIG["CXX"], which on most Ruby builds isg++ -std=gnu++11. The probe therefore silently passes whiletransliterator.cppstill fails with hundreds of errors out of ICU's headers (std::u16string_view,std::enable_if_t,autonon-type template parameters, etc.).This PR makes the probe represent reality by:
-std=flag baked intoCXXinto thetry_compileinvocation, so the probe fails exactly when the real build would fail.-std=...to$CXXFLAGS(so it only affects.cppcompilation) instead of$CPPFLAGS(which also leaked-x c++and-std=c++17onto the.ccompile lines).A later
-std=overrides the one baked intoCXXon both gcc and clang, so this cleanly upgrades the standard for ICU's headers without disturbing the rest of the build.Test plan
Reproduced the failure on the affected environment (Fedora 44, GCC 15, ICU 77.1, Ruby 4.0.3) and verified:
checking for icu that requires explicit C++ version flag... nofollowed bymakefailing intransliterator.cppwithstd::u16string_view,enable_if_t, andautotemplate parameter errors.checking for icu that requires explicit C++ version flag... yes→checking for icu that compiles with c++20 standard... yes, andrake compile testpasses (27 runs, 120 assertions, 0 failures, 0 errors).CXXFLAGS = ... -std=c++20 ...(only on the C++ rule) — the.cfiles no longer get the C++ standard flag.🤖 Generated with Claude Code