Fangjun Kuang
Committed by GitHub

Publish pre-built JNI libs for Linux aarch64 (#1472)

  1 +name: linux-jni-aarch64
  2 +
  3 +on:
  4 + push:
  5 + branches:
  6 + - jni
  7 + tags:
  8 + - 'v[0-9]+.[0-9]+.[0-9]+*'
  9 + workflow_dispatch:
  10 +
  11 +concurrency:
  12 + group: linux-jni-aarch64-${{ github.ref }}
  13 + cancel-in-progress: true
  14 +
  15 +jobs:
  16 + linux-jni-aarch64:
  17 + name: linux jni aarch64
  18 + runs-on: ${{ matrix.os }}
  19 + strategy:
  20 + fail-fast: false
  21 + matrix:
  22 + os: [ubuntu-latest]
  23 + # java-version: ['8', '11', '16', '17', '21']
  24 + java-version: ['21']
  25 +
  26 + steps:
  27 + - uses: actions/checkout@v4
  28 + with:
  29 + fetch-depth: 0
  30 +
  31 + - uses: actions/setup-java@v4
  32 + with:
  33 + distribution: 'temurin' # See 'Supported distributions' for available options
  34 + java-version: ${{ matrix.java-version }}
  35 +
  36 + - name: Set up QEMU
  37 + if: steps.cache-build-result.outputs.cache-hit != 'true'
  38 + uses: docker/setup-qemu-action@v2
  39 + with:
  40 + platforms: all
  41 +
  42 + - name: Display PWD
  43 + shell: bash
  44 + run: |
  45 + echo "pwd: $PWD"
  46 + ls -lh
  47 + du -h -d1 .
  48 +
  49 + - name: Build sherpa-onnx
  50 + if: matrix.java-version == '21'
  51 + uses: addnab/docker-run-action@v3
  52 + with:
  53 + image: quay.io/pypa/manylinux2014_aarch64
  54 + options: |
  55 + --volume ${{ github.workspace }}/:/home/runner/work/sherpa-onnx/sherpa-onnx
  56 + shell: bash
  57 + run: |
  58 + uname -a
  59 + gcc --version
  60 + cmake --version
  61 + cat /etc/*release
  62 + id
  63 + pwd
  64 +
  65 + yum install -y java-11-openjdk-devel
  66 + java -version
  67 + which java
  68 + ls -lh $(which java)
  69 + ls -lrt /etc/alternatives/java
  70 +
  71 + export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.23.0.9-2.el7_9.aarch64
  72 + echo "JAVA_HOME: $JAVA_HOME"
  73 + find $JAVA_HOME -name jni.h
  74 +
  75 + cd /home/runner/work/sherpa-onnx/sherpa-onnx
  76 +
  77 + git clone --depth 1 --branch v1.2.12 https://github.com/alsa-project/alsa-lib
  78 + pushd alsa-lib
  79 + ./gitcompile
  80 + popd
  81 +
  82 + export CPLUS_INCLUDE_PATH=$PWD/alsa-lib/include:$CPLUS_INCLUDE_PATH
  83 + export SHERPA_ONNX_ALSA_LIB_DIR=$PWD/alsa-lib/src/.libs
  84 +
  85 + mkdir build
  86 + cd build
  87 +
  88 + cmake \
  89 + -D SHERPA_ONNX_ENABLE_TTS=ON \
  90 + -D CMAKE_BUILD_TYPE=Release \
  91 + -D BUILD_SHARED_LIBS=ON \
  92 + -D CMAKE_INSTALL_PREFIX=./install \
  93 + -D SHERPA_ONNX_ENABLE_BINARY=OFF \
  94 + -D SHERPA_ONNX_ENABLE_JNI=ON \
  95 + ..
  96 +
  97 + make -j2
  98 + make install
  99 +
  100 + ls -lh lib
  101 + rm -rf ./install/lib/pkgconfig
  102 + rm -rf ./install/lib/share
  103 + rm -rf ./install/lib/cargs.h
  104 + rm -rf ./install/include/cargs.h
  105 + rm -rf ./install/lib/libcargs.so
  106 + rm -rf ./install/lib/libsherpa-onnx-c-api.so
  107 +
  108 + echo "----"
  109 + ls -lh install/lib
  110 +
  111 + echo "----"
  112 +
  113 + - uses: actions/upload-artifact@v4
  114 + if: matrix.java-version == '21'
  115 + with:
  116 + name: release-jni-linux-${{ matrix.java-version }}
  117 + path: build/install/*
  118 +
  119 + - name: Copy files
  120 + if: matrix.java-version == '21'
  121 + shell: bash
  122 + run: |
  123 + du -h -d1 .
  124 + SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
  125 +
  126 + dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-linux-aarch64-jni
  127 + mkdir $dst
  128 +
  129 + cp -a build/install/lib $dst/
  130 + cp -a build/install/include $dst/
  131 +
  132 + tree $dst
  133 +
  134 + tar cjvf ${dst}.tar.bz2 $dst
  135 + du -h -d1 .
  136 +
  137 + - name: Publish to huggingface
  138 + if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && matrix.java-version == '21'
  139 + env:
  140 + HF_TOKEN: ${{ secrets.HF_TOKEN }}
  141 + uses: nick-fields/retry@v3
  142 + with:
  143 + max_attempts: 20
  144 + timeout_seconds: 200
  145 + shell: bash
  146 + command: |
  147 + git config --global user.email "csukuangfj@gmail.com"
  148 + git config --global user.name "Fangjun Kuang"
  149 +
  150 + rm -rf huggingface
  151 + export GIT_CLONE_PROTECTION_ACTIVE=false
  152 + GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/csukuangfj/sherpa-onnx-libs huggingface
  153 +
  154 + cd huggingface
  155 + mkdir -p jni
  156 +
  157 + cp -v ../sherpa-onnx-*.tar.bz2 ./jni
  158 + cp -v ../*.jar ./jni
  159 +
  160 + git status
  161 + git lfs track "*.bz2"
  162 +
  163 + git add .
  164 +
  165 + git commit -m "add more files"
  166 +
  167 + git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-libs main
  168 +
  169 + - name: Release pre-compiled binaries and libs for linux aarch64
  170 + if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && github.event_name == 'push' && contains(github.ref, 'refs/tags/') && matrix.java-version == '21'
  171 + uses: svenstaro/upload-release-action@v2
  172 + with:
  173 + file_glob: true
  174 + overwrite: true
  175 + file: sherpa-onnx-*.tar.bz2
  176 +