Skip to content

Add macOS support - #20

Open
Jim Garrison (garrison) wants to merge 1 commit into
mainfrom
macos-support
Open

Add macOS support#20
Jim Garrison (garrison) wants to merge 1 commit into
mainfrom
macos-support

Conversation

@garrison

Copy link
Copy Markdown
Member

Declares Linux and macOS in the trove classifiers, and extends the test matrix to cover both.

Test matrix

test_latest_versions.yml now splits the dependency step by runner.os, following the pattern in qiskit-c-api-demo's test_latest_versions.yml: apt on Linux, Homebrew on macOS. The macOS side installs libomp in addition to the Linux set, since Apple clang ships without OpenMP support.

The matrix goes from 5 cells to 10 (ubuntu-latest and macos-latest × Python 3.10–3.14). fail-fast: false is added so that one failing cell doesn't hide the state of the rest — worth having now that a break could be specific to one OS.

setup.py fixes

There was already a platform.system() == 'Darwin' branch for the CPU extension, but three things in it would have kept the new macOS cells from building:

  • Homebrew paths were hardcoded to /opt/homebrew. That is right on Apple silicon and wrong on Intel. It now asks brew --prefix, falling back to the old value when brew isn't on PATH.
  • The rpath used -Wl,--rpath, a GNU ld spelling that Apple's linker rejects. Both linkers accept -Wl,-rpath, so that form is now used on both platforms.
  • The Darwin branch replaced extra_link_args wholesale and so emitted no rpath at all, which leaves the keg-only libomp and openblas dylibs unresolvable at import time. It now derives rpath entries over its own library dirs. It can't just reuse extra_link_args, because the bare -fopenmp in there is rejected by Apple clang at link time the same way it is when compiling.

Also drops a duplicate -lomp (libraries already supplies it), adds -DOMPI_SKIP_MPICXX to match the Linux branch, and hoists import platform to the top of the file now that two places use it.

Verification

The rpath spelling change affects Linux as well, so I checked it isn't a regression there: the built extension still carries RUNPATH, and both tox -e py and tox -e mpi pass.

The macOS cells themselves are unverified until CI runs on this PR — I have no Mac to test on locally, and that is the main thing to watch here.


This PR was generated by Claude Opus 5 under my guidance.

Declare Linux and macOS in the trove classifiers, and extend the test
matrix to cover both.

The workflow now splits the dependency step by `runner.os`, following
qiskit-c-api-demo's test_latest_versions.yml: apt on Linux, Homebrew on
macOS. The macOS side additionally installs libomp, since Apple clang
ships without OpenMP. `fail-fast: false` keeps one failing cell from
hiding the state of the rest of the matrix.

Three things in setup.py's existing Darwin branch would have kept that
new matrix half from building:

- The Homebrew paths were hardcoded to /opt/homebrew, which is correct
  on Apple silicon and wrong on Intel. Ask `brew --prefix` instead,
  keeping the old value as the fallback when brew is absent.
- The rpath used `-Wl,--rpath`, a GNU ld spelling Apple's linker
  rejects. Both linkers accept `-Wl,-rpath`, so use that on both.
- The Darwin branch replaced extra_link_args wholesale and so emitted no
  rpath at all, leaving the keg-only libomp and openblas dylibs
  unresolvable at import time. It now derives rpath entries over its own
  library dirs; it cannot reuse extra_link_args directly, because the
  bare `-fopenmp` in there is rejected by Apple clang at link time too.

Also drop the duplicate `-lomp` (`libraries` already supplies it), add
-DOMPI_SKIP_MPICXX to match the Linux branch, and hoist `import platform`
to the top now that two places use it.

Verified on Linux that the rpath change is not a regression: the built
extension still carries RUNPATH, and `tox -e py` and `tox -e mpi` pass.

Assisted-by: Claude Opus 5
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