thaler-lab / Wasserstein

Python/C++ library for computing Wasserstein distances efficiently.
https://thaler-lab.github.io/Wasserstein
Other
21 stars 8 forks source link

macOS wheel build fails while repairing wheel with `delocate.libsana.DelocationError` #28

Closed matthewfeickert closed 3 weeks ago

matthewfeickert commented 4 weeks ago

Related to Issues:

During

https://github.com/thaler-lab/Wasserstein/blob/0a0fdeb810fc6f6b55fe773ea75fef7febb02047/.github/workflows/build-wheels.yml#L75-L87

https://github.com/thaler-lab/Wasserstein/blob/0a0fdeb810fc6f6b55fe773ea75fef7febb02047/scripts/build-wheels-and-upload.sh#L9

the build fails in the "Repairing wheel" stage with a delocate.libsana.DelocationError

Repairing wheel...

  + delocate-wheel --require-archs x86_64 -w /private/var/folders/vy/h7r6h43j203gstfh6fj9_tyh0000gn/T/cibw-run-a9vgw6o1/cp37-macosx_x86_64/repaired_wheel -v /private/var/folders/vy/h7r6h43j203gstfh6fj9_tyh0000gn/T/cibw-run-a9vgw6o1/cp37-macosx_x86_64/built_wheel/Wasserstein-1.1.0-cp37-cp37m-macosx_10_9_x86_64.whl
  INFO:delocate.delocating:Copying library /usr/local/lib/libomp.dylib to wasserstein/.dylibs/libomp.dylib
  INFO:delocate.delocating:Modifying install name in wasserstein/_wasserstein_omp.cpython-37m-darwin.so from @rpath/libomp.dylib to @loader_path/.dylibs/libomp.dylib
  Fixing: /private/var/folders/vy/h7r6h43j203gstfh6fj9_tyh0000gn/T/cibw-run-a9vgw6o1/cp37-macosx_x86_64/built_wheel/Wasserstein-1.1.0-cp37-cp37m-macosx_10_9_x86_64.whl
  Traceback (most recent call last):
    File "/private/var/folders/vy/h7r6h43j203gstfh6fj9_tyh0000gn/T/cibw-run-a9vgw6o1/cp37-macosx_x86_64/build/venv/bin/delocate-wheel", line 8, in <module>
      sys.exit(main())
    File "/private/var/folders/vy/h7r6h43j203gstfh6fj9_tyh0000gn/T/cibw-run-a9vgw6o1/cp37-macosx_x86_64/build/venv/lib/python3.7/site-packages/delocate/cmd/delocate_wheel.py", line 116, in main
      **delocate_values(args),
    File "/private/var/folders/vy/h7r6h43j203gstfh6fj9_tyh0000gn/T/cibw-run-a9vgw6o1/cp37-macosx_x86_64/build/venv/lib/python3.7/site-packages/delocate/delocating.py", line 1005, in delocate_wheel
      out_wheel_, Path(wheel_dir), require_target_macos_version
    File "/private/var/folders/vy/h7r6h43j203gstfh6fj9_tyh0000gn/T/cibw-run-a9vgw6o1/cp37-macosx_x86_64/build/venv/lib/python3.7/site-packages/delocate/delocating.py", line 840, in _check_and_update_wheel_name
      "Library dependencies do not satisfy target MacOS"
  delocate.libsana.DelocationError: Library dependencies do not satisfy target MacOS version 10.9:
  /private/var/folders/vy/h7r6h43j203gstfh6fj9_tyh0000gn/T/tmprdp8i5mn/wheel/wasserstein/.dylibs/libomp.dylib has a minimum target of 13.6
  Error: Command delocate-wheel --require-archs x86_64 -w /private/var/folders/vy/h7r6h43j203gstfh6fj9_tyh0000gn/T/cibw-run-a9vgw6o1/cp37-macosx_x86_64/repaired_wheel -v /private/var/folders/vy/h7r6h43j203gstfh6fj9_tyh0000gn/T/cibw-run-a9vgw6o1/cp37-macosx_x86_64/built_wheel/Wasserstein-1.1.0-cp37-cp37m-macosx_10_9_x86_64.whl failed with code 1. 

so it seems the wrong version of libomp is being found even if running on a branch that follows PR https://github.com/thaler-lab/Wasserstein/pull/24.

matthewfeickert commented 4 weeks ago

In PR #24 libomp is built and installed under /usr/local/lib/

[100%] Built target omp
-- Install configuration: "Release"
-- Installing: /usr/local/lib/libomp.dylib
-- Installing: /usr/local/include/omp.h
-- Installing: /usr/local/include/ompx.h
-- Installing: /usr/local/include/omp-tools.h
-- Installing: /usr/local/include/ompt.h

and delocate finds it for the copy in the error message

...
INFO:delocate.delocating:Copying library /usr/local/lib/libomp.dylib to wasserstein/.dylibs/libomp.dylib
...

so I don't follow why

      "Library dependencies do not satisfy target MacOS"
  delocate.libsana.DelocationError: Library dependencies do not satisfy target MacOS version 10.9:
  /private/var/folders/vy/h7r6h43j203gstfh6fj9_tyh0000gn/T/tmprdp8i5mn/wheel/wasserstein/.dylibs/libomp.dylib has a minimum target of 13.6

is happening when the llvm omp should be fine. :?

We might need @henryiii to give a debugging direction hint later this week.

henryiii commented 4 weeks ago

Are you setting MACOSX_DEPLOYMENT_TARGET when building?

matthewfeickert commented 4 weeks ago

Are you setting MACOSX_DEPLOYMENT_TARGET when building?

No. I'm going to assume that this is just another example of why

https://github.com/thaler-lab/Wasserstein/blob/0a0fdeb810fc6f6b55fe773ea75fef7febb02047/scripts/build-wheels-and-upload.sh#L5-L9

isn't sufficient and https://github.com/thaler-lab/Wasserstein/issues/10 should also include migrating the wheel building to something like boost-histogram's.

matthewfeickert commented 4 weeks ago

I didn't know what MACOSX_DEPLOYMENT_TARGET was, but this is covered in macOS and deployment target versions cibuildwheel docs.

From reading there, my understanding is that the default MACOSX_DEPLOYMENT_TARGET value set by cibuildwheel is 10.9 and you need to manually adjust it through setting the MACOSX_DEPLOYMENT_TARGET based on how far backwards compatible you want to be.

Given that the current build has a comparatively high target of 13.6

      "Library dependencies do not satisfy target MacOS"
  delocate.libsana.DelocationError: Library dependencies do not satisfy target MacOS version 10.9:
  /private/var/folders/vy/h7r6h43j203gstfh6fj9_tyh0000gn/T/tmprdp8i5mn/wheel/wasserstein/.dylibs/libomp.dylib has a minimum target of 13.6

I'm going to assume that means that the version of llvm omp in PR https://github.com/thaler-lab/Wasserstein/pull/24 built from

      - name: Checkout LLVM on macOS
        uses: actions/checkout@v4
        with:
          repository: llvm/llvm-project
          ref: release/18.x
          path: llvm-project

      - name: Build OpenMP on macOS
        run: |
          cd llvm-project
          cmake \
            -DCMAKE_BUILD_TYPE=Release \
            -DCMAKE_INSTALL_PREFIX=$(brew --prefix) \
            -DCMAKE_C_COMPILER=clang \
            -DCMAKE_CXX_COMPILER=clang++ \
            -DLIBOMP_INSTALL_ALIASES=OFF \
            -S openmp \
            -B build
          cmake \
            --build build \
            --parallel
          cmake --install build
          cd "$GITHUB_WORKSPACE"

is using C++ features that are modern enough to push things up, and so to drop down to a lower target the https://github.com/llvm/llvm-project release branch should be changed to something older than release/18.x.

matthewfeickert commented 4 weeks ago

drop down to a lower target the https://github.com/llvm/llvm-project release branch should be changed to something older than release/18.x.

Through empirical testing release/17.x works for macos-13 with pypa/cibuildwheel@v2.14.

Though with pypa/cibuildwheel@v2.19 everything fails, including release/11.x and

https://github.com/thaler-lab/Wasserstein/blob/0a0fdeb810fc6f6b55fe773ea75fef7febb02047/scripts/install-libomp-macos.sh#L3

previously worked in the past.

So I don't think I understand enough about what cibuildwheel is doing between these releases do know why things are breaking.

henryiii commented 4 weeks ago

You are building this outside of cibuildwheel. So you need to set it manually.

henryiii commented 4 weeks ago
      - name: Build OpenMP on macOS
        env:
          MACOSX_DEPLOYMENT_TARGET: "10.9"
        working-directory: llvm-project
        run: |
          cmake -Sopenmp -Bbuild \
            -DCMAKE_BUILD_TYPE=Release \
            -DCMAKE_INSTALL_PREFIX=$(brew --prefix) \
            -DCMAKE_C_COMPILER=clang \
            -DCMAKE_CXX_COMPILER=clang++ \
            -DLIBOMP_INSTALL_ALIASES=OFF \
          cmake --build build --parallel 4
          cmake --install build
matthewfeickert commented 3 weeks ago

Resolved in PR #24, given https://github.com/thaler-lab/Wasserstein/issues/28#issuecomment-2178278452, so closing.