ENV/super: set CC and CXX to unversioned gcc on Linux#22889
Merged
Conversation
Formulae often save the build-time value of CC and CXX to be called at runtime; however, this can cause issues on Linux where users may not have the same GCC version. This has led to adding workarounds in formulae like: - `ecl` - https://github.com/Homebrew/homebrew-core/blob/main/Formula/e/ecl.rb#L44-L45 - `ghc` - https://github.com/Homebrew/homebrew-core/blob/main/Formula/g/ghc.rb#L109-L111 And has resulted in rebottling after Ubuntu 24.04 migration for - `hdf5` - `mpich` - `open-mpi` - `octave` - `r` - `root` This PR changes CC/CXX to be unversioned on Linux while keeping versioned HOMEBREW_CC so the shim will always redirect to the selected compiler. On macOS, we keep using versioned CC/CXX because `/usr/bin/gcc` is actually clang which may not be compatible with binaries built with GCC.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts Homebrew’s superenv on Linux so that when a versioned GCC is selected (e.g. gcc-13), CC/CXX are set to the unversioned driver names (gcc/g++) while keeping HOMEBREW_CC (and related shim redirection) versioned. This helps prevent downstream tools/formulae from persisting versioned compiler names that may not exist on user systems.
Changes:
- On Linux, override versioned GCC selection methods to rewrite
CC/CXXtogcc/g++after selecting a versioned compiler. - Add a new RSpec to validate versioned
HOMEBREW_CCand OS-specificCC/CXXbehavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Library/Homebrew/extend/os/linux/extend/ENV/super.rb | Overrides versioned GCC methods on Linux to set unversioned CC/CXX after compiler selection. |
| Library/Homebrew/test/extend/ENV/super_spec.rb | Adds coverage for versioned HOMEBREW_CC and Linux/macOS CC/CXX expectations under versioned GCC. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
93ea65e to
3f8abc7
Compare
p-linnane
approved these changes
Jun 27, 2026
Member
|
Nice work @cho-m! |
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.
brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?Commit description
Formulae often save the build-time value of CC and CXX to be called at runtime; however, this can cause issues on Linux where users may not have the same GCC version.
This has led to adding workarounds in formulae like:
ecl- https://github.com/Homebrew/homebrew-core/blob/main/Formula/e/ecl.rb#L44-L45ghc- https://github.com/Homebrew/homebrew-core/blob/main/Formula/g/ghc.rb#L109-L111And has resulted in rebottling after Ubuntu 24.04 migration for
hdf5mpichopen-mpioctaverrootThis PR changes CC/CXX to be unversioned on Linux while keeping versioned HOMEBREW_CC so the shim will always redirect to the selected compiler.
On macOS, we keep using versioned CC/CXX because
/usr/bin/gccis actually clang which may not be compatible with binaries built with GCC.Other details
As example, existing
open-mpibottle has:Locally building a new bottle with PR, the superenv logs show lines like:
And resulting installation has:
One minor case this doesn't account for is when superenv is bypassed, but that seems like something that we need to fix as superenv should not be bypassed unless we explicitly allow it (e.g. Scons, Bazel, etc)