Skip to content

Commit

Permalink
Publish sherpa_onnx.har for HarmonyOS (#1572)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Nov 28, 2024
1 parent 109fb79 commit 315d8e2
Show file tree
Hide file tree
Showing 104 changed files with 6,257 additions and 4,378 deletions.
181 changes: 181 additions & 0 deletions .github/workflows/har.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
name: har

on:
push:
branches:
- master
# - ohos-har
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'

workflow_dispatch:

concurrency:
group: har-${{ github.ref }}
cancel-in-progress: true

jobs:
har:
name: Har
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: har-linux

- name: cache-toolchain
id: cache-toolchain-ohos
uses: actions/cache@v4
with:
path: command-line-tools
key: commandline-tools-linux-x64-5.0.5.200.zip

- name: Download toolchain
if: steps.cache-toolchain-ohos.outputs.cache-hit != 'true'
shell: bash
run: |
curl -SL -O https://huggingface.co/csukuangfj/harmonyos-commandline-tools/resolve/main/commandline-tools-linux-x64-5.0.5.200.zip
unzip commandline-tools-linux-x64-5.0.5.200.zip
rm commandline-tools-linux-x64-5.0.5.200.zip
- name: Set environment variable
shell: bash
run: |
echo "$GITHUB_WORKSPACE/command-line-tools/sdk/default/openharmony/native/build-tools/cmake/bin" >> "$GITHUB_PATH"
which cmake
cmake --version
ls -lh $GITHUB_WORKSPACE/command-line-tools/sdk/default/openharmony/native/build/cmake/ohos.toolchain.cmake
echo "===="
cat $GITHUB_WORKSPACE/command-line-tools/sdk/default/openharmony/native/build/cmake/ohos.toolchain.cmake
echo "===="
# echo "$GITHUB_WORKSPACE/command-line-tools/sdk/default/openharmony/native/llvm/bin" >> "$GITHUB_PATH"
ls -lh $GITHUB_WORKSPACE/command-line-tools/sdk/default/openharmony/native/llvm/bin/
echo "--"
ls -lh $GITHUB_WORKSPACE/command-line-tools/sdk/default/openharmony/native/llvm/bin/*unknown*
cat $GITHUB_PATH
# /home/runner/work/onnxruntime-libs/onnxruntime-libs/command-line-tools/sdk/default/openharmony/native/llvm/bin/aarch64-unknown-linux-ohos-clang -v || true
export PATH=$PWD/command-line-tools/sdk/default/openharmony/native/llvm/bin:$PATH
echo "path: $PATH"
which aarch64-unknown-linux-ohos-clang++ || true
which aarch64-unknown-linux-ohos-clang || true
aarch64-unknown-linux-ohos-clang++ --version || true
aarch64-unknown-linux-ohos-clang --version || true
which armv7-unknown-linux-ohos-clang++
which armv7-unknown-linux-ohos-clang
armv7-unknown-linux-ohos-clang++ --version
armv7-unknown-linux-ohos-clang --version
which x86_64-unknown-linux-ohos-clang++
which x86_64-unknown-linux-ohos-clang
x86_64-unknown-linux-ohos-clang++ --version
x86_64-unknown-linux-ohos-clang --version
- name: Build libraries
shell: bash
run: |
export CMAKE_CXX_COMPILER_LAUNCHER=ccache
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
cmake --version
export OHOS_SDK_NATIVE_DIR="$GITHUB_WORKSPACE/command-line-tools/sdk/default/openharmony/native"
./build-ohos-arm64-v8a.sh
./build-ohos-x86-64.sh
- name: Build Har
shell: bash
run: |
export PATH="$GITHUB_WORKSPACE/command-line-tools/bin:$PATH"
which hvigorw
pushd harmony-os/SherpaOnnxHar
hvigorw --mode module -p product=default -p module=sherpa_onnx@default assembleHar --analyze=normal --parallel --incremental --no-daemon
ls -lh ./sherpa_onnx/build/default/outputs/default/sherpa_onnx.har
cp -v ./sherpa_onnx/build/default/outputs/default/sherpa_onnx.har ../../
popd
ls -lh *.har
- name: Collect result
shell: bash
run: |
SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
echo "SHERPA_ONNX_VERSION=$SHERPA_ONNX_VERSION" >> "$GITHUB_ENV"
mv sherpa_onnx.har sherpa_onnx-$SHERPA_ONNX_VERSION.har
- uses: actions/upload-artifact@v4
with:
name: sherpa-onnx-har
path: ./sherpa_onnx*.har

- name: Release jar
if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && github.event_name == 'push' && contains(github.ref, 'refs/tags/')
uses: svenstaro/upload-release-action@v2
with:
file_glob: true
overwrite: true
file: ./*.har
# repo_name: k2-fsa/sherpa-onnx
# repo_token: ${{ secrets.UPLOAD_GH_SHERPA_ONNX_TOKEN }}
# tag: v1.10.32

- name: Publish to huggingface
if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
uses: nick-fields/retry@v3
with:
max_attempts: 20
timeout_seconds: 200
shell: bash
command: |
git config --global user.email "csukuangfj@gmail.com"
git config --global user.name "Fangjun Kuang"
rm -rf huggingface
export GIT_LFS_SKIP_SMUDGE=1
export GIT_CLONE_PROTECTION_ACTIVE=false
SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-harmony-os huggingface
cd huggingface
git fetch
git pull
git merge -m "merge remote" --ff origin main
d=har
mkdir -p $d
cp -v ../*.har $d/
git status
git lfs track "*.har"
git add .
git commit -m "add more hars"
git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-harmony-os main
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@

### Supported platforms

|Architecture| Android | iOS | Windows | macOS | linux |
|------------|---------|---------|------------|-------|-------|
| x64 | ✔️ | | ✔️ | ✔️ | ✔️ |
| x86 | ✔️ | | ✔️ | | |
| arm64 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
| arm32 | ✔️ | | | | ✔️ |
| riscv64 | | | | | ✔️ |

|Architecture| Android | iOS | Windows | macOS | linux | HarmonyOS |
|------------|---------|---------|------------|-------|-------|-----------|
| x64 | ✔️ | | ✔️ | ✔️ | ✔️ | ✔️ |
| x86 | ✔️ | | ✔️ | | | |
| arm64 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
| arm32 | ✔️ | | | | ✔️ | ✔️ |
| riscv64 | | | | | ✔️ | |

### Supported programming languages

Expand Down Expand Up @@ -65,6 +64,7 @@ on the following platforms and operating systems:
- Linux, macOS, Windows, openKylin
- Android, WearOS
- iOS
- HarmonyOS
- NodeJS
- WebAssembly
- [Raspberry Pi][Raspberry Pi]
Expand Down
6 changes: 6 additions & 0 deletions build-ohos-arm64-v8a.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,9 @@ cp -fv $onnxruntime_dir/lib/libonnxruntime.so install/lib

rm -rf install/share
rm -rf install/lib/pkgconfig

d=../harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/libs/arm64-v8a
if [ -d $d ]; then
cp -v install/lib/libsherpa-onnx-c-api.so $d/
cp -v install/lib/libonnxruntime.so $d/
fi
6 changes: 6 additions & 0 deletions build-ohos-x86-64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,9 @@ cp -fv $onnxruntime_dir/lib/libonnxruntime.so install/lib

rm -rf install/share
rm -rf install/lib/pkgconfig

d=../harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/libs/x86_64
if [ -d $d ]; then
cp -v install/lib/libsherpa-onnx-c-api.so $d/
cp -v install/lib/libonnxruntime.so $d/
fi
1 change: 1 addition & 0 deletions harmony-os/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!build-profile.json5
12 changes: 12 additions & 0 deletions harmony-os/SherpaOnnxHar/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/node_modules
/oh_modules
/local.properties
/.idea
**/build
/.hvigor
.cxx
/.clangd
/.clang-format
/.clang-tidy
**/.test
/.appanalyzer
10 changes: 10 additions & 0 deletions harmony-os/SherpaOnnxHar/AppScope/app.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"app": {
"bundleName": "com.k2fsa.sherpa.onnx",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"string": [
{
"name": "app_name",
"value": "SherpaOnnxHar"
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions harmony-os/SherpaOnnxHar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Introduction

How to build `sherpa_onnx.har` from the command line:

```bash
git clone https://github.com/k2-fsa/sherpa-onnx
cd sherpa-onnx
./build-ohos-arm64-v8a.sh
./build-ohos-x86-64.sh

cd harmony-os/SherpaOnnxHar

hvigorw clean --no-daemon

hvigorw --mode module -p product=default -p module=sherpa_onnx@default assembleHar --analyze=normal --parallel --incremental --no-daemon

ls -lh ./sherpa_onnx/build/default/outputs/default/sherpa_onnx.har
```
44 changes: 44 additions & 0 deletions harmony-os/SherpaOnnxHar/build-profile.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"app": {
"signingConfigs": [],
"products": [
{
"name": "default",
"signingConfig": "default",
"compatibleSdkVersion": "4.0.0(10)",
"runtimeOS": "HarmonyOS",
"buildOption": {
"strictMode": {
"caseSensitiveCheck": true,
}
}
}
],
"buildModeSet": [
{
"name": "debug",
},
{
"name": "release"
}
]
},
"modules": [
{
"name": "entry",
"srcPath": "./entry",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
},
{
"name": "sherpa_onnx",
"srcPath": "./sherpa_onnx",
}
]
}
20 changes: 20 additions & 0 deletions harmony-os/SherpaOnnxHar/code-linter.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"files": [
"**/*.ets"
],
"ignore": [
"**/src/ohosTest/**/*",
"**/src/test/**/*",
"**/src/mock/**/*",
"**/node_modules/**/*",
"**/oh_modules/**/*",
"**/build/**/*",
"**/.preview/**/*"
],
"ruleSet": [
"plugin:@performance/recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
}
}
6 changes: 6 additions & 0 deletions harmony-os/SherpaOnnxHar/entry/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/node_modules
/oh_modules
/.preview
/build
/.cxx
/.test
28 changes: 28 additions & 0 deletions harmony-os/SherpaOnnxHar/entry/build-profile.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"apiType": "stageMode",
"buildOption": {
},
"buildOptionSet": [
{
"name": "release",
"arkOptions": {
"obfuscation": {
"ruleOptions": {
"enable": false,
"files": [
"./obfuscation-rules.txt"
]
}
}
}
},
],
"targets": [
{
"name": "default"
},
{
"name": "ohosTest",
}
]
}
6 changes: 6 additions & 0 deletions harmony-os/SherpaOnnxHar/entry/hvigorfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { hapTasks } from '@ohos/hvigor-ohos-plugin';

export default {
system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
}
Loading

0 comments on commit 315d8e2

Please sign in to comment.