From 8a34cc8a926fd868e7b4b84249e3482bee78ed85 Mon Sep 17 00:00:00 2001 From: Antoine Lambert Date: Tue, 26 Nov 2024 22:35:24 +0100 Subject: [PATCH] gha/macos-wheels: Build wheels for arm64 architecture --- .../workflows/macos-macports-wheels-build.yml | 47 ++++++++++++++----- .../talipot-core/packaging/setup.py.in | 15 ++++++ 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/.github/workflows/macos-macports-wheels-build.yml b/.github/workflows/macos-macports-wheels-build.yml index 4af8143503..533c5ec6d1 100644 --- a/.github/workflows/macos-macports-wheels-build.yml +++ b/.github/workflows/macos-macports-wheels-build.yml @@ -2,14 +2,25 @@ name: macos-macports-wheels-build on: [push, pull_request] jobs: macos: - name: Talipot Python wheels build on macOS - runs-on: macos-12 + name: ${{ matrix.config.name }} + runs-on: ${{ matrix.config.os }} + strategy: + fail-fast: false + matrix: + config: + - name: Talipot wheels build on macOS x86_64 + os: macos-12 + macosx_deployment_target: "12.0" + - name: Talipot wheels build on macOS arm64 + os: macos-14 + macosx_deployment_target: "14.0" env: CLANG_VERSION: 16 - MACOSX_DEPLOYMENT_TARGET: "12.0" + MACOSX_DEPLOYMENT_TARGET: ${{ matrix.config.macosx_deployment_target }} TWINE_REPOSITORY: https://test.pypi.org/legacy/ TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }} + steps: - name: Cancel Previous Runs uses: styfle/cancel-workflow-action@0.12.1 @@ -77,11 +88,14 @@ jobs: graphviz - name: Install Python versions to build wheels against run: | - curl -LO https://www.python.org/ftp/python/3.9.0/python-3.9.0-macosx10.9.pkg - sudo installer -pkg python-3.9.0-macosx10.9.pkg -target / - sudo /Library/Frameworks/Python.framework/Versions/3.9/bin/pip3 install wheel - curl -LO https://www.python.org/ftp/python/3.10.0/python-3.10.0post2-macos11.pkg - sudo installer -pkg python-3.10.0post2-macos11.pkg -target / + os_ver=$(sw_vers -productVersion | cut -c1-2) + if [[ $os_ver -lt 13 ]]; then + curl -LO https://www.python.org/ftp/python/3.9.0/python-3.9.0-macosx10.9.pkg + sudo installer -pkg python-3.9.0-macosx10.9.pkg -target / + sudo /Library/Frameworks/Python.framework/Versions/3.9/bin/pip3 install wheel + fi + curl -LO https://www.python.org/ftp/python/3.10.10/python-3.10.10-macos11.pkg + sudo installer -pkg python-3.10.10-macos11.pkg -target / sudo /Library/Frameworks/Python.framework/Versions/3.10/bin/pip3 install wheel curl -LO https://www.python.org/ftp/python/3.11.0/python-3.11.0-macos11.pkg sudo installer -pkg python-3.11.0-macos11.pkg -target / @@ -97,7 +111,13 @@ jobs: - name: Build Talipot Python wheels working-directory: ./build run: | - for py3Version in 3.9 3.10 3.11 3.12 3.13 + os_ver=$(sw_vers -productVersion | cut -c1-2) + if [[ $os_ver -lt 13 ]]; then + py3Versions="3.9 3.10 3.11 3.12 3.13" + else + py3Versions="3.10 3.11 3.12 3.13" + fi + for py3Version in $py3Versions do rm -f CMakeCache.txt || true sudo /Library/Frameworks/Python.framework/Versions/$py3Version/bin/pip3 install sip @@ -120,6 +140,7 @@ jobs: - name: Test uploaded wheels in clean environment if: github.ref == 'refs/tags/dev-latest' run: | + os_ver=$(sw_vers -productVersion | cut -c1-2) sudo port -N -f uninstall \ cmake \ clang-${CLANG_VERSION} \ @@ -140,9 +161,11 @@ jobs: python313 \ py313-pip - sudo pip-3.9 install --index-url https://test.pypi.org/simple/ talipot - python3.9 -c "from talipot import tlp; print(tlp.getLayoutAlgorithmPluginsList())" - python3.9 -c "from talipot import tlp; print(tlp.getImportPluginsList())" + if [[ $os_ver -lt 13 ]]; then + sudo pip-3.9 install --index-url https://test.pypi.org/simple/ talipot + python3.9 -c "from talipot import tlp; print(tlp.getLayoutAlgorithmPluginsList())" + python3.9 -c "from talipot import tlp; print(tlp.getImportPluginsList())" + fi sudo pip-3.10 install --index-url https://test.pypi.org/simple/ talipot python3.10 -c "from talipot import tlp; print(tlp.getLayoutAlgorithmPluginsList())" diff --git a/library/talipot-python/bindings/talipot-core/packaging/setup.py.in b/library/talipot-python/bindings/talipot-core/packaging/setup.py.in index 2988f43461..124da254e0 100644 --- a/library/talipot-python/bindings/talipot-core/packaging/setup.py.in +++ b/library/talipot-python/bindings/talipot-core/packaging/setup.py.in @@ -11,6 +11,9 @@ import subprocess import sys import shutil +from wheel.bdist_wheel import bdist_wheel +from wheel._bdist_wheel import get_platform + # On MacOS, we need to relink dylibs and set correct rpaths in # order for the modules to be imported in a portable way when # distributed through pip @@ -111,6 +114,17 @@ elif platform.system() == 'Linux': talipot_native_libs = ['native/*.so*', 'native/plugins/*.so', 'native/graphviz/*.so'] + +class CustomWheel(bdist_wheel): + """Override platform tags on macOS when building a wheel.""" + + def finalize_options(self): + platform_name = get_platform("_") + if "universal2" in platform_name: + self.plat_name = platform_name.replace("universal2", platform.uname().machine) + super().finalize_options() + + here = path.abspath(path.dirname(__file__)) with open(path.join(here, 'README.rst'), encoding='utf-8') as f: @@ -183,4 +197,5 @@ setup( include_package_data=True, distclass=BinaryDistribution, + cmdclass={"bdist_wheel": CustomWheel}, )