diff --git a/.github/workflows/build-crick.yml b/.github/workflows/build-crick.yml new file mode 100644 index 000000000..b39d3d209 --- /dev/null +++ b/.github/workflows/build-crick.yml @@ -0,0 +1,124 @@ +# SPDX-FileCopyrightText: 2026 The RISE Project +# SPDX-License-Identifier: MIT +--- +# This workflow is based on: https://github.com/dask/crick/blob/0.0.8/.github/workflows/wheels.yml +name: Build crick wheels (riscv64) + +on: + workflow_dispatch: + inputs: + version: + description: 'crick version to build (git tag, e.g. 0.0.8)' + required: true + default: '0.0.8' + pull_request: + paths: + - '.github/workflows/build-crick.yml' + - 'patches/crick/**' + +concurrency: + group: ${{ github.workflow }}-${{ inputs.version || '0.0.8' }}-${{ 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 to 0.0.8 there. + CRICK_VERSION: ${{ inputs.version || '0.0.8' }} + MANYLINUX_RISCV64_IMAGE: quay.io/pypa/manylinux_2_39_riscv64 + +jobs: + setup: + uses: $/.github/workflows/_setup.yml + + build_wheels: + needs: [setup] + name: Build crick ${{ inputs.version || '0.0.8' }} ${{ matrix.python }}-manylinux_riscv64 + runs-on: ubuntu-24.04-riscv + timeout-minutes: 60 + strategy: + fail-fast: false + matrix: + # Per-interpreter (not abi3): the Cython extensions link the version-specific ABI. + # cp314/cp314t excluded: upstream tests neither (tests.yml matrix stops at 3.13, + # no free-threaded env, no classifiers), and both crash for reasons unrelated to + # riscv64 -- cp314 segfaults in object construction during test collection, cp314t + # fails test_object_reference_counting because free-threaded CPython's immortal + # objects break plain sys.getrefcount() arithmetic. + python: + - "cp310" + - "cp311" + - "cp312" + - "cp313" + + steps: + - name: Checkout crick ${{ env.CRICK_VERSION }} + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: dask/crick + ref: ${{ env.CRICK_VERSION }} + fetch-depth: 0 # versioneer derives the version from `git describe` + persist-credentials: false + + - name: Checkout python-wheels + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + path: python-wheels + persist-credentials: false + + - name: Apply patches + run: git apply python-wheels/patches/crick/${{ env.CRICK_VERSION }}/*.patch + + # `git apply` dirties the tree, and versioneer (unlike setuptools_scm) has no + # PRETEND_VERSION escape hatch -- `git describe --dirty` would otherwise turn + # 0.0.8 into 0.0.8+0.g.dirty. skip-worktree hides the two patched files + # from git's dirty check while keeping their patched content on disk. + - name: Pin the version past the patch (CLAUDE.md gotcha 315) + run: git update-index --skip-worktree crick/stats_stubs.c crick/space_saving_stubs.c.in + + - 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 }} + # numpy is a build-time requirement (headers + libnpymath) and, despite not + # being declared as a runtime dependency, an implicit one too (the compiled + # extensions call numpy's C API at import time). Only our registry has it + # for riscv64; only-binary keeps a newer PyPI release from winning the + # resolution and then compiling from sdist. + CIBW_ENVIRONMENT: >- + PIP_EXTRA_INDEX_URL=https://pypi.riseproject.dev/simple/ + PIP_ONLY_BINARY=numpy + CIBW_TEST_REQUIRES: pytest numpy + CIBW_TEST_COMMAND: python -m pytest --pyargs crick + + - name: Check wheel contents + run: | + python3 - wheelhouse/*.whl <<'EOF' + import sys, zipfile + names = zipfile.ZipFile(sys.argv[1]).namelist() + exts = {n.split("/")[-1].split(".")[0] for n in names if n.endswith(".so")} + assert exts == {"numpy_version", "space_saving", "stats", "tdigest"}, exts + licences = {n.rsplit("/", 1)[-1] for n in names if ".dist-info/licenses/" in n} - {""} + assert licences == {"LICENSE"}, licences + EOF + + - name: Store wheels + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: crick-${{ env.CRICK_VERSION }}-${{ matrix.python }}-manylinux_riscv64 + path: ./wheelhouse/*.whl + if-no-files-found: error + + publish: + name: Publish crick ${{ inputs.version || '0.0.8' }} + needs: [setup, build_wheels] + permissions: + contents: write + pull-requests: write + uses: $/.github/workflows/_publish-wheel.yml + with: + artifact-pattern: crick-${{ inputs.version || '0.0.8' }}-*-manylinux_riscv64 diff --git a/patches/crick/0.0.8/0001-Fix-sequence-point-error-in-stats_kurt.patch b/patches/crick/0.0.8/0001-Fix-sequence-point-error-in-stats_kurt.patch new file mode 100644 index 000000000..778140c34 --- /dev/null +++ b/patches/crick/0.0.8/0001-Fix-sequence-point-error-in-stats_kurt.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Ludovic Henry +Date: Mon, 7 Sep 2026 01:13:42 +0200 +Subject: [PATCH] Fix sequence point error in stats_kurt + +`kurt = m2 ? kurt = m4 / (m2 * m2) : 0;` assigns to `kurt` twice in the +same full expression, which newer/stricter compiler diagnostics flag as +a sequence-point hazard even though both assignments write the same +value. Drop the redundant inner assignment. + +Backported onto v0.0.8 unchanged; upstream carries it on main only, so +no 0.0.x release contains it yet. + +Upstream-Status: Backport [https://github.com/dask/crick/commit/720de70c6adf28cb30e8293597ed03b90d09bba8] +--- + crick/stats_stubs.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/crick/stats_stubs.c b/crick/stats_stubs.c +index 11f7c62..c8b73bc 100644 +--- a/crick/stats_stubs.c ++++ b/crick/stats_stubs.c +@@ -129,7 +129,7 @@ CRICK_INLINE double stats_kurt(stats_t *T, int fisher, int bias) { + n = T->count; + m2 = T->m2 / T->count; + m4 = T->m4 / T->count; +- kurt = m2 ? kurt = m4 / (m2 * m2) : 0; ++ kurt = m2 ? m4 / (m2 * m2) : 0; + if (!bias && n > 3 && m2 > 0) + kurt = ((n*n - 1)*kurt - 9*n + 15)/((n - 2)*(n - 3)); + return fisher ? kurt - 3 : kurt; +-- +2.50.1 diff --git a/patches/crick/0.0.8/0002-Avoid-dereferencing-a-type-punned-pointer-in-asint64.patch b/patches/crick/0.0.8/0002-Avoid-dereferencing-a-type-punned-pointer-in-asint64.patch new file mode 100644 index 000000000..81c3f038a --- /dev/null +++ b/patches/crick/0.0.8/0002-Avoid-dereferencing-a-type-punned-pointer-in-asint64.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Ludovic Henry +Date: Mon, 7 Sep 2026 01:13:42 +0200 +Subject: [PATCH] Avoid dereferencing a type-punned pointer in asint64 + +`return *(npy_int64 *)(&key);` reinterprets a `npy_float64` through an +incompatible pointer type, which violates strict aliasing (undefined +behaviour) and can be miscompiled under -O2/-O3 depending on compiler +and target. Use memcpy instead, which the compiler can still optimise +to a plain reinterpretation but without the aliasing violation. + +Backported onto v0.0.8 unchanged; upstream carries it on main only, so +no 0.0.x release contains it yet. + +Upstream-Status: Backport [https://github.com/dask/crick/commit/70d9dc24dd307f3c8cfd4580c7ecea42ec2a93a2] +--- + crick/space_saving_stubs.c.in | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/crick/space_saving_stubs.c.in b/crick/space_saving_stubs.c.in +index 4750816..fe7ce38 100644 +--- a/crick/space_saving_stubs.c.in ++++ b/crick/space_saving_stubs.c.in +@@ -460,5 +460,7 @@ finish: + * as int64. Define a small helper to view float64 as int64: */ + + CRICK_INLINE npy_int64 asint64(npy_float64 key) { +- return *(npy_int64 *)(&key); ++ npy_int64 bytes; ++ memcpy(&bytes, &key, sizeof(bytes)); ++ return bytes; + } +-- +2.50.1