From 3ad70e2861101715028ffd7f6f0b06298eb0293c Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Mon, 24 Aug 2026 18:20:02 +0200 Subject: [PATCH 1/5] cython: add build-cython.yml for riscv64 wheels Cython ships per-interpreter compiled wheels (cp39-cp315) plus a py3-none-any fallback on PyPI, but none for riscv64 -- which every source build of a Cython-using package on riscv64 needs (protobuf, fonttools, grpcio-tools, etc. all compile Cython from sdist today). Cython is self-hosting: setup.py compiles its own modules with the in-tree Cython, so the build-from-checkout shape needs no external build tool. Matrix is per-interpreter [cp312, cp313, cp314] with no cp314t -- setup.py disables self-compilation under Py_GIL_DISABLED, so a free-threaded build would silently ship the pure-Python fallback. The wheel test asserts a core module loaded from a compiled .so (a self-compile failure degrades to the pure-Python fallback silently) and then cythonizes+compiles+imports a module to prove the wheel works as a compiler end-to-end. Co-Authored-By: Claude Opus 4.8 --- .github/workflows/build-cython.yml | 117 +++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 .github/workflows/build-cython.yml diff --git a/.github/workflows/build-cython.yml b/.github/workflows/build-cython.yml new file mode 100644 index 00000000..5f326a00 --- /dev/null +++ b/.github/workflows/build-cython.yml @@ -0,0 +1,117 @@ +# SPDX-FileCopyrightText: 2026 The RISE Project +# SPDX-License-Identifier: MIT +--- +# This workflow is based on the `build_wheels` job in: +# https://github.com/cython/cython/blob/3.3.0/.github/workflows/wheels.yml +# +# Cython is self-hosting: setup.py compiles Cython's own modules with the +# in-tree Cython, so no external build tool is needed. Upstream ships +# per-interpreter compiled wheels (cp39-cp315) plus a py3-none-any fallback, +# but no riscv64 -- which every source build of a Cython-using package needs. +name: Build cython wheels (riscv64) + +on: + workflow_dispatch: + inputs: + version: + description: 'cython version to build (git tag, e.g. 3.3.0)' + required: true + default: '3.3.0' + pull_request: + paths: + - '.github/workflows/build-cython.yml' + +concurrency: + group: ${{ github.workflow }}-${{ inputs.version || '3.3.0' }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +permissions: + contents: read # to fetch code (actions/checkout) + +env: + # `inputs.version` is empty on pull_request events; default there. + CYTHON_VERSION: ${{ inputs.version || '3.3.0' }} + MANYLINUX_RISCV64_IMAGE: quay.io/pypa/manylinux_2_39_riscv64 + +jobs: + build_wheels: + name: Build cython ${{ inputs.version || '3.3.0' }} ${{ matrix.python }}-manylinux_riscv64 + runs-on: ubuntu-24.04-riscv + timeout-minutes: 90 + strategy: + fail-fast: false + matrix: + # Per-interpreter (not abi3), matching upstream's primary-platform wheels. + # No cp314t: setup.py disables self-compilation under Py_GIL_DISABLED (a + # compiled Cython would force the GIL back on), so a free-threaded build + # would silently ship the pure-Python fallback. + python: ["cp312", "cp313", "cp314"] + + steps: + - name: Checkout cython ${{ env.CYTHON_VERSION }} + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + repository: cython/cython + ref: ${{ env.CYTHON_VERSION }} + persist-credentials: false + + # Staged into the checkout root so cibuildwheel copies it under {package}. + # Upstream's wheel workflow only runs twine/abi3audit, not the (huge) test + # suite; this asserts the self-compiled .so shipped (a silent failure ships + # the pure-Python fallback) and that the wheel works as a compiler. + - name: Stage wheel test + run: | + cat > testwheel.py <<'EOF' + import sys, tempfile, subprocess, os + import Cython + from Cython.Compiler import Scanning + assert Scanning.__file__.endswith(".so"), \ + "expected compiled .so, got %r (pure-Python fallback)" % Scanning.__file__ + print("Cython", Cython.__version__, "compiled:", Scanning.__file__) + + with tempfile.TemporaryDirectory() as d: + with open(os.path.join(d, "greet.pyx"), "w") as f: + f.write("def hi():\n cdef int n = 41\n return n + 1\n") + subprocess.run([sys.executable, "-m", "Cython.Build.Cythonize", + "-i", "greet.pyx"], cwd=d, check=True) + subprocess.run([sys.executable, "-c", + "import greet; assert greet.hi() == 42"], + cwd=d, check=True) + print("cythonize + compile + import OK") + EOF + + - name: Build wheels + uses: pypa/cibuildwheel@1828c10ab37f080699c7b81cea34097c684a7074 # v4.2.0 + with: + output-dir: wheelhouse/ + only: ${{ matrix.python }}-manylinux_riscv64 + env: + CIBW_MANYLINUX_RISCV64_IMAGE: ${{ env.MANYLINUX_RISCV64_IMAGE }} + # cythonize -i needs a build backend; the manylinux base interpreter + # ships neither setuptools nor distutils (dropped in 3.12). + CIBW_TEST_REQUIRES: setuptools + CIBW_TEST_COMMAND: python {package}/testwheel.py + + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: cython-${{ env.CYTHON_VERSION }}-${{ matrix.python }}-manylinux_riscv64 + path: wheelhouse/*.whl + if-no-files-found: error + + publish: + name: Publish cython ${{ inputs.version || '3.3.0' }} to GitLab + needs: [build_wheels] + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - name: Publish wheels and open docs PR + uses: riseproject-dev/python-wheels/actions/publish-wheels@main + with: + artifact-pattern: cython-${{ env.CYTHON_VERSION }}-*-manylinux_riscv64 + gitlab-username: ${{ vars.GITLAB_DEPLOY_USER }} + gitlab-token: ${{ secrets.GITLAB_DEPLOY_TOKEN }} + gitlab-project-id: ${{ vars.GITLAB_PROJECT_ID }} + gh-token: ${{ secrets.GITHUB_TOKEN }} From 267745025aa24b107b9d55a8ee384b14d6c6aa80 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Mon, 24 Aug 2026 19:46:33 +0200 Subject: [PATCH 2/5] cython: fix riscv64 build via pyproject patch, run real test suite The CI build failed because upstream's pyproject.toml [tool.cibuildwheel] config sets x86 CFLAGS (-march=core2 -mno-ssse3) with per-arch overrides for aarch64/armv7l but none for riscv64, so the riscv64 build inherited the x86 flags and gcc rejected them ("ISA string must begin with rv"). Add patches/cython/3.3.0/ with a riscv64 [tool.cibuildwheel] override (applied matplotlib/pillow-style via a second checkout + git apply), using the RVA-baseline flags used for riscv64gc builds. Also add patches/cython/** to the PR paths trigger. Replace the placeholder smoke test with upstream's own suite (Tools/ci-run.sh): runtests.py over the bundled tests/, C and C++ backends. runtests.py + tests/ are copied into cibuildwheel's temp test cwd (not the source Cython/) so the suite exercises the installed wheel, not the checkout's pure-Python source. Validated end-to-end under QEMU: cp312 wheel builds with 19 compiled .so, and a runtests.py shard passes 186 tests against it. Co-Authored-By: Claude Opus 4.8 --- .github/workflows/build-cython.yml | 58 ++++++++----------- ...64-cibuildwheel-environment-override.patch | 43 ++++++++++++++ 2 files changed, 66 insertions(+), 35 deletions(-) create mode 100644 patches/cython/3.3.0/0001-Add-riscv64-cibuildwheel-environment-override.patch diff --git a/.github/workflows/build-cython.yml b/.github/workflows/build-cython.yml index 5f326a00..8a445054 100644 --- a/.github/workflows/build-cython.yml +++ b/.github/workflows/build-cython.yml @@ -4,10 +4,9 @@ # This workflow is based on the `build_wheels` job in: # https://github.com/cython/cython/blob/3.3.0/.github/workflows/wheels.yml # -# Cython is self-hosting: setup.py compiles Cython's own modules with the -# in-tree Cython, so no external build tool is needed. Upstream ships -# per-interpreter compiled wheels (cp39-cp315) plus a py3-none-any fallback, -# but no riscv64 -- which every source build of a Cython-using package needs. +# Cython is self-hosting (setup.py compiles its own modules with the in-tree +# Cython), so no external build tool is needed. It ships per-interpreter +# compiled wheels + a py3-none-any fallback on PyPI, but no riscv64. name: Build cython wheels (riscv64) on: @@ -20,6 +19,7 @@ on: pull_request: paths: - '.github/workflows/build-cython.yml' + - 'patches/cython/**' concurrency: group: ${{ github.workflow }}-${{ inputs.version || '3.3.0' }}-${{ github.head_ref || github.run_id }} @@ -37,14 +37,12 @@ jobs: build_wheels: name: Build cython ${{ inputs.version || '3.3.0' }} ${{ matrix.python }}-manylinux_riscv64 runs-on: ubuntu-24.04-riscv - timeout-minutes: 90 + timeout-minutes: 600 strategy: fail-fast: false matrix: - # Per-interpreter (not abi3), matching upstream's primary-platform wheels. - # No cp314t: setup.py disables self-compilation under Py_GIL_DISABLED (a - # compiled Cython would force the GIL back on), so a free-threaded build - # would silently ship the pure-Python fallback. + # No cp314t: setup.py disables self-compilation under Py_GIL_DISABLED, so + # a free-threaded build would silently ship the pure-Python fallback. python: ["cp312", "cp313", "cp314"] steps: @@ -55,30 +53,16 @@ jobs: ref: ${{ env.CYTHON_VERSION }} persist-credentials: false - # Staged into the checkout root so cibuildwheel copies it under {package}. - # Upstream's wheel workflow only runs twine/abi3audit, not the (huge) test - # suite; this asserts the self-compiled .so shipped (a silent failure ships - # the pure-Python fallback) and that the wheel works as a compiler. - - name: Stage wheel test - run: | - cat > testwheel.py <<'EOF' - import sys, tempfile, subprocess, os - import Cython - from Cython.Compiler import Scanning - assert Scanning.__file__.endswith(".so"), \ - "expected compiled .so, got %r (pure-Python fallback)" % Scanning.__file__ - print("Cython", Cython.__version__, "compiled:", Scanning.__file__) + - name: Checkout python-wheels + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + path: python-wheels + persist-credentials: false - with tempfile.TemporaryDirectory() as d: - with open(os.path.join(d, "greet.pyx"), "w") as f: - f.write("def hi():\n cdef int n = 41\n return n + 1\n") - subprocess.run([sys.executable, "-m", "Cython.Build.Cythonize", - "-i", "greet.pyx"], cwd=d, check=True) - subprocess.run([sys.executable, "-c", - "import greet; assert greet.hi() == 42"], - cwd=d, check=True) - print("cythonize + compile + import OK") - EOF + # Adds a riscv64 [tool.cibuildwheel] override; without it the build inherits + # upstream's x86 CFLAGS (-march=core2) and the C compile fails. + - name: Patch cython source + run: git apply python-wheels/patches/cython/${{ env.CYTHON_VERSION }}/*.patch - name: Build wheels uses: pypa/cibuildwheel@1828c10ab37f080699c7b81cea34097c684a7074 # v4.2.0 @@ -87,10 +71,14 @@ jobs: only: ${{ matrix.python }}-manylinux_riscv64 env: CIBW_MANYLINUX_RISCV64_IMAGE: ${{ env.MANYLINUX_RISCV64_IMAGE }} - # cythonize -i needs a build backend; the manylinux base interpreter - # ships neither setuptools nor distutils (dropped in 3.12). + # Upstream's own suite (Tools/ci-run.sh), C and C++ backends. Copy in only + # runtests.py + tests/ (not the source Cython/) so it imports the installed + # wheel, not the checkout's pure-Python source (gotcha 21). CIBW_TEST_REQUIRES: setuptools - CIBW_TEST_COMMAND: python {package}/testwheel.py + CIBW_TEST_COMMAND: >- + cp -r {package}/runtests.py {package}/tests . && + python runtests.py -vv --no-code-style --no-cleanup + -x Debugger --backends=c,cpp -j$(nproc) --work-dir=TEST_TMP - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: diff --git a/patches/cython/3.3.0/0001-Add-riscv64-cibuildwheel-environment-override.patch b/patches/cython/3.3.0/0001-Add-riscv64-cibuildwheel-environment-override.patch new file mode 100644 index 00000000..bcd36e4a --- /dev/null +++ b/patches/cython/3.3.0/0001-Add-riscv64-cibuildwheel-environment-override.patch @@ -0,0 +1,43 @@ +From 353d241c339f14e9bddf81d64a485859e57964b1 Mon Sep 17 00:00:00 2001 +From: RISE Project +Date: Mon, 24 Aug 2026 19:21:28 +0200 +Subject: [PATCH] Add riscv64 cibuildwheel environment override + +The [tool.cibuildwheel.linux.environment] default sets x86-specific +CFLAGS (-march=core2 -mno-ssse3), and the per-arch overrides cover +aarch64 and armv7l but not riscv64. Building manylinux_riscv64 wheels +therefore inherits the x86 default and fails at the C compile: + + gcc: error: '-march=core2': ISA string must begin with rv32 or rv64 + gcc: error: unrecognized command-line option '-mno-ssse3' + +Add a riscv64 override mirroring the aarch64 one, using the RVA-baseline +flags used to build riscv64gc packages (matches the Yocto qemuriscv64 +toolchain: rv64imafdc + lp64d ABI). + +Upstream-Status: To upstream [riscv64 has no cibuildwheel override; x86 CFLAGS leak in] + +Signed-off-by: RISE Project +--- + pyproject.toml | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/pyproject.toml b/pyproject.toml +index a26fa99..e570611 100644 +--- a/pyproject.toml ++++ b/pyproject.toml +@@ -41,6 +41,11 @@ select = "*aarch64" + inherit.environment = "append" + environment = {CFLAGS = "-O3 -g0 -pipe -fPIC -DNDEBUG -march=armv8-a -mtune=cortex-a72", AR = "gcc-ar", NM = "gcc-nm", RANLIB = "gcc-ranlib"} + ++[[tool.cibuildwheel.overrides]] ++select = "*riscv64" ++inherit.environment = "append" ++environment = {CFLAGS = "-O3 -g0 -pipe -fPIC -DNDEBUG -march=rv64imafdc_zicsr_zifencei -mabi=lp64d -fstack-protector-strong", AR = "gcc-ar", NM = "gcc-nm", RANLIB = "gcc-ranlib"} ++ + [[tool.cibuildwheel.overrides]] + select = "*armv7l" + inherit.environment = "append" +-- +2.43.0 + From 37eb9f076cf22d1402d5622c6473f54a71a855b8 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Wed, 26 Aug 2026 12:45:40 +0200 Subject: [PATCH 3/5] cython: trim workflow comments to one-line whys --- .github/workflows/build-cython.yml | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-cython.yml b/.github/workflows/build-cython.yml index 8a445054..b8c77ec4 100644 --- a/.github/workflows/build-cython.yml +++ b/.github/workflows/build-cython.yml @@ -3,10 +3,6 @@ --- # This workflow is based on the `build_wheels` job in: # https://github.com/cython/cython/blob/3.3.0/.github/workflows/wheels.yml -# -# Cython is self-hosting (setup.py compiles its own modules with the in-tree -# Cython), so no external build tool is needed. It ships per-interpreter -# compiled wheels + a py3-none-any fallback on PyPI, but no riscv64. name: Build cython wheels (riscv64) on: @@ -41,8 +37,7 @@ jobs: strategy: fail-fast: false matrix: - # No cp314t: setup.py disables self-compilation under Py_GIL_DISABLED, so - # a free-threaded build would silently ship the pure-Python fallback. + # No cp314t: setup.py disables self-compilation under Py_GIL_DISABLED. python: ["cp312", "cp313", "cp314"] steps: @@ -59,8 +54,7 @@ jobs: path: python-wheels persist-credentials: false - # Adds a riscv64 [tool.cibuildwheel] override; without it the build inherits - # upstream's x86 CFLAGS (-march=core2) and the C compile fails. + # Without a riscv64 override the build inherits upstream's x86 `-march=core2` CFLAGS. - name: Patch cython source run: git apply python-wheels/patches/cython/${{ env.CYTHON_VERSION }}/*.patch @@ -71,9 +65,7 @@ jobs: only: ${{ matrix.python }}-manylinux_riscv64 env: CIBW_MANYLINUX_RISCV64_IMAGE: ${{ env.MANYLINUX_RISCV64_IMAGE }} - # Upstream's own suite (Tools/ci-run.sh), C and C++ backends. Copy in only - # runtests.py + tests/ (not the source Cython/) so it imports the installed - # wheel, not the checkout's pure-Python source (gotcha 21). + # Stage only runtests.py + tests/ so the installed wheel is imported, not the source tree. CIBW_TEST_REQUIRES: setuptools CIBW_TEST_COMMAND: >- cp -r {package}/runtests.py {package}/tests . && From 5907e7afaaa8c313754c02b1b1386cfeaea73efb Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Thu, 27 Aug 2026 02:11:26 +0200 Subject: [PATCH 4/5] cython: stage the checkout paths the test suite reaches into EmbedTest chdirs to Demos/embed and the end-to-end srctrees compile fixtures from docs/ and invoke the root cython.py / cythonize.py, none of which were staged, so all three interpreters failed in runtests.py after building cleanly. Cython/ stays unstaged, so cython.py still resolves the compiler from the installed wheel. --- .github/workflows/build-cython.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-cython.yml b/.github/workflows/build-cython.yml index b8c77ec4..0aac973f 100644 --- a/.github/workflows/build-cython.yml +++ b/.github/workflows/build-cython.yml @@ -65,10 +65,12 @@ jobs: only: ${{ matrix.python }}-manylinux_riscv64 env: CIBW_MANYLINUX_RISCV64_IMAGE: ${{ env.MANYLINUX_RISCV64_IMAGE }} - # Stage only runtests.py + tests/ so the installed wheel is imported, not the source tree. + # EmbedTest needs Demos/embed and the end-to-end srctrees reach into docs/ and run the + # root cython.py; Cython/ stays unstaged so those still import the installed wheel. CIBW_TEST_REQUIRES: setuptools CIBW_TEST_COMMAND: >- - cp -r {package}/runtests.py {package}/tests . && + cp -r {package}/runtests.py {package}/tests {package}/Demos {package}/docs + {package}/cython.py {package}/cythonize.py . && python runtests.py -vv --no-code-style --no-cleanup -x Debugger --backends=c,cpp -j$(nproc) --work-dir=TEST_TMP From 32d73bacc88ce50bbb0d74ddddd064c0ddec9c4c Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Thu, 27 Aug 2026 11:24:50 +0200 Subject: [PATCH 5/5] cython: exclude the two embedding tests EmbedTest and the embed_modules end-to-end case both link -lpython3.X, and the manylinux CPython is static-only with no shared libpython, so ld fails with "cannot find -lpython3.12". Not riscv64-specific: upstream runs these on runners that have a shared libpython. runtests.py gates EmbedTest on an exclude selector matching "embedded" (runtests.py:814); the srctree case matches its module name. --- .github/workflows/build-cython.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-cython.yml b/.github/workflows/build-cython.yml index 0aac973f..f6453649 100644 --- a/.github/workflows/build-cython.yml +++ b/.github/workflows/build-cython.yml @@ -65,14 +65,16 @@ jobs: only: ${{ matrix.python }}-manylinux_riscv64 env: CIBW_MANYLINUX_RISCV64_IMAGE: ${{ env.MANYLINUX_RISCV64_IMAGE }} - # EmbedTest needs Demos/embed and the end-to-end srctrees reach into docs/ and run the - # root cython.py; Cython/ stays unstaged so those still import the installed wheel. + # The srctrees reach into docs/ and run the root cython.py; Cython/ stays unstaged so + # those still import the installed wheel. The two embedding tests are excluded: they + # link -lpython3.X, and manylinux CPython is static-only with no shared libpython. CIBW_TEST_REQUIRES: setuptools CIBW_TEST_COMMAND: >- cp -r {package}/runtests.py {package}/tests {package}/Demos {package}/docs {package}/cython.py {package}/cythonize.py . && python runtests.py -vv --no-code-style --no-cleanup - -x Debugger --backends=c,cpp -j$(nproc) --work-dir=TEST_TMP + -x Debugger -x embedded -x embed_modules + --backends=c,cpp -j$(nproc) --work-dir=TEST_TMP - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: