-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support cross-compiling for HarmonyOS
- Loading branch information
1 parent
9a48012
commit 5e096b3
Showing
5 changed files
with
517 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
name: harmony-os | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- ohos | ||
tags: | ||
- 'v[0-9]+.[0-9]+.[0-9]+*' | ||
|
||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: harmony-os-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
harmony_os: | ||
name: Harmony OS ${{ matrix.arch }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest] | ||
arch: [arm64-v8a, armeabi-v7a, x86_64] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: ccache | ||
uses: hendrikmuhs/[email protected] | ||
with: | ||
key: ohos-${{ matrix.arch }} | ||
|
||
- 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 ${{ matrix.arch }} | ||
shell: bash | ||
run: | | ||
export CMAKE_CXX_COMPILER_LAUNCHER=ccache | ||
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" | ||
cmake --version | ||
arch=${{ matrix.arch }} | ||
echo "arch: $arch" | ||
export OHOS_SDK_NATIVE_DIR="$GITHUB_WORKSPACE/command-line-tools/sdk/default/openharmony/native" | ||
if [[ $arch == arm64-v8a ]]; then | ||
./build-ohos-arm64-v8a.sh | ||
elif [[ $arch == armeabi-v7a ]]; then | ||
./build-ohos-armeabi-v7a.sh | ||
elif [[ $arch == x86_64 ]]; then | ||
./build-ohos-x86-64.sh | ||
else | ||
echo "Unknown arch $arch" | ||
fi | ||
- name: Collect result for ${{ matrix.arch }} | ||
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" | ||
arch=${{ matrix.arch }} | ||
d=sherpa-onnx-$SHERPA_ONNX_VERSION-ohos-$arch | ||
if [[ $arch == x86_64 ]]; then | ||
cd ./build-ohos-x86-64 | ||
else | ||
cd ./build-ohos-$arch | ||
fi | ||
mv install $d | ||
tar cjfv $d.tar.bz2 $d | ||
ls -lh $d/lib | ||
file $d/lib/* | ||
readelf -d $d/lib/libsherpa-onnx-c-api.so | ||
mv $d.tar.bz2 ../ | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: sherpa-onnx-ohos-${{ matrix.arch }} | ||
path: ./*.tar.bz2 | ||
|
||
- 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: ./*.tar.bz2 | ||
# repo_name: k2-fsa/sherpa-onnx | ||
# repo_token: ${{ secrets.UPLOAD_GH_SHERPA_ONNX_TOKEN }} | ||
# tag: v1.10.23 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#!/usr/bin/env bash | ||
set -ex | ||
|
||
dir=$PWD/build-ohos-arm64-v8a | ||
|
||
mkdir -p $dir | ||
cd $dir | ||
|
||
# Please first download the commandline tools from | ||
# https://developer.huawei.com/consumer/cn/download/ | ||
# | ||
# Example filename on Linux: commandline-tools-linux-x64-5.0.5.200.zip | ||
# You can also download it from https://hf-mirror.com/csukuangfj/harmonyos-commandline-tools/tree/main | ||
|
||
# mkdir /star-fj/fangjun/software/huawei | ||
# cd /star-fj/fangjun/software/huawei | ||
# wget https://hf-mirror.com/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 | ||
if [ -z $OHOS_SDK_NATIVE_DIR ]; then | ||
OHOS_SDK_NATIVE_DIR=/star-fj/fangjun/software/huawei/command-line-tools/sdk/default/openharmony/native/ | ||
# You can find the following content inside OHOS_SDK_NATIVE_DIR | ||
# ls -lh /star-fj/fangjun/software/huawei/command-line-tools/sdk/default/openharmony/native/ | ||
# total 524K | ||
# -rw-r--r-- 1 kuangfangjun root 501K Jan 1 2001 NOTICE.txt | ||
# drwxr-xr-x 3 kuangfangjun root 0 Nov 6 22:36 build | ||
# drwxr-xr-x 3 kuangfangjun root 0 Nov 6 22:36 build-tools | ||
# -rw-r--r-- 1 kuangfangjun root 371 Jan 1 2001 compatible_config.json | ||
# drwxr-xr-x 4 kuangfangjun root 0 Nov 6 22:36 docs | ||
# drwxr-xr-x 10 kuangfangjun root 0 Nov 6 22:36 llvm | ||
# -rw-r--r-- 1 kuangfangjun root 16K Jan 1 2001 nativeapi_syscap_config.json | ||
# -rw-r--r-- 1 kuangfangjun root 5.9K Jan 1 2001 ndk_system_capability.json | ||
# -rw-r--r-- 1 kuangfangjun root 167 Jan 1 2001 oh-uni-package.json | ||
# drwxr-xr-x 3 kuangfangjun root 0 Nov 6 22:36 sysroot | ||
fi | ||
|
||
if [ ! -d $OHOS_SDK_NATIVE_DIR ]; then | ||
echo "Please first download Command Line Tools for HarmonyOS" | ||
exit 1 | ||
fi | ||
|
||
if [ ! -f $OHOS_SDK_NATIVE_DIR/llvm/bin/aarch64-unknown-linux-ohos-clang ]; then | ||
echo "$OHOS_SDK_NATIVE_DIR/llvm/bin/aarch64-unknown-linux-ohos-clang does not exist" | ||
echo "Please first download Command Line Tools for HarmonyOS" | ||
exit 1 | ||
fi | ||
|
||
export PATH=$OHOS_SDK_NATIVE_DIR/build-tools/cmake/bin:$PATH | ||
export PATH=$OHOS_SDK_NATIVE_DIR/llvm/bin:$PATH | ||
|
||
OHOS_TOOLCHAIN_FILE=$OHOS_SDK_NATIVE_DIR/build/cmake/ohos.toolchain.cmake | ||
|
||
if [ ! -f $OHOS_TOOLCHAIN_FILE ]; then | ||
echo "$OHOS_TOOLCHAIN_FILE does not exist" | ||
echo "Please first download Command Line Tools for HarmonyOS" | ||
exit 1 | ||
fi | ||
|
||
|
||
sleep 1 | ||
onnxruntime_version=1.16.3 | ||
onnxruntime_dir=onnxruntime-ohos-arm64-v8a-$onnxruntime_version | ||
|
||
if [ ! -f $onnxruntime_dir/lib/libonnxruntime.so ]; then | ||
wget -c -q https://github.com/csukuangfj/onnxruntime-libs/releases/download/v${onnxruntime_version}/$onnxruntime_dir.zip | ||
unzip $onnxruntime_dir.zip | ||
rm $onnxruntime_dir.zip | ||
fi | ||
|
||
export SHERPA_ONNXRUNTIME_LIB_DIR=$dir/$onnxruntime_dir/lib | ||
export SHERPA_ONNXRUNTIME_INCLUDE_DIR=$dir/$onnxruntime_dir/include | ||
|
||
echo "SHERPA_ONNXRUNTIME_LIB_DIR: $SHERPA_ONNXRUNTIME_LIB_DIR" | ||
echo "SHERPA_ONNXRUNTIME_INCLUDE_DIR $SHERPA_ONNXRUNTIME_INCLUDE_DIR" | ||
|
||
if [ -z $SHERPA_ONNX_ENABLE_TTS ]; then | ||
SHERPA_ONNX_ENABLE_TTS=ON | ||
fi | ||
|
||
if [ -z $SHERPA_ONNX_ENABLE_SPEAKER_DIARIZATION ]; then | ||
SHERPA_ONNX_ENABLE_SPEAKER_DIARIZATION=ON | ||
fi | ||
|
||
if [ -z $SHERPA_ONNX_ENABLE_BINARY ]; then | ||
SHERPA_ONNX_ENABLE_BINARY=OFF | ||
fi | ||
|
||
cmake \ | ||
-DOHOS_ARCH=arm64-v8a \ | ||
-DCMAKE_TOOLCHAIN_FILE=$OHOS_TOOLCHAIN_FILE \ | ||
-DSHERPA_ONNX_ENABLE_TTS=$SHERPA_ONNX_ENABLE_TTS \ | ||
-DSHERPA_ONNX_ENABLE_SPEAKER_DIARIZATION=$SHERPA_ONNX_ENABLE_SPEAKER_DIARIZATION \ | ||
-DSHERPA_ONNX_ENABLE_BINARY=$SHERPA_ONNX_ENABLE_BINARY \ | ||
-DBUILD_PIPER_PHONMIZE_EXE=OFF \ | ||
-DBUILD_PIPER_PHONMIZE_TESTS=OFF \ | ||
-DBUILD_ESPEAK_NG_EXE=OFF \ | ||
-DBUILD_ESPEAK_NG_TESTS=OFF \ | ||
-DCMAKE_BUILD_TYPE=Release \ | ||
-DBUILD_SHARED_LIBS=ON \ | ||
-DSHERPA_ONNX_ENABLE_PYTHON=OFF \ | ||
-DSHERPA_ONNX_ENABLE_TESTS=OFF \ | ||
-DSHERPA_ONNX_ENABLE_CHECK=OFF \ | ||
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ | ||
-DSHERPA_ONNX_ENABLE_JNI=OFF \ | ||
-DSHERPA_ONNX_ENABLE_C_API=ON \ | ||
-DCMAKE_INSTALL_PREFIX=./install \ | ||
.. | ||
|
||
# make VERBOSE=1 -j4 | ||
make -j2 | ||
make install/strip | ||
cp -fv $onnxruntime_dir/lib/libonnxruntime.so install/lib | ||
cp -fv $OHOS_SDK_NATIVE_DIR/llvm/lib/aarch64-linux-ohos/libc++_shared.so install/lib | ||
|
||
rm -rf install/share | ||
rm -rf install/lib/pkgconfig |
Oops, something went wrong.