Fangjun Kuang
Committed by GitHub

build pre-compiled libs for jni (linux x64) (#1026)

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