Skip to content

ENV/super: set CC and CXX to unversioned gcc on Linux#22889

Merged
cho-m merged 4 commits into
mainfrom
linux-unversioned-gcc
Jul 1, 2026
Merged

ENV/super: set CC and CXX to unversioned gcc on Linux#22889
cho-m merged 4 commits into
mainfrom
linux-unversioned-gcc

Conversation

@cho-m

@cho-m cho-m commented Jun 26, 2026

Copy link
Copy Markdown
Member

  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • AI was used to generate or assist with generating this PR.

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:

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.


Other details

As example, existing open-mpi bottle has:

$ mpicc -show
gcc-13 -I/home/linuxbrew/.linuxbrew/Cellar/open-mpi/5.0.9/include -L/home/linuxbrew/.linuxbrew/Cellar/open-mpi/5.0.9/lib -Wl,-rpath -Wl,/home/linuxbrew/.linuxbrew/Cellar/open-mpi/5.0.9/lib -Wl,--enable-new-dtags -lmpi

Locally building a new bottle with PR, the superenv logs show lines like:

gcc called with: -E /var/tmp/cgv8NSK3/dummy.c
superenv added:    -isystem/home/linuxbrew/.linuxbrew/include -fdebug-prefix-map=/var/tmp/open-mpi-20260626-2423654-sgk8g7/openmpi-5.0.9=. -mbranch-protection=standard
superenv executed: gcc-13 -E /var/tmp/cgv8NSK3/dummy.c -isystem/home/linuxbrew/.linuxbrew/include -fdebug-prefix-map=/var/tmp/open-mpi-20260626-2423654-sgk8g7/openmpi-5.0.9=. -mbranch-protection=standard

And resulting installation has:

$ mpicc -show
gcc -I/home/linuxbrew/.linuxbrew/Cellar/open-mpi/5.0.9/include -L/home/linuxbrew/.linuxbrew/Cellar/open-mpi/5.0.9/lib -Wl,-rpath -Wl,/home/linuxbrew/.linuxbrew/Cellar/open-mpi/5.0.9/lib -Wl,--enable-new-dtags -lmpi

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)

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.
Copilot AI review requested due to automatic review settings June 26, 2026 18:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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/CXX to gcc/g++ after selecting a versioned compiler.
  • Add a new RSpec to validate versioned HOMEBREW_CC and OS-specific CC/CXX behavior.

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.

Comment thread Library/Homebrew/extend/os/linux/extend/ENV/super.rb
Comment thread Library/Homebrew/test/extend/ENV/super_spec.rb Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread Library/Homebrew/test/extend/ENV/super_spec.rb Outdated
Comment thread Library/Homebrew/test/extend/ENV/super_spec.rb Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread Library/Homebrew/test/extend/ENV/super_spec.rb Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@cho-m cho-m added this pull request to the merge queue Jul 1, 2026
Merged via the queue into main with commit 15d0912 Jul 1, 2026
42 checks passed
@cho-m cho-m deleted the linux-unversioned-gcc branch July 1, 2026 20:44
@MikeMcQuaid

Copy link
Copy Markdown
Member

Nice work @cho-m!

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