Repository navigation
macOS: find libomp in the environment being built into - #58
Jim Garrison (garrison) wants to merge 1 commit into
Conversation
The Darwin block probes $CONDA_PREFIX/include/omp.h and falls back to Homebrew.
That misses the case where the activated environment is not the one being built
into: conda-build and rattler-build activate their own base installation and
install into $PREFIX, so a recipe that puts llvm-openmp in the host environment
still fails with
Error: no OpenMP runtime found on this macOS host.
Looked in $CONDA_PREFIX/include and /opt/homebrew/opt/libomp/include.
on a builder with no Homebrew libomp -- while the header sits unexamined in
$PREFIX. This is what the conda-forge osx_64 build hits.
Consult sys.prefix, then sys.base_prefix, after CONDA_PREFIX and before
Homebrew. sys.prefix is the prefix of the interpreter running setup.py, which
under both build backends is the environment the extension is built for; it is
also the convention _mpi_prefix_from_env_prefix() already uses, which is why MPI
detection succeeded in the same build where OpenMP failed.
CONDA_PREFIX stays first, so an ordinary activated environment behaves exactly
as before. The new candidates can only be reached where the code previously
fell through to Homebrew, so no build that passes today changes behavior.
This serves the intent of the original change rather than reversing it: build
against the libomp that will be LOADED at import time, resolved through the
interpreter's rpath. Linking the base installation's copy while installing into
$PREFIX is how a process ends up with two LLVM OpenMP runtimes, the abort
described in the README and tracked as #27.
The error message listed $CONDA_PREFIX literally, which no longer describes the
set of prefixes searched, so report the paths actually tried, deduplicated.
Assisted-by: Claude Opus 5
The osx_64 build failed with
Error: no OpenMP runtime found on this macOS host.
Looked in $CONDA_PREFIX/include and /opt/homebrew/opt/libomp/include.
although llvm-openmp was installed in the host environment as the recipe asks.
setup.py locates macOS libomp by probing $CONDA_PREFIX/include/omp.h, and under
rattler-build CONDA_PREFIX is the base installation (/Users/runner/miniforge3 on
the builder) rather than the build environment, so the header in $PREFIX went
unexamined and the probe fell through to Homebrew, which the builder does not
have.
Export CONDA_PREFIX=$PREFIX for osx so the probe looks in the environment the
extension is being built into. Scoped to osx because no other platform consults
it: the Darwin branch is the only caller.
This is a workaround for an upstream path assumption, fixed properly in
Qiskit/sbd-eigensolver-python#58, which also consults sys.prefix. Remove it once
a release carrying that change is available.
Assisted-by: Claude Opus 5
|
The conda-forge That run confirms the diagnosis behind this PR, but it did not execute this PR's code, so I want to be exact about what it shows. The recipe builds from the released 1.7.0 sdist, which carries the current — the existing wording, from the released code, but resolving to The macOS jobs in this repository do not cover the new code path either. They Validating this change on macOSThe new path needs a build where the activated environment differs from the one being installed into, which is what conda-build and # 1. This branch, with the submodule the build needs
git clone --recurse-submodules -b darwin-openmp-build-prefix \
https://github.com/Qiskit/sbd-eigensolver-python
# 2. The conda-forge recipe
curl -O https://raw.githubusercontent.com/garrison/staged-recipes/sbd-eigensolver/recipes/sbd-eigensolver/recipe.yaml
curl -O https://raw.githubusercontent.com/garrison/staged-recipes/sbd-eigensolver/recipes/sbd-eigensolver/conda_build_config.yamlThen edit rattler-build build --recipe recipe.yaml --variant-config conda_build_config.yamlExpected: the build succeeds and prints The authentic test arrives on its own once a release carries this change and the recipe drops the workaround: conda-forge's macOS CI then exercises the This comment was drafted by Claude Opus 5 under my guidance. |
On macOS the build locates
libompby probing$CONDA_PREFIX/include/omp.h, falling back to Homebrew. That misses the case where the activated environment is not the one being built into. conda-build and rattler-build activate their own base installation and install into$PREFIX, so a recipe that providesllvm-openmpstill fails:on a builder with no Homebrew
libomp— while the header sits unexamined in$PREFIX. This is what the conda-forgeosx_64build hits (staged-recipes#35125), whereCONDA_PREFIXis/Users/runner/miniforge3andllvm-openmp 21.1.8is installed in the host environment.The change
Consult
sys.prefix, thensys.base_prefix, afterCONDA_PREFIXand before Homebrew.sys.prefixis the prefix of the interpreter runningsetup.py, which under both build backends is the environment the extension is built for. It is also the convention_mpi_prefix_from_env_prefix()already uses — which is why MPI detection succeeded in the same build where OpenMP failed.CONDA_PREFIXstays first, so an ordinary activated environment behaves exactly as before. The new candidates are reachable only where the code previously fell through to Homebrew, so no build that passes today changes behavior.This serves the intent of the original logic rather than reversing it: build against the
libompthat will be loaded at import time, resolved through the interpreter's rpath. Linking the base installation's copy while installing into$PREFIXis one way to end up with two LLVM OpenMP runtimes in one process — the abort described in the README and tracked as #27.The error message named
$CONDA_PREFIXliterally, which no longer describes the set of prefixes searched, so it now reports the paths actually tried, deduplicated.Verification
The changed branch is
platform.system() == 'Darwin'-only, so it is unreachable on Linux. I exercised the prefix selection directly across six cases: activated environment with the header present (unchanged); activated prefix without it but the build prefix with it (the failure above, now resolved); neither, so the Homebrew fallback still engages; both, confirmingCONDA_PREFIXkeeps precedence;CONDA_PREFIXunset; and onlysys.base_prefixcarrying it.I do not have a macOS host, so the end-to-end check is the conda-forge
osx_64build. I will report back once it has run against this change.This pull request was drafted by Claude Opus 5 under my guidance.