Skip to content

Commit 4667340

Browse files
committed
build-cffi.yml: add
Follow the development guide's best practices to create a cffi workflow, with changes to use uv and simplify the build matrix. A new build of cffi for version v2.1.0 is ultimately needed to get the matplotlib workflow to succeed without building cffi from source, so add it first. Ref: #64 Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
1 parent 26c360c commit 4667340

1 file changed

Lines changed: 145 additions & 0 deletions

File tree

.github/workflows/build-cffi.yml

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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: install python
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: build/test wheels
88+
id: build
89+
env:
90+
CFLAGS: -Dffi_call=cffistatic_ffi_call # override name for ffi_call to break hard if we linked against someone else's libffi
91+
CIBW_BUILD: ${{ matrix.python }}-manylinux_riscv64
92+
CIBW_ENVIRONMENT_PASS_LINUX: CFLAGS # ensure that the build container can see our overridden build config
93+
CIBW_MANYLINUX_RISCV64_IMAGE: ${{ env.MANYLINUX_RISCV64_IMAGE }}
94+
CIBW_BEFORE_BUILD: |
95+
set -eux && \
96+
curl -L -O https://github.com/libffi/libffi/archive/v3.4.6.tar.gz && \
97+
tar zxf v3.4.6.tar.gz && cd libffi-3.4.6 && \
98+
((command -v apk && apk add libtool) || true) && \
99+
./autogen.sh && \
100+
./configure --without-gcc-arch --disable-docs --with-pic --enable-shared=no && \
101+
make install && \
102+
cd .. && \
103+
rm -rf libffi-3.4.6
104+
CIBW_TEST_REQUIRES: pytest setuptools meson-python ninja # 3.12+ no longer includes distutils, just always ensure setuptools is present
105+
CIBW_TEST_COMMAND: PYTHONUNBUFFERED=1 python -m pytest {project}
106+
run: |
107+
set -eux
108+
109+
mkdir cffi
110+
111+
tar zxf ${{ steps.fetch_sdist.outputs.download-path }}/cffi*.tar.gz --strip-components=1 -C cffi
112+
uv pip install --upgrade cibuildwheel
113+
114+
# actually build libffi + wheel (using env tweaks above)
115+
python -m cibuildwheel --output-dir dist ./cffi
116+
117+
echo "artifact_name=$(ls ./dist/)" >> "$GITHUB_OUTPUT"
118+
119+
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
120+
with:
121+
name: cffi-${{ env.CFFI_VERSION }}-${{ matrix.python }}-manylinux_riscv64
122+
path: ./wheelhouse/*.whl
123+
if-no-files-found: error
124+
125+
publish:
126+
name: Publish cffi ${{ inputs.version || '2.1.0' }} to GitLab
127+
needs: [linux]
128+
# Only publish when the workflow was triggered from main with a specific
129+
# version. Manual trigger is the only entry point, so checking the ref is
130+
# enough to gate uploads.
131+
if: github.ref == 'refs/heads/main'
132+
runs-on: ubuntu-latest
133+
permissions:
134+
contents: write
135+
pull-requests: write
136+
137+
steps:
138+
- name: Publish wheels and open docs PR
139+
uses: riseproject-dev/python-wheels/actions/publish-wheels@main
140+
with:
141+
artifact-pattern: cffi-${{ env.CFFI_VERSION }}-*-manylinux_riscv64
142+
gitlab-username: ${{ vars.GITLAB_DEPLOY_USER }}
143+
gitlab-token: ${{ secrets.GITLAB_DEPLOY_TOKEN }}
144+
gitlab-project-id: ${{ vars.GITLAB_PROJECT_ID }}
145+
gh-token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)