|
| 1 | +# SPDX-FileCopyrightText: 2026 The RISE Project |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | +--- |
| 4 | +# This workflow is based on: https://github.com/onnx/optimizer/blob/v0.4.2/.github/workflows/build-and-test.yml |
| 5 | +name: Build onnxoptimizer wheels (riscv64) |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + version: |
| 11 | + description: 'Version glob to (re)build; empty builds every version of docs/packages/onnxoptimizer.yaml not released yet' |
| 12 | + required: false |
| 13 | + default: '' |
| 14 | + pull_request: |
| 15 | + branches: [main] |
| 16 | + paths: |
| 17 | + - '.github/workflows/build-onnxoptimizer.yml' |
| 18 | + - 'docs/packages/onnxoptimizer.yaml' |
| 19 | + push: |
| 20 | + branches: [main] |
| 21 | + paths: |
| 22 | + - '.github/workflows/build-onnxoptimizer.yml' |
| 23 | + - 'docs/packages/onnxoptimizer.yaml' |
| 24 | + |
| 25 | +concurrency: |
| 26 | + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} |
| 27 | + cancel-in-progress: true |
| 28 | + |
| 29 | +permissions: |
| 30 | + contents: read # to fetch code (actions/checkout) |
| 31 | + |
| 32 | +env: |
| 33 | + MANYLINUX_RISCV64_IMAGE: quay.io/pypa/manylinux_2_39_riscv64 |
| 34 | + |
| 35 | +jobs: |
| 36 | + setup: |
| 37 | + uses: $/.github/workflows/_setup.yml |
| 38 | + with: |
| 39 | + package: onnxoptimizer |
| 40 | + version: ${{ inputs.version }} |
| 41 | + |
| 42 | + build_wheels: |
| 43 | + needs: [setup] |
| 44 | + if: needs.setup.outputs.versions != '[]' |
| 45 | + name: Build onnxoptimizer ${{ matrix.version }} ${{ matrix.python }}-manylinux_riscv64 |
| 46 | + runs-on: ubuntu-24.04-riscv |
| 47 | + strategy: |
| 48 | + fail-fast: false |
| 49 | + matrix: |
| 50 | + version: ${{ fromJSON(needs.setup.outputs.versions) }} |
| 51 | + # Upstream ships cp310/cp311/cp312-abi3 (no free-threaded wheel: setup.py's |
| 52 | + # py_limited_api targets the stable cp312 ABI unconditionally once |
| 53 | + # py_minor >= 12, with no separate Py_GIL_DISABLED build path). cp310 is |
| 54 | + # dropped: onnx (the runtime dependency) has no riscv64 wheel for it on our |
| 55 | + # registry, at any version, and no py3-none-any fallback either (it's a |
| 56 | + # compiled extension). cp311 stays: onnx ships a riscv64 cp311 wheel up to |
| 57 | + # 1.21.0, and the build-time `protobuf` dependency resolves too, via its |
| 58 | + # py3-none-any fallback wheel (no riscv64-specific protobuf build exists |
| 59 | + # below cp312, but the pure-Python one installs anywhere). |
| 60 | + include: |
| 61 | + - python: cp311 |
| 62 | + # No riscv64 onnxruntime wheel on cp311; the rest of the suite still runs. |
| 63 | + onnxruntime: '' |
| 64 | + - python: cp312 |
| 65 | + onnxruntime: onnxruntime |
| 66 | + |
| 67 | + env: |
| 68 | + ONNXOPTIMIZER_VERSION: ${{ matrix.version }} |
| 69 | + |
| 70 | + steps: |
| 71 | + - name: Checkout onnxoptimizer v${{ env.ONNXOPTIMIZER_VERSION }} |
| 72 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 73 | + with: |
| 74 | + repository: onnx/optimizer |
| 75 | + ref: v${{ env.ONNXOPTIMIZER_VERSION }} |
| 76 | + submodules: recursive |
| 77 | + persist-credentials: false |
| 78 | + |
| 79 | + - name: Build wheels |
| 80 | + uses: pypa/cibuildwheel@1828c10ab37f080699c7b81cea34097c684a7074 # v4.2.0 |
| 81 | + with: |
| 82 | + output-dir: wheelhouse/ |
| 83 | + only: ${{ matrix.python }}-manylinux_riscv64 |
| 84 | + env: |
| 85 | + # The riscv64 manylinux image's own cmake (3.31.8) already satisfies |
| 86 | + # CMakeLists.txt's cmake_minimum_required(3.22); upstream's |
| 87 | + # CIBW_BEFORE_ALL_LINUX pip-installs a newer one only for its older |
| 88 | + # manylinux_2_28 x86_64/aarch64 images. |
| 89 | + CIBW_MANYLINUX_RISCV64_IMAGE: ${{ env.MANYLINUX_RISCV64_IMAGE }} |
| 90 | + CIBW_ENVIRONMENT: >- |
| 91 | + CMAKE_ARGS=" |
| 92 | + -DONNX_USE_PROTOBUF_SHARED_LIBS=OFF |
| 93 | + -DProtobuf_USE_STATIC_LIBS=ON |
| 94 | + -DONNX_USE_LITE_PROTO=ON |
| 95 | + -DCMAKE_POLICY_VERSION_MINIMUM=3.5 |
| 96 | + " |
| 97 | + PIP_EXTRA_INDEX_URL=https://pypi.riseproject.dev/simple/ |
| 98 | + CIBW_BEFORE_BUILD_LINUX: pip install protobuf |
| 99 | + # Upstream's flake8p/mypy lint step and its onnxscript/torch/torchvision |
| 100 | + # installs cover optional test paths guarded by try/except in |
| 101 | + # onnxoptimizer/test/optimizer_test.py (onnxscript itself isn't even |
| 102 | + # imported by any test); torch and torchvision have no riscv64 wheels, so |
| 103 | + # those paths are left to skip rather than installed. onnxruntime does |
| 104 | + # have a riscv64 wheel on our registry, but only from cp312 (matrix.onnxruntime). |
| 105 | + CIBW_TEST_REQUIRES: pytest pytest-xdist ${{ matrix.onnxruntime }} |
| 106 | + CIBW_TEST_COMMAND: pytest {project}/onnxoptimizer/test/ |
| 107 | + |
| 108 | + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 109 | + with: |
| 110 | + name: onnxoptimizer-${{ env.ONNXOPTIMIZER_VERSION }}-${{ matrix.python }}-manylinux_riscv64 |
| 111 | + path: wheelhouse/*.whl |
| 112 | + if-no-files-found: error |
| 113 | + |
| 114 | + publish: |
| 115 | + name: Publish onnxoptimizer ${{ matrix.version }} |
| 116 | + needs: [setup, build_wheels] |
| 117 | + if: needs.setup.outputs.versions != '[]' |
| 118 | + strategy: |
| 119 | + fail-fast: false |
| 120 | + matrix: |
| 121 | + version: ${{ fromJSON(needs.setup.outputs.versions) }} |
| 122 | + permissions: |
| 123 | + contents: write |
| 124 | + pull-requests: write |
| 125 | + uses: $/.github/workflows/_publish-wheel.yml |
| 126 | + secrets: |
| 127 | + app-private-key: ${{ secrets.RISEPROJECT_APP_PRIVATE_KEY }} |
| 128 | + with: |
| 129 | + artifact-pattern: onnxoptimizer-${{ matrix.version }}-*-manylinux_riscv64 |
0 commit comments