Fangjun Kuang
Committed by GitHub

Provide pre-built wheels for 32-bit arm (e.g., 32-bit Raspberry Pi) (#338)

  1 +name: build-wheels-armv7l
  2 +
  3 +on:
  4 + push:
  5 + branches:
  6 + - wheel
  7 + tags:
  8 + - '*'
  9 + workflow_dispatch:
  10 +
  11 +env:
  12 + SHERPA_ONNX_IS_IN_GITHUB_ACTIONS: 1
  13 +
  14 +concurrency:
  15 + group: build-wheels-armv7l-${{ github.ref }}
  16 + cancel-in-progress: true
  17 +
  18 +jobs:
  19 + build_wheels_armv7l:
  20 + name: ${{ matrix.python-version }}
  21 + runs-on: ${{ matrix.os }}
  22 + strategy:
  23 + fail-fast: false
  24 + matrix:
  25 + os: [ubuntu-latest]
  26 + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
  27 +
  28 + steps:
  29 + - uses: actions/checkout@v2
  30 +
  31 + - name: Set up QEMU
  32 + uses: docker/setup-qemu-action@v2
  33 + with:
  34 + platforms: arm
  35 +
  36 + - name: Get version
  37 + shell: bash
  38 + run: |
  39 + SHERPA_ONNX_VERSION=$(cat ./CMakeLists.txt | grep SHERPA_ONNX_VERSION | cut -d " " -f 2 | cut -d '"' -f 2)
  40 + echo "sherpa-onnx version: $SHERPA_ONNX_VERSION"
  41 + echo SHERPA_ONNX_VERSION=$SHERPA_ONNX_VERSION >> $GITHUB_ENV
  42 +
  43 + v=${{ matrix.python-version }}
  44 + PYTHON_VERSION=${v/./}
  45 + echo PYTHON_VERSION=$PYTHON_VERSION >> $GITHUB_ENV
  46 +
  47 + # https://github.com/mshr-h/onnx-dockerfile-for-raspberry-pi/blob/main/3.10-bullseye-build/Dockerfile.arm32v7
  48 + - name: Run docker
  49 + uses: addnab/docker-run-action@v3
  50 + with:
  51 + image: balenalib/raspberrypi3-python:${{ matrix.python-version }}-bullseye-build
  52 + options: |
  53 + --platform linux/arm/v7
  54 + --volume ${{ github.workspace }}/:/workspace
  55 + shell: bash
  56 + run: |
  57 + uname -a
  58 + cd /workspace
  59 + ls -lh
  60 +
  61 + id
  62 + apt install -qq -y git wget
  63 + wget -qq https://huggingface.co/csukuangfj/sherpa-onnx-cmake-deps/resolve/main/cmake-3.27-for-armv7.tar.bz2
  64 +
  65 + ls -lh
  66 + tar xf cmake-3.27-for-armv7.tar.bz2
  67 + ls -lh cmake/data/bin
  68 + chmod +x cmake/data/bin/cmake
  69 + export PATH=$PWD/cmake/data/bin:$PATH
  70 +
  71 + cmake --version
  72 +
  73 + export SHERPA_ONNX_CMAKE_ARGS='-DCMAKE_C_FLAGS="-march=armv7-a -mfloat-abi=hard -mfpu=neon" -DCMAKE_CXX_FLAGS="-march=armv7-a -mfloat-abi=hard -mfpu=neon"'
  74 + python3 setup.py bdist_wheel
  75 + ls -lh dist
  76 +
  77 + mkdir wheelhouse
  78 + cp -v dist/* wheelhouse/
  79 +
  80 + - name: Display wheels
  81 + shell: bash
  82 + run: |
  83 + ls -lh ./wheelhouse/
  84 +
  85 + - name: Upload wheel
  86 + uses: actions/upload-artifact@v3
  87 + with:
  88 + name: sherpa_onnx-${{ env.SHERPA_ONNX_VERSION }}-cp${{ env.PYTHON_VERSION }}-cp${{ env.PYTHON_VERSION }}-linux_armv7l.whl.zip
  89 + path: ./wheelhouse/*.whl
  90 +
  91 + - name: Publish wheels to PyPI
  92 + env:
  93 + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
  94 + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
  95 + run: |
  96 + python3 -m pip install --upgrade pip
  97 + python3 -m pip install wheel twine setuptools
  98 +
  99 + twine upload ./wheelhouse/*.whl
  1 +name: nightly-wheel-arm
  2 +
  3 +on:
  4 + push:
  5 + branches:
  6 + - master
  7 + - nightly
  8 + schedule:
  9 + # minute (0-59)
  10 + # hour (0-23)
  11 + # day of the month (1-31)
  12 + # month (1-12)
  13 + # day of the week (0-6)
  14 + # nightly build at 23:50 UTC time every day
  15 + - cron: "50 23 * * *"
  16 +
  17 + workflow_dispatch:
  18 +
  19 +concurrency:
  20 + group: nightly-wheel-armv7l-${{ github.ref }}
  21 + cancel-in-progress: true
  22 +
  23 +jobs:
  24 + nightly-wheel-arm:
  25 + name: ${{ matrix.python-version }}
  26 + # see https://github.com/actions/virtual-environments/blob/win19/20210525.0/images/win/Windows2019-Readme.md
  27 + runs-on: ${{ matrix.os}}
  28 + strategy:
  29 + fail-fast: false
  30 + matrix:
  31 + os: [ubuntu-latest]
  32 + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
  33 +
  34 + steps:
  35 + - uses: actions/checkout@v2
  36 + with:
  37 + fetch-depth: 0
  38 +
  39 + - name: Set up QEMU
  40 + uses: docker/setup-qemu-action@v2
  41 + with:
  42 + platforms: arm
  43 +
  44 + - name: Run docker
  45 + uses: addnab/docker-run-action@v3
  46 + with:
  47 + image: balenalib/raspberrypi3-python:${{ matrix.python-version }}-bullseye-build
  48 + options: |
  49 + --platform linux/arm/v7
  50 + --volume ${{ github.workspace }}/:/workspace
  51 + shell: bash
  52 + run: |
  53 + uname -a
  54 + cd /workspace
  55 + ls -lh
  56 +
  57 + v=${{ matrix.python-version }}
  58 + PYTHON_VERSION=${v/./}
  59 + echo PYTHON_VERSION=$PYTHON_VERSION >> $GITHUB_ENV
  60 + extra=""
  61 + if [[ ${PYTHON_VERSION} == "37" ]]; then
  62 + extra="m"
  63 + fi
  64 +
  65 + # pip install -i https://www.piwheels.org/simple numpy sentencepiece click
  66 + pip install https://huggingface.co/csukuangfj/sherpa-onnx-cmake-deps/resolve/main/sentencepiece-0.2.0-cp${PYTHON_VERSION}-cp${PYTHON_VERSION}${extra}-linux_armv7l.whl
  67 + pip install --no-deps sherpa-onnx
  68 + python3 -c "import sherpa_onnx; print(sherpa_onnx.__file__, sherpa_onnx.__version__); print(dir(sherpa_onnx)); print(help(sherpa_onnx))"
@@ -6,7 +6,7 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Linux) @@ -6,7 +6,7 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Linux)
6 message(FATAL_ERROR "This file is for Linux only. Given: ${CMAKE_SYSTEM_NAME}") 6 message(FATAL_ERROR "This file is for Linux only. Given: ${CMAKE_SYSTEM_NAME}")
7 endif() 7 endif()
8 8
9 -if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL arm) 9 +if(NOT (CMAKE_SYSTEM_PROCESSOR STREQUAL arm OR CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l))
10 message(FATAL_ERROR "This file is for arm only. Given: ${CMAKE_SYSTEM_PROCESSOR}") 10 message(FATAL_ERROR "This file is for arm only. Given: ${CMAKE_SYSTEM_PROCESSOR}")
11 endif() 11 endif()
12 12
@@ -7,7 +7,7 @@ function(download_onnxruntime) @@ -7,7 +7,7 @@ function(download_onnxruntime)
7 7
8 if(CMAKE_SYSTEM_NAME STREQUAL Linux AND CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) 8 if(CMAKE_SYSTEM_NAME STREQUAL Linux AND CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
9 include(onnxruntime-linux-aarch64) 9 include(onnxruntime-linux-aarch64)
10 - elseif(CMAKE_SYSTEM_NAME STREQUAL Linux AND CMAKE_SYSTEM_PROCESSOR STREQUAL arm) 10 + elseif(CMAKE_SYSTEM_NAME STREQUAL Linux AND (CMAKE_SYSTEM_PROCESSOR STREQUAL arm OR CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l))
11 include(onnxruntime-linux-arm) 11 include(onnxruntime-linux-arm)
12 elseif(CMAKE_SYSTEM_NAME STREQUAL Linux AND CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64) 12 elseif(CMAKE_SYSTEM_NAME STREQUAL Linux AND CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
13 if(SHERPA_ONNX_ENABLE_GPU) 13 if(SHERPA_ONNX_ENABLE_GPU)