Skip to content

Build PETSc on macOS without the Homebrew library path - #961

Merged
timlichtenberg merged 6 commits into
mainfrom
tl/petsc-brew-ldflags
Oct 7, 2026
Merged

timlichtenberg merged 6 commits into
mainfrom
tl/petsc-brew-ldflags

Conversation

@timlichtenberg

@timlichtenberg timlichtenberg commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Description

On macOS, tools/get_petsc.sh no longer puts the Homebrew library directory into PETSc's LDFLAGS. With a Homebrew SUNDIALS 7 installed, that -L made the linker pick it up before the SUNDIALS 2.5 that PETSc downloads, and configure failed with "Downloaded sundials2 could not be used" (CVDense and CVSpgmr missing). LDFLAGS is now only -Wl,-w; the system MPI still links, because mpicc adds its own library path.

  • The architecture check for the Homebrew prefix goes with it, since the prefix was only used for that -L.
  • A test runs the macOS platform and configure steps of the script with stub tools, under set -euo pipefail, and checks that configure gets LDFLAGS=-Wl,-w and --download-sundials2, that no argument carries -L, and that LDFLAGS, LIBRARY_PATH, LIBS and CPATH are not exported with the Homebrew library directory. The two tests of the removed prefix logic go. Two more cases cover the script without mpicc (configure gets --download-mpich with the same flags) and without xcrun (the script stops with its message before configure).
  • The troubleshooting page has an entry for this failure, and the manual configure command and the install page match the script.

On an Intel Mac, Homebrew installs into /usr/local/lib, which the linker searches by default, so a Homebrew SUNDIALS can still hide PETSc's there; the troubleshooting entry says so. The same change for the standalone SPIDER script is in FormingWorlds/SPIDER#19.

Validation of changes

Full PETSc builds from this branch with Homebrew Open MPI 5.0.11: configure, build and the PETSc check examples (ex19 on 1 and 2 MPI ranks) pass; with the old flags configure fails on the same Mac with a Homebrew SUNDIALS 7.9 installed. tests/tools/test_install_scripts.py: 102 passed; the new test fails when a Homebrew -L or LIBRARY_PATH is put back.

Tested on an M1 Ultra, macOS 26.6.2, Python 3.12.

Checklist

  • I have followed the contributing guidelines
  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • My changes generate no new warnings or errors
  • I have checked that the tests still pass on my computer
  • I have updated the docs, as appropriate
  • I have added tests for these changes, as appropriate
  • I have checked that all dependencies have been updated, as required

With -L$(brew --prefix)/lib in LDFLAGS, a Homebrew SUNDIALS (7.x) sits ahead of the SUNDIALS 2.5 that PETSc downloads, so configure cannot link CVDense and CVSpgmr and stops with "Downloaded sundials2 could not be used". The system MPI does not need the path: mpicc adds its own -L. LDFLAGS now only carries -Wl,-w, which keeps the macOS 26 linker warnings from failing configure.
The test now looks at every code line of get_petsc.sh for a -L library path instead of two exact LDFLAGS values, and the manual configure command in the troubleshooting guide no longer adds the Homebrew library path.
The test runs the shipped platform and configure steps of get_petsc.sh as macOS with a system MPI and a stub configure, and checks that no argument carries -L and that LDFLAGS=-Wl,-w arrives, which catches any spelling of a library path.
The stub configure also records its environment, the shipped steps run under set -euo pipefail as in the script, and the test checks that --download-sundials2 reaches configure.
The macOS configure test checks that LDFLAGS, LIBRARY_PATH, LIBS and CPATH stay unset and that no exported variable names the Homebrew library directory. The troubleshooting docs describe the "Downloaded sundials2 could not be used" failure that a Homebrew SUNDIALS causes, and that Intel Macs can still hit it. The install docs say the script uses the MPI on PATH.
Without mpicc on PATH, configure gets --download-mpich and still only LDFLAGS=-Wl,-w with no library path; without xcrun, the script stops with its install hint before configure runs. Both cases run with PATH limited to the stub tools.
@codecov

codecov Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.58%. Comparing base (4936a75) to head (1aca468).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #961   +/-   ##
=======================================
  Coverage   93.57%   93.58%           
=======================================
  Files         127      127           
  Lines       21186    21186           
  Branches     3597     3597           
=======================================
+ Hits        19824    19826    +2     
+ Misses        941      940    -1     
+ Partials      421      420    -1     
Flag Coverage Δ
nightly 93.54% <ø> (ø)
unit-tests 92.19% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timlichtenberg
timlichtenberg merged commit 285d662 into main Oct 7, 2026
41 checks passed
@timlichtenberg
timlichtenberg deleted the tl/petsc-brew-ldflags branch October 7, 2026 03:58
timlichtenberg added a commit to FormingWorlds/SPIDER that referenced this pull request Oct 7, 2026
On macOS, tools/get_petsc.sh no longer puts the Homebrew library directory into PETSc's LDFLAGS. With a Homebrew SUNDIALS 7 installed, that -L made the linker pick it up before the SUNDIALS 2.5 that PETSc downloads, and configure failed with "Downloaded sundials2 could not be used". LDFLAGS is now only -Wl,-w; the system MPI still links because mpicc adds its own library path. The architecture check for the Homebrew prefix goes with it.

A test runs the macOS platform and configure steps of the script with stub tools and checks the configure arguments and the exported environment, with cases for a missing mpicc and a missing xcrun. The installation page has a troubleshooting entry for this failure, including the Intel Mac limit where /usr/local/lib is on the default search path. The same change for the PROTEUS copy of the script is FormingWorlds/PROTEUS#961.
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.

1 participant