|
| 1 | +# This workflow builds the Python wheels using cibuildwheel and uploads them to TestPyPI. |
| 2 | +# It can be triggered on push to the develop branch or manually via Github Actions. |
| 3 | + |
| 4 | +name: Build Wheels for Release |
| 5 | + |
| 6 | +on: |
| 7 | + release: |
| 8 | + types: [published] |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +jobs: |
| 12 | + build_wheels: |
| 13 | + name: Build Wheels |
| 14 | + runs-on: ${{ matrix.os }} |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + include: |
| 19 | + # Linux x86_64 |
| 20 | + - os: ubuntu-latest |
| 21 | + python_version: "3.10" |
| 22 | + cibw_python_version: 310 |
| 23 | + platform_id: manylinux_x86_64 |
| 24 | + manylinux_image: manylinux2014 |
| 25 | + - os: ubuntu-latest |
| 26 | + python_version: "3.11" |
| 27 | + cibw_python_version: 311 |
| 28 | + platform_id: manylinux_x86_64 |
| 29 | + manylinux_image: manylinux2014 |
| 30 | + - os: ubuntu-latest |
| 31 | + python_version: "3.12" |
| 32 | + cibw_python_version: 312 |
| 33 | + platform_id: manylinux_x86_64 |
| 34 | + manylinux_image: manylinux2014 |
| 35 | + - os: ubuntu-latest |
| 36 | + python_version: "3.13" |
| 37 | + cibw_python_version: 313 |
| 38 | + platform_id: manylinux_x86_64 |
| 39 | + manylinux_image: manylinux2014 |
| 40 | + |
| 41 | + # Linux aarch64 |
| 42 | + - os: ubuntu-24.04-arm |
| 43 | + python_version: "3.10" |
| 44 | + cibw_python_version: 310 |
| 45 | + platform_id: manylinux_aarch64 |
| 46 | + manylinux_image: manylinux2014 |
| 47 | + - os: ubuntu-24.04-arm |
| 48 | + python_version: "3.11" |
| 49 | + cibw_python_version: 311 |
| 50 | + platform_id: manylinux_aarch64 |
| 51 | + manylinux_image: manylinux2014 |
| 52 | + - os: ubuntu-24.04-arm |
| 53 | + python_version: "3.12" |
| 54 | + cibw_python_version: 312 |
| 55 | + platform_id: manylinux_aarch64 |
| 56 | + manylinux_image: manylinux2014 |
| 57 | + - os: ubuntu-24.04-arm |
| 58 | + python_version: "3.13" |
| 59 | + cibw_python_version: 313 |
| 60 | + platform_id: manylinux_aarch64 |
| 61 | + manylinux_image: manylinux2014 |
| 62 | + |
| 63 | + # MacOS x86_64 |
| 64 | + - os: macos-13 |
| 65 | + python_version: "3.10" |
| 66 | + cibw_python_version: 310 |
| 67 | + platform_id: macosx_x86_64 |
| 68 | + - os: macos-13 |
| 69 | + python_version: "3.11" |
| 70 | + cibw_python_version: 311 |
| 71 | + platform_id: macosx_x86_64 |
| 72 | + - os: macos-13 |
| 73 | + python_version: "3.12" |
| 74 | + cibw_python_version: 312 |
| 75 | + platform_id: macosx_x86_64 |
| 76 | + - os: macos-13 |
| 77 | + python_version: "3.13" |
| 78 | + cibw_python_version: 313 |
| 79 | + platform_id: macosx_x86_64 |
| 80 | + |
| 81 | + # MacOS arm64 |
| 82 | + - os: macos-14 |
| 83 | + python_version: "3.10" |
| 84 | + cibw_python_version: 310 |
| 85 | + platform_id: macosx_arm64 |
| 86 | + - os: macos-14 |
| 87 | + python_version: "3.11" |
| 88 | + cibw_python_version: 311 |
| 89 | + platform_id: macosx_arm64 |
| 90 | + - os: macos-14 |
| 91 | + python_version: "3.12" |
| 92 | + cibw_python_version: 312 |
| 93 | + platform_id: macosx_arm64 |
| 94 | + - os: macos-14 |
| 95 | + python_version: "3.13" |
| 96 | + cibw_python_version: 313 |
| 97 | + platform_id: macosx_arm64 |
| 98 | + |
| 99 | + steps: |
| 100 | + - name: Checkout |
| 101 | + uses: actions/checkout@v4 |
| 102 | + with: |
| 103 | + fetch-depth: 0 |
| 104 | + ref: ${{ github.sha }} |
| 105 | + |
| 106 | + - name: Set up Python ${{ matrix.python_version }} |
| 107 | + uses: actions/setup-python@v5 |
| 108 | + with: |
| 109 | + python-version: ${{ matrix.python_version }} |
| 110 | + |
| 111 | + - name: Install Dependencies |
| 112 | + run: | |
| 113 | + python3 -m pip install -r python/dev_requirements.txt |
| 114 | + if [ "$RUNNER_OS" == "Linux" ]; then |
| 115 | + sudo apt-get install -y wget libicu-dev python3-pip python3-setuptools libboost-all-dev ninja-build |
| 116 | + elif [ "$RUNNER_OS" == "macOS" ]; then |
| 117 | + brew install boost ninja python-setuptools |
| 118 | + else |
| 119 | + echo "$RUNNER_OS not supported" |
| 120 | + exit 1 |
| 121 | + fi |
| 122 | +
|
| 123 | + # We first build the Python wrapper module on the host machine. This is done because cibuildwheel |
| 124 | + # expects a setup.py file to be present in the project directory. |
| 125 | + # |
| 126 | + # The Python wrapper module is then rebuilt within the cibuildwheel container before building |
| 127 | + # the wheels to ensure platform compatibility. |
| 128 | + - name: Run CMake |
| 129 | + run: | |
| 130 | + cmake . -B build -DGTSAM_BUILD_PYTHON=1 -DGTSAM_PYTHON_VERSION=${{ matrix.python_version }} |
| 131 | +
|
| 132 | + # If on macOS, we previously installed boost using homebrew for the first build. |
| 133 | + # We need to uninstall it before building the wheels with cibuildwheel, which will |
| 134 | + # install boost from source. |
| 135 | + - name: Uninstall Boost (MacOS) |
| 136 | + if: runner.os == 'macOS' |
| 137 | + run: | |
| 138 | + brew uninstall boost |
| 139 | +
|
| 140 | + - name: Build and test wheels |
| 141 | + env: |
| 142 | + # Generate the platform identifier. See https://cibuildwheel.pypa.io/en/stable/options/#build-skip. |
| 143 | + CIBW_BUILD: cp${{ matrix.cibw_python_version }}-${{ matrix.platform_id }} |
| 144 | + CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux_image }} |
| 145 | + CIBW_MANYLINUX_AARCH64_IMAGE: ${{ matrix.manylinux_image }} |
| 146 | + CIBW_ARCHS: all |
| 147 | + |
| 148 | + # Set the minimum required MacOS version for the wheels. |
| 149 | + MACOSX_DEPLOYMENT_TARGET: 10.15 |
| 150 | + |
| 151 | + # Set DYLD_LIBRARY_PATH to REPAIR_LIBRARY_PATH, which is set in cibw_before_all.sh. REPAIR_LIBRARY_PATH |
| 152 | + # simply appends BOOST_LIBRARYDIR to the path, which is required during during link-time repair. |
| 153 | + CIBW_REPAIR_WHEEL_COMMAND_MACOS: DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel} |
| 154 | + |
| 155 | + # Use build instead of pip wheel to build the wheels. This is recommended by PyPA. |
| 156 | + # See https://cibuildwheel.pypa.io/en/stable/options/#build-frontend. |
| 157 | + CIBW_BUILD_FRONTEND: "build" |
| 158 | + CIBW_BEFORE_ALL: bash .github/scripts/python_wheels/cibw_before_all.sh ${{ matrix.python_version }} {project} |
| 159 | + |
| 160 | + CIBW_BUILD_VERBOSITY: 1 |
| 161 | + |
| 162 | + run: bash .github/scripts/python_wheels/build_wheels.sh |
| 163 | + |
| 164 | + - name: Store artifacts |
| 165 | + uses: actions/upload-artifact@v4 |
| 166 | + with: |
| 167 | + name: cibw-wheels-cp${{ matrix.cibw_python_version }}-${{ matrix.platform_id }} |
| 168 | + path: wheelhouse/*.whl |
| 169 | + |
| 170 | + upload_all: |
| 171 | + name: Upload All |
| 172 | + needs: build_wheels |
| 173 | + runs-on: ubuntu-latest |
| 174 | + permissions: |
| 175 | + id-token: write |
| 176 | + steps: |
| 177 | + - name: Download Artifacts |
| 178 | + uses: actions/download-artifact@v4 |
| 179 | + with: |
| 180 | + path: dist/ |
| 181 | + merge-multiple: true |
| 182 | + |
| 183 | + - name: Publish to PyPI |
| 184 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 185 | + with: |
| 186 | + verbose: true |
| 187 | + packages-dir: dist/ |
| 188 | + repository-url: https://test.pypi.org/legacy/ |
0 commit comments