Skip to content

Commit 449e258

Browse files
committed
numpy: add riscv64 workflow
Upstream numpy has started building riscv64 wheels, but they are not yet deploying them. In the meantime, we still need to support builds and publish them to the RISE registry. Use the custom publish-to-gitlab action in the publish step, since the registry is on GitLab. Unlike upstream, we build for Python 3.12, 3.13, 3.14, and 3.14t (3.11 is no longer supported as of NumPy 2.5.0). This is consistent with how RISE has been building for a broader range of versions. This workflow keeps the general structure of the upstream project, but also checks out the python-wheels repository at 'python-wheels-repo' so that we can use publish-to-gitlab when deploying. Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
1 parent 36c57ff commit 449e258

1 file changed

Lines changed: 135 additions & 0 deletions

File tree

.github/workflows/build-numpy.yml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
---
2+
name: Build numpy wheels (riscv64)
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
version:
8+
description: 'numpy version to build (git tag without leading v, e.g. 2.5.0)'
9+
required: true
10+
default: '2.5.0'
11+
pull_request:
12+
paths:
13+
- '.github/workflows/build-numpy.yml'
14+
- 'actions/publish-to-gitlab/**'
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ inputs.version || '2.5.0' }}-${{ github.head_ref || github.run_id }}
18+
cancel-in-progress: true
19+
20+
permissions:
21+
contents: read # to fetch code (actions/checkout)
22+
23+
env:
24+
# `inputs.version` is empty on pull_request events; default to 2.5.0 there.
25+
NUMPY_VERSION: ${{ inputs.version || '2.5.0' }}
26+
27+
jobs:
28+
build_wheels:
29+
name: Build numpy ${{ inputs.version || '2.5.0' }} ${{ matrix.python }}-manylinux_riscv64
30+
runs-on: ubuntu-24.04-riscv
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
python: ["cp312", "cp313", "cp314", "cp314t"]
35+
36+
env:
37+
CCACHE_DIR: ${{ github.workspace }}/.ccache
38+
CCACHE_BASEDIR: "/project"
39+
CCACHE_COMPILERCHECK: "content"
40+
41+
steps:
42+
# Layout note: numpy is checked out at the workspace root (not under a
43+
# subdir) so cibuildwheel's `{project}` template substitution resolves
44+
# to the numpy source tree. numpy's pyproject.toml uses
45+
# `{project}/tools/wheels/cibw_before_build.sh`, which only works when
46+
# CWD == numpy root at cibuildwheel invocation time. python-wheels is
47+
# placed under `python-wheels-repo/` to free the workspace root for numpy.
48+
- name: Checkout python-wheels
49+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
50+
with:
51+
path: python-wheels-repo
52+
persist-credentials: false
53+
54+
- name: Checkout numpy v${{ env.NUMPY_VERSION }}
55+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
56+
with:
57+
repository: numpy/numpy
58+
ref: v${{ env.NUMPY_VERSION }}
59+
submodules: true
60+
persist-credentials: false
61+
62+
- name: Restore compilation cache
63+
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
64+
id: ccache-restore
65+
with:
66+
path: ${{ env.CCACHE_DIR }}
67+
key: ccache-wheels-numpy-v${{ env.NUMPY_VERSION }}-manylinux_riscv64-${{ matrix.python }}-${{ github.run_id }}
68+
restore-keys: |
69+
ccache-wheels-numpy-v${{ env.NUMPY_VERSION }}-manylinux_riscv64-${{ matrix.python }}-
70+
ccache-wheels-numpy-manylinux_riscv64-${{ matrix.python }}-
71+
72+
- name: Build wheels
73+
uses: pypa/cibuildwheel@294735312765b09d24a2fbec22660ce817587d55 # v4.1.0
74+
env:
75+
CIBW_BUILD: ${{ matrix.python }}-manylinux_riscv64
76+
CIBW_BEFORE_ALL_LINUX: |
77+
set -eux
78+
CCACHE_VERSION=4.13.6
79+
curl -fsSL https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}-linux-$(uname -m)-musl-static.tar.gz | \
80+
tar -xvzf - --strip-components 1 -C /usr/local/bin ccache-${CCACHE_VERSION}-linux-$(uname -m)-musl-static/ccache
81+
ccache --version
82+
ccache --zero-stats
83+
CIBW_ENVIRONMENT_PASS_LINUX: >-
84+
CCACHE_BASEDIR
85+
CCACHE_COMPILERCHECK
86+
CIBW_CONTAINER_ENGINE: "docker; create_args: --volume ${{ env.CCACHE_DIR }}:/root/.ccache"
87+
88+
- name: Save compilation cache
89+
if: always() && github.ref == 'refs/heads/main'
90+
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
91+
with:
92+
path: ${{ env.CCACHE_DIR }}
93+
key: ccache-wheels-numpy-v${{ env.NUMPY_VERSION }}-manylinux_riscv64-${{ matrix.python }}-${{ github.run_id }}
94+
95+
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
96+
with:
97+
name: numpy-${{ env.NUMPY_VERSION }}-${{ matrix.python }}-manylinux_riscv64
98+
path: ./wheelhouse/*.whl
99+
if-no-files-found: error
100+
101+
publish:
102+
name: Publish numpy ${{ inputs.version || '2.5.0' }} to GitLab
103+
needs: build_wheels
104+
# Only publish when the workflow was triggered from main with a specific
105+
# version. Manual trigger is the only entry point, so checking the ref is
106+
# enough to gate uploads.
107+
if: github.ref == 'refs/heads/main'
108+
runs-on: ubuntu-24.04-riscv
109+
permissions:
110+
contents: read
111+
112+
steps:
113+
- name: Checkout python-wheels
114+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
115+
with:
116+
path: python-wheels-repo
117+
persist-credentials: false
118+
119+
- name: Download wheels
120+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
121+
with:
122+
pattern: numpy-${{ env.NUMPY_VERSION }}-*-manylinux_riscv64
123+
path: dist
124+
merge-multiple: true
125+
126+
- name: Publish to GitLab Package Registry
127+
uses: ./python-wheels-repo/actions/publish-to-gitlab
128+
with:
129+
gitlab-token: ${{ secrets.GITLAB_DEPLOY_TOKEN }}
130+
token-type: deploy-token
131+
gitlab-project-id: ${{ vars.GITLAB_PROJECT_ID }}
132+
package-name: numpy
133+
package-version: ${{ env.NUMPY_VERSION }}
134+
files: |
135+
dist/*.whl

0 commit comments

Comments
 (0)