Skip to content

Commit cdf367c

Browse files
authored
gemmi: add build-gemmi.yml for riscv64 wheels (#1026)
* **Package**: `gemmi` * **Version**: `0.7.5` * **Source**: https://github.com/project-gemmi/gemmi * **Docs**: https://github.com/project-gemmi/gemmi Compiles gemmi's C++ macromolecular-crystallography library and its nanobind Python bindings. Upstream publishes no riscv64 wheel. Mirrors [upstream's `wheels2.yml`](https://github.com/project-gemmi/gemmi/blob/v0.7.5/.github/workflows/wheels2.yml). **Differs from upstream** - Nothing beyond the riscv64 image. **Testing** - same as upstream **License**: OK
1 parent af77ab6 commit cdf367c

2 files changed

Lines changed: 146 additions & 0 deletions

File tree

‎.github/workflows/build-gemmi.yml‎

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# SPDX-FileCopyrightText: 2026 The RISE Project
2+
# SPDX-License-Identifier: MIT
3+
---
4+
# Based on the `build_wheels` job of
5+
# https://github.com/project-gemmi/gemmi/blob/v0.7.5/.github/workflows/wheels2.yml
6+
name: Build gemmi wheels (riscv64)
7+
8+
on:
9+
workflow_dispatch:
10+
inputs:
11+
version:
12+
description: 'gemmi version/tag to build (git tag without leading v, e.g. 0.7.5)'
13+
required: true
14+
default: '0.7.5'
15+
pull_request:
16+
paths:
17+
- '.github/workflows/build-gemmi.yml'
18+
- 'patches/gemmi/**'
19+
20+
concurrency:
21+
group: ${{ github.workflow }}-${{ inputs.version || '0.7.5' }}-${{ github.head_ref || github.run_id }}
22+
cancel-in-progress: true
23+
24+
permissions:
25+
contents: read # to fetch code (actions/checkout)
26+
27+
env:
28+
GEMMI_VERSION: ${{ inputs.version || '0.7.5' }}
29+
MANYLINUX_RISCV64_IMAGE: quay.io/pypa/manylinux_2_39_riscv64
30+
MUSLLINUX_RISCV64_IMAGE: quay.io/pypa/musllinux_1_2_riscv64
31+
32+
jobs:
33+
setup:
34+
uses: $/.github/workflows/_setup.yml
35+
36+
build_wheels:
37+
needs: [setup]
38+
name: Build gemmi ${{ inputs.version || '0.7.5' }} ${{ matrix.python }}-${{ matrix.libc }}_riscv64
39+
runs-on: ubuntu-24.04-riscv
40+
timeout-minutes: 120
41+
strategy:
42+
fail-fast: false
43+
matrix:
44+
python: ["cp312", "cp313", "cp314", "cp314t"]
45+
libc: [manylinux, musllinux]
46+
47+
steps:
48+
- name: Checkout gemmi v${{ env.GEMMI_VERSION }}
49+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
50+
with:
51+
repository: project-gemmi/gemmi
52+
ref: v${{ env.GEMMI_VERSION }}
53+
persist-credentials: false
54+
55+
- name: Checkout python-wheels
56+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
57+
with:
58+
path: python-wheels
59+
persist-credentials: false
60+
61+
# stb_sprintf.h has no riscv64 entry in its 64-bit-pointer-arch allowlist.
62+
- name: Patch gemmi source
63+
run: git apply python-wheels/patches/gemmi/${{ env.GEMMI_VERSION }}/00*.patch
64+
65+
- uses: pypa/cibuildwheel@1828c10ab37f080699c7b81cea34097c684a7074 # v4.2.0
66+
env:
67+
CIBW_ARCHS: riscv64
68+
CIBW_BUILD: ${{ matrix.python }}-${{ matrix.libc }}_riscv64
69+
CIBW_MANYLINUX_RISCV64_IMAGE: ${{ env.MANYLINUX_RISCV64_IMAGE }}
70+
CIBW_MUSLLINUX_RISCV64_IMAGE: ${{ env.MUSLLINUX_RISCV64_IMAGE }}
71+
# find_package(nanobind 2.4.0) in CMakeLists.txt rejects nanobind 3.x as
72+
# incompatible; pyproject.toml's build-system.requires has no upper bound.
73+
CIBW_BEFORE_ALL: echo 'nanobind<3' > /nanobind-constraint.txt
74+
# The fetched zlib-ng's RVV chunkset/inflate kernels SIGILL on the first
75+
# gzipped file gemmi reads; fall back to its portable C implementation.
76+
CIBW_ENVIRONMENT: >-
77+
SKBUILD_CMAKE_ARGS='-DBUILD_GEMMI_PROGRAM=OFF;-DINSTALL_DEV_FILES=OFF;-DBUILD_SHARED_LIBS=OFF;-DFETCH_ZLIB_NG=ON;-DWITH_RVV=OFF'
78+
PIP_CONSTRAINT=/nanobind-constraint.txt
79+
PIP_BUILD_CONSTRAINT=/nanobind-constraint.txt
80+
81+
- name: Check wheel contents
82+
run: |
83+
python3 - wheelhouse/*.whl <<'EOF'
84+
import sys, zipfile
85+
path = sys.argv[1]
86+
names = zipfile.ZipFile(path).namelist()
87+
exts = [n for n in names if n.endswith(".so")]
88+
assert exts and all("gemmi_ext" in n for n in exts), exts
89+
licences = {n.split(".dist-info/licenses/", 1)[1] for n in names
90+
if ".dist-info/licenses/" in n and not n.endswith("/")}
91+
assert licences == {"LICENSE.txt"}, licences
92+
EOF
93+
94+
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
95+
with:
96+
name: gemmi-${{ env.GEMMI_VERSION }}-${{ matrix.python }}-${{ matrix.libc }}_riscv64
97+
path: ./wheelhouse/*.whl
98+
if-no-files-found: error
99+
100+
publish:
101+
name: Publish gemmi ${{ inputs.version || '0.7.5' }}
102+
needs: [setup, build_wheels]
103+
permissions:
104+
contents: write
105+
pull-requests: write
106+
uses: $/.github/workflows/_publish-wheel.yml
107+
with:
108+
artifact-pattern: gemmi-${{ inputs.version || '0.7.5' }}-*riscv64
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
From dadacda267c6a3078c80576a103e970b4ed59ffc Mon Sep 17 00:00:00 2001
2+
From: Ludovic Henry <git@ludovic.dev>
3+
Date: Sun, 6 Sep 2026 13:48:56 +0200
4+
Subject: [PATCH] third_party: detect riscv64 as a 64-bit pointer arch in
5+
stb_sprintf
6+
7+
stb_sprintf.h's stbsp__uintptr allowlist (__ppc64__, __aarch64__,
8+
__x86_64__, __s390x__, ...) has no riscv64 entry, so it falls back to
9+
a 32-bit unsigned int on a platform with 64-bit pointers. Every
10+
(stbsp__uintptr)ptr alignment check in the file then narrows a
11+
pointer to 32 bits, which GCC 14 rejects as a hard error (cast ...
12+
loses precision [-fpermissive]) rather than a warning.
13+
14+
Add the same __riscv/__riscv_xlen==64 test glibc and the Linux kernel
15+
use to detect riscv64, matching the pattern the file already uses for
16+
every other LP64 architecture.
17+
18+
Upstream-Status: Inappropriate [gemmi vendors stb_sprintf.h directly with no submodule; the actual gap is in nothings/stb's stb_sprintf.h itself, which has no riscv64 detection and no riscv64 CI]
19+
---
20+
third_party/stb_sprintf.h | 2 +-
21+
1 file changed, 1 insertion(+), 1 deletion(-)
22+
23+
diff --git a/third_party/stb_sprintf.h b/third_party/stb_sprintf.h
24+
index 28e9d64..4ce0ec9 100644
25+
--- a/third_party/stb_sprintf.h
26+
+++ b/third_party/stb_sprintf.h
27+
@@ -230,7 +230,7 @@ STBSP__PUBLICDEC void STB_SPRINTF_DECORATE(set_separators)(char comma, char peri
28+
#define stbsp__uint16 unsigned short
29+
30+
#ifndef stbsp__uintptr
31+
-#if defined(__ppc64__) || defined(__powerpc64__) || defined(__aarch64__) || defined(_M_X64) || defined(__x86_64__) || defined(__x86_64) || defined(__s390x__)
32+
+#if defined(__ppc64__) || defined(__powerpc64__) || defined(__aarch64__) || defined(_M_X64) || defined(__x86_64__) || defined(__x86_64) || defined(__s390x__) || (defined(__riscv) && __riscv_xlen == 64)
33+
#define stbsp__uintptr stbsp__uint64
34+
#else
35+
#define stbsp__uintptr stbsp__uint32
36+
--
37+
2.50.1 (Apple Git-155)
38+

0 commit comments

Comments
 (0)