Build wheels #97
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build wheels | |
| on: | |
| push: | |
| branches: | |
| - master | |
| pull_request: | |
| workflow_dispatch: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
| cancel-in-progress: true | |
| jobs: | |
| generate_wheels_matrix: | |
| name: Generate wheels matrix | |
| runs-on: ubuntu-latest | |
| outputs: | |
| include: ${{ steps.set-matrix.outputs.include }} | |
| steps: | |
| - id: set-matrix | |
| shell: python | |
| run: | | |
| import json | |
| import os | |
| import pprint | |
| # Platforms: | |
| platforms = ["linux", "macos", "windows", "pyodide"] | |
| # For each platform, what arch to use with cibuildwheel: | |
| platform_archs = { | |
| "linux": ["x86_64", "i686", "aarch64"], | |
| "macos": ["arm64", "x86_64"], | |
| "windows": ["x86", "AMD64", "ARM64"], | |
| "pyodide": ["wasm32"], | |
| } | |
| # Available Python versions: https://pypi.org/project/cibuildwheel/ | |
| # Note that cibuildwheel recommends not shipping wheels for pre-release versions | |
| # of Python: https://cibuildwheel.readthedocs.io/en/stable/options/#enable | |
| pys = ["cp39", "cp310", "cp311", "cp312", "cp313", "cp314"] | |
| # Some plaform/arch combinations are only suported on newer Python versions: | |
| platform_arch_pys = { | |
| ("windows", "ARM64"): ["cp311", "cp312", "cp313", "cp314"], | |
| ("pyodide", "wasm32"): ["cp312", "cp313"], | |
| } | |
| # Which OS to use for build (if different from platform name): | |
| platform_os = {"pyodide": "ubuntu", "linux": "ubuntu"} | |
| all_them = [] | |
| for the_platform in platforms: | |
| for the_arch in platform_archs[the_platform]: | |
| for the_py in platform_arch_pys.get((the_platform, the_arch), pys): | |
| the_os = platform_os.get(the_platform, the_platform) | |
| them = { | |
| "platform": the_platform, | |
| "os": the_os, | |
| "py": the_py, | |
| "arch": the_arch, | |
| } | |
| # For some OS/arch we need to specify OS version | |
| if the_os == "windows" and the_arch == "ARM64": | |
| them["os-version"] = "11-arm" | |
| if the_arch == "aarch64": | |
| # https://github.com/pypa/cibuildwheel/issues/2257 | |
| them["os-version"] = "22.04-arm" | |
| all_them.append(them) | |
| pprint.pprint(all_them) | |
| with open(os.environ["GITHUB_OUTPUT"], "a") as f: | |
| f.write(f"include={json.dumps(all_them)}\n") | |
| build_wheels: | |
| name: "${{ matrix.py }} ${{ matrix.platform }} ${{ matrix.arch }} wheels" | |
| needs: generate_wheels_matrix | |
| runs-on: "${{ matrix.os }}-${{ matrix.os-version || 'latest' }}" | |
| env: | |
| MATRIX_ID: "${{ matrix.py }}-${{ matrix.platform }}-${{ matrix.arch }}" | |
| strategy: | |
| matrix: | |
| include: ${{ fromJson(needs.generate_wheels_matrix.outputs.include) }} | |
| fail-fast: false | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Copy library content | |
| shell: bash | |
| run: | | |
| cp -r lib-rt/* . | |
| - uses: pypa/cibuildwheel@v3.2.0 | |
| with: | |
| config-file: pyproject.toml | |
| env: | |
| CIBW_BUILD: ${{ matrix.py }}*-* | |
| CIBW_ARCHS: ${{ matrix.arch }} | |
| CIBW_PLATFORM: ${{ matrix.platform }} | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist-${{ env.MATRIX_ID }} | |
| path: ./wheelhouse/*.whl | |
| overwrite: true | |
| build_sdist: | |
| name: Build source distribution | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - uses: actions/setup-python@v5 | |
| name: Install Python | |
| with: | |
| python-version: "3.9" | |
| - name: Build sdist | |
| run: | | |
| cp -r lib-rt/* . | |
| rm -rf lib-rt | |
| pip install --upgrade setuptools build | |
| python -m build --sdist | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist-sdist | |
| path: dist/*.tar.gz | |
| release: | |
| if: ${{ github.event_name == 'workflow_dispatch' }} | |
| needs: [build_wheels, build_sdist] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| steps: | |
| - name: Download artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: dist-* | |
| path: dist | |
| merge-multiple: true | |
| - name: Skip WASM wheels (not supported by PyPI yet) | |
| run: rm dist/*_wasm32.whl | |
| - name: Release to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| skip-existing: true |