|
| 1 | +name: Example – cibuildwheel + conan-py-build |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: read |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_dispatch: |
| 8 | + push: |
| 9 | + branches: [main] |
| 10 | + pull_request: |
| 11 | + branches: [main] |
| 12 | + |
| 13 | +jobs: |
| 14 | + # Build conan-py-build wheel and upload as artifact for build-wheels jobs. |
| 15 | + backend-wheel: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + persist-credentials: false |
| 21 | + - uses: actions/setup-python@v5 |
| 22 | + with: |
| 23 | + python-version: "3.12" |
| 24 | + - run: pip install build && python -m build --wheel --outdir backend-dist . |
| 25 | + - uses: actions/upload-artifact@v4 |
| 26 | + with: |
| 27 | + name: conan-py-build-wheel |
| 28 | + path: backend-dist/*.whl |
| 29 | + |
| 30 | + build-wheels: |
| 31 | + needs: backend-wheel |
| 32 | + name: Build wheels on ${{ matrix.os }} |
| 33 | + runs-on: ${{ matrix.os }} |
| 34 | + strategy: |
| 35 | + fail-fast: false |
| 36 | + matrix: |
| 37 | + include: |
| 38 | + - os: ubuntu-latest |
| 39 | + arch: x86_64 |
| 40 | + profile: linux-x86_64 |
| 41 | + - os: ubuntu-24.04-arm |
| 42 | + arch: aarch64 |
| 43 | + profile: linux-aarch64 |
| 44 | + - os: macos-14 |
| 45 | + arch: arm64 |
| 46 | + profile: macos-arm64 |
| 47 | + - os: macos-14 |
| 48 | + arch: x86_64 |
| 49 | + profile: macos-x86_64.jinja |
| 50 | + - os: windows-latest |
| 51 | + arch: AMD64 |
| 52 | + profile: windows-x86_64 |
| 53 | + |
| 54 | + env: |
| 55 | + CIBW_ARCHS_LINUX: ${{ matrix.arch }} |
| 56 | + CIBW_ARCHS_MACOS: ${{ matrix.arch }} |
| 57 | + CIBW_ARCHS_WINDOWS: ${{ matrix.arch }} |
| 58 | + CIBW_CONFIG_SETTINGS: "host-profile=./profiles/${{ matrix.profile }}" |
| 59 | + CIBW_BEFORE_BUILD: "pip install backend-dist/*.whl" |
| 60 | + CIBW_BUILD_VERBOSITY: 3 |
| 61 | + steps: |
| 62 | + - uses: actions/checkout@v4 |
| 63 | + with: |
| 64 | + persist-credentials: false |
| 65 | + |
| 66 | + - uses: actions/download-artifact@v4 |
| 67 | + with: |
| 68 | + name: conan-py-build-wheel |
| 69 | + |
| 70 | + # CIBW_BEFORE_BUILD installs the backend from backend-dist/*.whl |
| 71 | + - name: Place backend wheel inside example project |
| 72 | + shell: bash |
| 73 | + run: | |
| 74 | + mkdir -p examples/cibw-example/backend-dist |
| 75 | + mv *.whl examples/cibw-example/backend-dist/ |
| 76 | + ls -la examples/cibw-example/backend-dist/ |
| 77 | +
|
| 78 | + # On Linux, cibuildwheel runs in Docker and only gets files from the repo copy |
| 79 | + # (e.g. git archive), so backend-dist is not there. Mount it so before_build can pip install. |
| 80 | + - name: Set container engine to mount backend-dist (Linux only) |
| 81 | + if: runner.os == 'Linux' |
| 82 | + shell: bash |
| 83 | + run: | |
| 84 | + echo "CIBW_CONTAINER_ENGINE=docker; create_args: -v ${{ github.workspace }}/examples/cibw-example/backend-dist:/project/backend-dist" >> $GITHUB_ENV |
| 85 | +
|
| 86 | + # Export cpython-portable to Conan cache so it's available for the build. |
| 87 | + - name: Export cpython-portable |
| 88 | + shell: bash |
| 89 | + run: | |
| 90 | + pip install conan |
| 91 | + conan profile detect --force |
| 92 | + for ver in 3.9.20 3.10.19 3.11.14 3.12.12 3.13.11; do |
| 93 | + conan export recipes/cpython --version=$ver |
| 94 | + done |
| 95 | +
|
| 96 | + - name: Set CIBW_BEFORE_BUILD to absolute path (macOS and Windows) |
| 97 | + if: runner.os != 'Linux' |
| 98 | + shell: bash |
| 99 | + run: | |
| 100 | + whl=$(ls "${{ github.workspace }}/examples/cibw-example/backend-dist/"*.whl 2>/dev/null | head -1) |
| 101 | + echo "CIBW_BEFORE_BUILD=pip install $whl" >> $GITHUB_ENV |
| 102 | +
|
| 103 | + - name: Build wheels |
| 104 | + uses: pypa/cibuildwheel@v3.4.0 |
| 105 | + with: |
| 106 | + package-dir: examples/cibw-example |
| 107 | + output-dir: wheelhouse |
| 108 | + |
| 109 | + - uses: actions/upload-artifact@v4 |
| 110 | + with: |
| 111 | + name: cibw-wheels-${{ matrix.os }}-${{ matrix.arch }} |
| 112 | + path: wheelhouse/*.whl |
0 commit comments