Skip to content

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

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

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.
  • tests/test_get_petsc_ldflags.py 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. 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 installation page has a troubleshooting entry for this failure. 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 same change for the PROTEUS copy of the script is in FormingWorlds/PROTEUS#961.

Testing: a full PETSc build from this branch with Homebrew Open MPI 5.0.11 passes configure, build and the PETSc check examples (ex19 on 1 and 2 MPI ranks); the new test fails when a Homebrew -L or LIBRARY_PATH is put back. Tested on an M1 Ultra, macOS 26.6.2.

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.
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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The test lacks required edge/error-path coverage, and the Intel troubleshooting entry omits recovery instructions.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

Removes the Homebrew library path from macOS PETSc configuration to avoid selecting incompatible SUNDIALS versions.

Changes:

  • Uses only -Wl,-w for macOS linker flags.
  • Adds a stubbed configuration test.
  • Documents the SUNDIALS conflict.
File Description
tools/​get_petsc.sh Removes Homebrew’s library path from PETSc linker flags.
tests/​test_get_petsc_ldflags.py Tests macOS configure arguments and environment.
docs/​How-to/​installation.md Adds troubleshooting guidance for SUNDIALS conflicts.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/test_get_petsc_ldflags.py Outdated
Comment thread docs/How-to/installation.md
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.
timlichtenberg added a commit to FormingWorlds/PROTEUS 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 troubleshooting page has an entry for this failure, including the Intel Mac limit where /usr/local/lib is on the default search path. The same change for the standalone SPIDER script is FormingWorlds/SPIDER#19.
@timlichtenberg
timlichtenberg merged commit 6dfb150 into main Oct 7, 2026
8 checks passed
@timlichtenberg
timlichtenberg deleted the tl/petsc-brew-ldflags branch October 7, 2026 04:02
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.

2 participants