|
| 1 | +--- |
| 2 | +name: Build cffi wheels (riscv64) |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + version: |
| 8 | + description: 'cffi version to build (git tag without leading v, e.g. 2.1.0)' |
| 9 | + required: true |
| 10 | + default: '2.1.0' |
| 11 | + pull_request: |
| 12 | + paths: |
| 13 | + - '.github/workflows/build-cffi.yml' |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: ${{ github.workflow }}-${{ inputs.version || '2.1.0' }}-${{ github.head_ref || github.run_id }} |
| 17 | + cancel-in-progress: true |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: read # to fetch code (actions/checkout) |
| 21 | + |
| 22 | +env: |
| 23 | + CFFI_VERSION: ${{ inputs.version || '2.1.0' }} |
| 24 | + UV_EXTRA_INDEX_URL: https://pypi.riseproject.dev/simple/ |
| 25 | + UV_INDEX_STRATEGY: unsafe-best-match |
| 26 | + UV_ONLY_BINARY: ':all:' |
| 27 | + MANYLINUX_RISCV64_IMAGE: quay.io/pypa/manylinux_2_39_riscv64 |
| 28 | + |
| 29 | +jobs: |
| 30 | + python_sdist: |
| 31 | + runs-on: ubuntu-24.04-riscv |
| 32 | + outputs: |
| 33 | + sdist_artifact_name: ${{ steps.build_sdist.outputs.sdist_artifact_name }} |
| 34 | + package_version: ${{ steps.build_sdist.outputs.package_version }} |
| 35 | + steps: |
| 36 | + - name: checkout cffi |
| 37 | + uses: actions/checkout@v7 |
| 38 | + with: |
| 39 | + repository: python-cffi/cffi |
| 40 | + ref: v${{ env.CFFI_VERSION }} |
| 41 | + submodules: true |
| 42 | + persist-credentials: false |
| 43 | + |
| 44 | + - name: setup uv |
| 45 | + uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0 |
| 46 | + with: |
| 47 | + python-version: '3.12' |
| 48 | + activate-environment: true |
| 49 | + enable-cache: false |
| 50 | + |
| 51 | + - name: build sdist |
| 52 | + id: build_sdist |
| 53 | + run: | |
| 54 | + rm -rf dist/ |
| 55 | + uv pip install build |
| 56 | + python -m build --sdist |
| 57 | +
|
| 58 | + echo "sdist_artifact_name=$(ls ./dist)" >> "$GITHUB_OUTPUT" |
| 59 | + echo "package_version=$(ls ./dist | sed -En 's/cffi-(.+)\.tar\.gz/\1/p')" >> "$GITHUB_OUTPUT" |
| 60 | +
|
| 61 | + - name: upload sdist artifact |
| 62 | + uses: actions/upload-artifact@v7 |
| 63 | + with: |
| 64 | + name: ${{ steps.build_sdist.outputs.sdist_artifact_name }} |
| 65 | + path: dist/${{ steps.build_sdist.outputs.sdist_artifact_name }} |
| 66 | + if-no-files-found: error |
| 67 | + # always upload the sdist artifact- all the wheel build jobs require it |
| 68 | + |
| 69 | + linux: |
| 70 | + # Unlike upstream, we depend only on python_sdist, since we don't need to |
| 71 | + # build a large matrix of targets |
| 72 | + needs: [python_sdist] |
| 73 | + name: Build cffi ${{ inputs.version || '2.1.0' }} ${{ matrix.python }}-manylinux_riscv64 |
| 74 | + runs-on: ubuntu-24.04-riscv |
| 75 | + strategy: |
| 76 | + fail-fast: false |
| 77 | + matrix: |
| 78 | + python: ["cp312", "cp313", "cp314", "cp314t"] |
| 79 | + |
| 80 | + steps: |
| 81 | + - name: fetch sdist artifact |
| 82 | + id: fetch_sdist |
| 83 | + uses: actions/download-artifact@v8 |
| 84 | + with: |
| 85 | + name: ${{ needs.python_sdist.outputs.sdist_artifact_name }} |
| 86 | + |
| 87 | + - name: setup uv |
| 88 | + uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0 |
| 89 | + with: |
| 90 | + python-version: '3.12' |
| 91 | + activate-environment: true |
| 92 | + enable-cache: false |
| 93 | + |
| 94 | + - name: build/test wheels |
| 95 | + id: build |
| 96 | + env: |
| 97 | + CFLAGS: -Dffi_call=cffistatic_ffi_call # override name for ffi_call to break hard if we linked against someone else's libffi |
| 98 | + CIBW_BUILD: ${{ matrix.python }}-manylinux_riscv64 |
| 99 | + CIBW_ENVIRONMENT_PASS_LINUX: CFLAGS # ensure that the build container can see our overridden build config |
| 100 | + CIBW_MANYLINUX_RISCV64_IMAGE: ${{ env.MANYLINUX_RISCV64_IMAGE }} |
| 101 | + CIBW_BEFORE_BUILD: | |
| 102 | + set -eux && \ |
| 103 | + curl -L -O https://github.com/libffi/libffi/archive/v3.4.6.tar.gz && \ |
| 104 | + tar zxf v3.4.6.tar.gz && cd libffi-3.4.6 && \ |
| 105 | + ((command -v apk && apk add libtool) || true) && \ |
| 106 | + ./autogen.sh && \ |
| 107 | + ./configure --without-gcc-arch --disable-docs --with-pic --enable-shared=no && \ |
| 108 | + make install && \ |
| 109 | + cd .. && \ |
| 110 | + rm -rf libffi-3.4.6 |
| 111 | + CIBW_TEST_REQUIRES: pytest setuptools meson-python ninja # 3.12+ no longer includes distutils, just always ensure setuptools is present |
| 112 | + CIBW_TEST_COMMAND: PYTHONUNBUFFERED=1 python -m pytest {project} |
| 113 | + run: | |
| 114 | + set -eux |
| 115 | +
|
| 116 | + mkdir cffi |
| 117 | +
|
| 118 | + tar zxf ${{ steps.fetch_sdist.outputs.download-path }}/cffi*.tar.gz --strip-components=1 -C cffi |
| 119 | + uv pip install --upgrade cibuildwheel |
| 120 | +
|
| 121 | + # actually build libffi + wheel (using env tweaks above) |
| 122 | + python -m cibuildwheel --output-dir dist ./cffi |
| 123 | +
|
| 124 | + echo "artifact_name=$(ls ./dist/)" >> "$GITHUB_OUTPUT" |
| 125 | +
|
| 126 | + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 127 | + with: |
| 128 | + name: cffi-${{ env.CFFI_VERSION }}-${{ matrix.python }}-manylinux_riscv64 |
| 129 | + path: ./dist/*.whl |
| 130 | + if-no-files-found: error |
| 131 | + |
| 132 | + publish: |
| 133 | + name: Publish cffi ${{ inputs.version || '2.1.0' }} to GitLab |
| 134 | + needs: [linux] |
| 135 | + # Only publish when the workflow was triggered from main with a specific |
| 136 | + # version. Manual trigger is the only entry point, so checking the ref is |
| 137 | + # enough to gate uploads. |
| 138 | + if: github.ref == 'refs/heads/main' |
| 139 | + runs-on: ubuntu-latest |
| 140 | + permissions: |
| 141 | + contents: write |
| 142 | + pull-requests: write |
| 143 | + |
| 144 | + steps: |
| 145 | + - name: Publish wheels and open docs PR |
| 146 | + uses: riseproject-dev/python-wheels/actions/publish-wheels@main |
| 147 | + with: |
| 148 | + artifact-pattern: cffi-${{ env.CFFI_VERSION }}-*-manylinux_riscv64 |
| 149 | + gitlab-username: ${{ vars.GITLAB_DEPLOY_USER }} |
| 150 | + gitlab-token: ${{ secrets.GITLAB_DEPLOY_TOKEN }} |
| 151 | + gitlab-project-id: ${{ vars.GITLAB_PROJECT_ID }} |
| 152 | + gh-token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments