From 2def3df9abb6cae216fbf112ea684eee51a5d213 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Thu, 3 Sep 2026 15:25:50 +0200 Subject: [PATCH] opencv-contrib-python: add build-opencv-contrib-python.yml for riscv64 wheels Mirrors build-opencv-python.yml, the third build variant from the same opencv/opencv-python source repo: checks out the opencv_contrib submodule and sets ENABLE_CONTRIB=1 (plus the matching find_version.py/version.py stamp) to build opencv_contrib_python instead of opencv_python. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01Az13NcXsVZzzxXmaxxUEy7 --- .../workflows/build-opencv-contrib-python.yml | 140 ++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 .github/workflows/build-opencv-contrib-python.yml diff --git a/.github/workflows/build-opencv-contrib-python.yml b/.github/workflows/build-opencv-contrib-python.yml new file mode 100644 index 000000000..43277fe85 --- /dev/null +++ b/.github/workflows/build-opencv-contrib-python.yml @@ -0,0 +1,140 @@ +# SPDX-FileCopyrightText: 2026 The RISE Project +# SPDX-License-Identifier: MIT +--- +name: Build opencv-contrib-python wheels (riscv64) + +on: + workflow_dispatch: + inputs: + version: + description: 'opencv-contrib-python version to build (e.g. 5.0.0.93)' + required: true + default: '5.0.0.93' + pull_request: + paths: + - '.github/workflows/build-opencv-contrib-python.yml' + +concurrency: + group: ${{ github.workflow }}-${{ inputs.version || '5.0.0.93' }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +permissions: + contents: read # to fetch code (actions/checkout) + +env: + OPENCV_PYTHON_VERSION: ${{ inputs.version || '5.0.0.93' }} + MANYLINUX_RISCV64_IMAGE: quay.io/pypa/manylinux_2_39_riscv64 + +jobs: + setup: + uses: $/.github/workflows/_setup.yml + + build_wheels: + needs: [setup] + name: Build opencv-contrib-python ${{ inputs.version || '5.0.0.93' }} cp37-abi3-manylinux_riscv64 + runs-on: ubuntu-24.04-riscv + timeout-minutes: 1440 + + steps: + # Upstream tags a release by its build number alone: 5.0.0.93 is tag `93`. + - name: Resolve upstream tag + run: echo "OPENCV_TAG=${OPENCV_PYTHON_VERSION##*.}" >> "$GITHUB_ENV" + + - name: Checkout opencv-python ${{ env.OPENCV_PYTHON_VERSION }} + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: opencv/opencv-python + ref: ${{ env.OPENCV_TAG }} + fetch-depth: 0 + persist-credentials: false + + # Checked out one by one and shallow: `submodules: true` alongside the + # fetch-depth 0 above pulls ~1.8 GB of OpenCV history. + - name: Resolve submodule commits + run: | + { + echo "OPENCV_SHA=$(git rev-parse HEAD:opencv)" + echo "OPENCV_CONTRIB_SHA=$(git rev-parse HEAD:opencv_contrib)" + echo "OPENCV_EXTRA_SHA=$(git rev-parse HEAD:opencv_extra)" + } >> "$GITHUB_ENV" + + - name: Checkout OpenCV sources + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: opencv/opencv + ref: ${{ env.OPENCV_SHA }} + path: opencv + persist-credentials: false + + - name: Checkout OpenCV contrib modules + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: opencv/opencv_contrib + ref: ${{ env.OPENCV_CONTRIB_SHA }} + path: opencv_contrib + persist-credentials: false + + - name: Checkout OpenCV test data + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: opencv/opencv_extra + ref: ${{ env.OPENCV_EXTRA_SHA }} + path: opencv_extra + persist-credentials: false + + # setup.py re-derives cv2/version.py from `git describe` whenever .git is + # present, so stamp it here and drop the repositories: the build then runs + # no git at all, and cibuildwheel copies ~1 GB less into the container. + # Without .git the stamped `contrib` flag is what selects the package + # name and -DOPENCV_EXTRA_MODULES_PATH, so ENABLE_CONTRIB below cannot be + # the only place it is set. + - name: Stamp the package version + run: | + python3 find_version.py True False False False + grep -Fqx "opencv_version = \"${OPENCV_PYTHON_VERSION}\"" cv2/version.py + grep -Fqx "contrib = True" cv2/version.py + rm -rf .git opencv/.git opencv_contrib/.git opencv_extra/.git + + - name: Build wheels + uses: pypa/cibuildwheel@1828c10ab37f080699c7b81cea34097c684a7074 # v4.2.0 + env: + # setup.py always configures -DPYTHON3_LIMITED_API=ON, so the one + # cp37-abi3 wheel built on cp312 is reused to test 3.13 and 3.14. + # Upstream publishes no free-threaded wheel, hence no cp314t entry. + CIBW_BUILD: cp312-manylinux_riscv64 cp313-manylinux_riscv64 cp314-manylinux_riscv64 + CIBW_MANYLINUX_RISCV64_IMAGE: ${{ env.MANYLINUX_RISCV64_IMAGE }} + CIBW_BUILD_FRONTEND: build + CIBW_CONFIG_SETTINGS: --build-option=--py-limited-api=cp37 + # Upstream's CI_BUILD=1 additionally links Qt5 and bundles DejaVu fonts; + # neither is packaged for riscv64, so highgui is built without a GUI backend. + # PNG_RISCV_RVV defaults to OpenCV's CPU_RVV_SUPPORTED, which is set from a + # -march=rv64gc_v *dispatch* probe; libpng then re-probes the intrinsics with + # the baseline flags and fails the build. Its own sources get no -march either, + # so RVV can only be off here. + CIBW_ENVIRONMENT: >- + ENABLE_CONTRIB=1 + MAKEFLAGS=-j$(nproc) + CMAKE_ARGS=-DPNG_RISCV_RVV=off + PIP_EXTRA_INDEX_URL=https://pypi.riseproject.dev/simple/ + CIBW_TEST_ENVIRONMENT: 'PIP_ONLY_BINARY=:all:' + CIBW_TEST_COMMAND: >- + python {project}/tests/get_build_info.py && + cd {project}/opencv && + OPENCV_TEST_DATA_PATH={project}/opencv_extra/testdata + python modules/python/test/test.py -v --repo . + + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: opencv-contrib-python-${{ env.OPENCV_PYTHON_VERSION }}-cp37-abi3-manylinux_riscv64 + path: ./wheelhouse/*.whl + if-no-files-found: error + + publish: + name: Publish opencv-contrib-python ${{ inputs.version || '5.0.0.93' }} + needs: [setup, build_wheels] + permissions: + contents: write + pull-requests: write + uses: $/.github/workflows/_publish-wheel.yml + with: + artifact-pattern: opencv-contrib-python-${{ inputs.version || '5.0.0.93' }}-*-manylinux_riscv64