-
-
Notifications
You must be signed in to change notification settings - Fork 12.9k
open-mpi: force build with Homebrew’s brewed GCC #230544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Thanks @abhinavsns! |
I'm not sure I understand the motivation for this change.
Isn't this a reason to avoid using GCC whenever possible?
Can you give concrete examples of issues for downstream formula that this change would fix? |
Formula/o/open-mpi.rb
Outdated
# Force use of Homebrew's default GCC | ||
gcc = Formula["gcc"] | ||
ENV["CC"] = gcc.opt_bin/"gcc-#{gcc.version.major}" | ||
ENV["CXX"] = gcc.opt_bin/"g++-#{gcc.version.major}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't the right way to force the use of GCC -- see openblas.rb
for how to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Fixed.
Set ENV["CC"] and ENV["CXX"] to the Homebrew GCC shims (gcc-<major>, g++-<major>) so that Open MPI always compiles with the brewed GNU toolchain rather than Apple’s Clang. This prevents breakage of GCC’s fixed headers on Xcode/Clang upgrades and ensures ABI consistency for downstream MPI-using formulae (e.g. PETSc, Trilinos) that rely on gfortran and MPI wrappers. Bump revision to rebuild bottles under the new settings.
Apple’s Clang 17 disables “relaxed template-template arguments” by default. Any library that relies on that older, more permissive rule now stops at the compile stage with errors like
That pattern can shows up in slightly older versions of several widely-used scientific libraries (PETSc, Trilinos, deal.II, etc.) once they are compiled through mpicxx. GCC 12-15 still accept the code, so an Open MPI built with brewed GCC simply sidesteps the new Clang restriction and everything builds again, no extra flags or patches. Further, mpifort is built around gfortran, which comes only from the Homebrew gcc formula. Right now we mix clang and gcc. That split toolchain can introduce subtle ABI mismatches. Building all three wrappers with the same GCC version makes the compiler stack consistent end-to-end. The idea here is to get immunity from further Clang template-diagnostic tightenings that Apple may ship in future Xcode releases. We could also have version controlled openmpi from brew because Apple does not allow older Clang versions easily via command line. |
I see another problem with this. Apple notoriously links |
This patch makes Open MPI always compile with the Homebrew-installed GCC (e.g. gcc-11, gcc-12, etc.) rather than Apple’s system Clang. By setting ENV["CC"]/ENV["CXX"] to the brewed-GCC shims at install time, we ensure:
Stability across Xcode/Clang upgrades. Every time Apple bumps its Clang, the “fixed headers” in GCC can go out of sync (see e.g. errors in include-fixed/stdio.h), breaking MPI builds.
Consistency for downstream formula that rely on GNU Fortran (gfortran) and MPI wrappers—PETSc, Trilinos, etc.—so that they all link against the same compiler and runtime ABI.
Minimal user overhead: folks who already depend on gcc (as Open MPI does) get the correct toolchain “for free,” without extra flags or brew extract hacks.
This change preserves all existing options and defaults (no user-visible flag changes) and only affects the build environment. We bump revision to force users’ bottles to rebuild under the new compiler settings.
HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source <formula>
, where<formula>
is the name of the formula you're submitting?brew test <formula>
, where<formula>
is the name of the formula you're submitting?brew audit --strict <formula>
(after doingHOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source <formula>
)? If this is a new formula, does it passbrew audit --new <formula>
?