Committed by
GitHub
Support static linking onnxruntime for 64-bit ARM (#402)
正在显示
9 个修改的文件
包含
291 行增加
和
19 行删除
| 1 | # Modified from https://github.com/Tencent/ncnn/blob/master/.github/workflows/linux-arm-cpu-gcc.yml | 1 | # Modified from https://github.com/Tencent/ncnn/blob/master/.github/workflows/linux-arm-cpu-gcc.yml |
| 2 | -name: aarch64-linux-gnu | 2 | +name: aarch64-linux-gnu-shared |
| 3 | 3 | ||
| 4 | on: | 4 | on: |
| 5 | push: | 5 | push: |
| @@ -8,7 +8,7 @@ on: | @@ -8,7 +8,7 @@ on: | ||
| 8 | tags: | 8 | tags: |
| 9 | - '*' | 9 | - '*' |
| 10 | paths: | 10 | paths: |
| 11 | - - '.github/workflows/aarch64-linux-gnu.yaml' | 11 | + - '.github/workflows/aarch64-linux-gnu-shared.yaml' |
| 12 | - 'CMakeLists.txt' | 12 | - 'CMakeLists.txt' |
| 13 | - 'cmake/**' | 13 | - 'cmake/**' |
| 14 | - 'sherpa-onnx/csrc/*' | 14 | - 'sherpa-onnx/csrc/*' |
| @@ -17,7 +17,7 @@ on: | @@ -17,7 +17,7 @@ on: | ||
| 17 | branches: | 17 | branches: |
| 18 | - master | 18 | - master |
| 19 | paths: | 19 | paths: |
| 20 | - - '.github/workflows/aarch64-linux-gnu.yaml' | 20 | + - '.github/workflows/aarch64-linux-gnu-shared.yaml' |
| 21 | - 'CMakeLists.txt' | 21 | - 'CMakeLists.txt' |
| 22 | - 'cmake/**' | 22 | - 'cmake/**' |
| 23 | - 'sherpa-onnx/csrc/*' | 23 | - 'sherpa-onnx/csrc/*' |
| @@ -35,12 +35,13 @@ env: | @@ -35,12 +35,13 @@ env: | ||
| 35 | ${{ github.event.release.tag_name != '' || github.event.inputs.release == 'true' }} | 35 | ${{ github.event.release.tag_name != '' || github.event.inputs.release == 'true' }} |
| 36 | 36 | ||
| 37 | concurrency: | 37 | concurrency: |
| 38 | - group: aarch64-linux-gnu-${{ github.ref }} | 38 | + group: aarch64-linux-gnu-shared-${{ github.ref }} |
| 39 | cancel-in-progress: true | 39 | cancel-in-progress: true |
| 40 | 40 | ||
| 41 | jobs: | 41 | jobs: |
| 42 | - aarch64_linux_gnu: | 42 | + aarch64_linux_gnu_shared: |
| 43 | runs-on: ${{ matrix.os }} | 43 | runs-on: ${{ matrix.os }} |
| 44 | + name: aarch64 shared lib test | ||
| 44 | strategy: | 45 | strategy: |
| 45 | fail-fast: false | 46 | fail-fast: false |
| 46 | matrix: | 47 | matrix: |
| @@ -51,6 +52,11 @@ jobs: | @@ -51,6 +52,11 @@ jobs: | ||
| 51 | with: | 52 | with: |
| 52 | fetch-depth: 0 | 53 | fetch-depth: 0 |
| 53 | 54 | ||
| 55 | + - name: ccache | ||
| 56 | + uses: hendrikmuhs/ccache-action@v1.2 | ||
| 57 | + with: | ||
| 58 | + key: ${{ matrix.os }}-aarch64-shared | ||
| 59 | + | ||
| 54 | - name: cache-qemu | 60 | - name: cache-qemu |
| 55 | id: cache-qemu | 61 | id: cache-qemu |
| 56 | uses: actions/cache@v3 | 62 | uses: actions/cache@v3 |
| @@ -114,6 +120,13 @@ jobs: | @@ -114,6 +120,13 @@ jobs: | ||
| 114 | run: | | 120 | run: | |
| 115 | export PATH=$GITHUB_WORKSPACE/toolchain/bin:$PATH | 121 | export PATH=$GITHUB_WORKSPACE/toolchain/bin:$PATH |
| 116 | 122 | ||
| 123 | + export CMAKE_CXX_COMPILER_LAUNCHER=ccache | ||
| 124 | + export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" | ||
| 125 | + | ||
| 126 | + cmake --version | ||
| 127 | + | ||
| 128 | + export BUILD_SHARED_LIBS=ON | ||
| 129 | + | ||
| 117 | ./build-aarch64-linux-gnu.sh | 130 | ./build-aarch64-linux-gnu.sh |
| 118 | 131 | ||
| 119 | ls -lh build-aarch64-linux-gnu/bin | 132 | ls -lh build-aarch64-linux-gnu/bin |
| @@ -132,12 +145,14 @@ jobs: | @@ -132,12 +145,14 @@ jobs: | ||
| 132 | 145 | ||
| 133 | qemu-aarch64 ./build-aarch64-linux-gnu/bin/sherpa-onnx --help | 146 | qemu-aarch64 ./build-aarch64-linux-gnu/bin/sherpa-onnx --help |
| 134 | 147 | ||
| 148 | + readelf -d ./build-aarch64-linux-gnu/bin/sherpa-onnx | ||
| 149 | + | ||
| 135 | - name: Copy files | 150 | - name: Copy files |
| 136 | shell: bash | 151 | shell: bash |
| 137 | run: | | 152 | run: | |
| 138 | SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) | 153 | SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) |
| 139 | 154 | ||
| 140 | - dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-linux-aarch64 | 155 | + dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-linux-aarch64-shared |
| 141 | mkdir $dst | 156 | mkdir $dst |
| 142 | 157 | ||
| 143 | cp -a build-aarch64-linux-gnu/install/bin $dst/ | 158 | cp -a build-aarch64-linux-gnu/install/bin $dst/ |
| @@ -149,7 +164,8 @@ jobs: | @@ -149,7 +164,8 @@ jobs: | ||
| 149 | 164 | ||
| 150 | - uses: actions/upload-artifact@v3 | 165 | - uses: actions/upload-artifact@v3 |
| 151 | with: | 166 | with: |
| 152 | - path: sherpa-onnx-*linux-aarch64.tar.bz2 | 167 | + name: sherpa-onnx-linux-aarch64-shared |
| 168 | + path: sherpa-onnx-*linux-aarch64-shared.tar.bz2 | ||
| 153 | 169 | ||
| 154 | - name: Release pre-compiled binaries and libs for aarch64 linux | 170 | - name: Release pre-compiled binaries and libs for aarch64 linux |
| 155 | if: env.RELEASE == 'true' | 171 | if: env.RELEASE == 'true' |
| @@ -157,4 +173,4 @@ jobs: | @@ -157,4 +173,4 @@ jobs: | ||
| 157 | with: | 173 | with: |
| 158 | file_glob: true | 174 | file_glob: true |
| 159 | overwrite: true | 175 | overwrite: true |
| 160 | - file: sherpa-onnx-*linux-aarch64.tar.bz2 | 176 | + file: sherpa-onnx-*linux-aarch64*.tar.bz2 |
| 1 | +# Modified from https://github.com/Tencent/ncnn/blob/master/.github/workflows/linux-arm-cpu-gcc.yml | ||
| 2 | +name: aarch64-linux-gnu-static | ||
| 3 | + | ||
| 4 | +on: | ||
| 5 | + push: | ||
| 6 | + branches: | ||
| 7 | + - master | ||
| 8 | + tags: | ||
| 9 | + - '*' | ||
| 10 | + paths: | ||
| 11 | + - '.github/workflows/aarch64-linux-gnu-static.yaml' | ||
| 12 | + - 'CMakeLists.txt' | ||
| 13 | + - 'cmake/**' | ||
| 14 | + - 'sherpa-onnx/csrc/*' | ||
| 15 | + - 'toolchains/aarch64-linux-gnu.toolchain.cmake' | ||
| 16 | + pull_request: | ||
| 17 | + branches: | ||
| 18 | + - master | ||
| 19 | + paths: | ||
| 20 | + - '.github/workflows/aarch64-linux-gnu-static.yaml' | ||
| 21 | + - 'CMakeLists.txt' | ||
| 22 | + - 'cmake/**' | ||
| 23 | + - 'sherpa-onnx/csrc/*' | ||
| 24 | + - 'toolchains/aarch64-linux-gnu.toolchain.cmake' | ||
| 25 | + | ||
| 26 | + workflow_dispatch: | ||
| 27 | + inputs: | ||
| 28 | + release: | ||
| 29 | + description: "Whether to release" | ||
| 30 | + type: boolean | ||
| 31 | + | ||
| 32 | +env: | ||
| 33 | + RELEASE: | ||
| 34 | + |- # Release if there is a release tag name or a release flag in workflow_dispatch | ||
| 35 | + ${{ github.event.release.tag_name != '' || github.event.inputs.release == 'true' }} | ||
| 36 | + | ||
| 37 | +concurrency: | ||
| 38 | + group: aarch64-linux-gnu-static-${{ github.ref }} | ||
| 39 | + cancel-in-progress: true | ||
| 40 | + | ||
| 41 | +jobs: | ||
| 42 | + aarch64_linux_gnu_static: | ||
| 43 | + runs-on: ${{ matrix.os }} | ||
| 44 | + name: aarch64 static lib test | ||
| 45 | + strategy: | ||
| 46 | + fail-fast: false | ||
| 47 | + matrix: | ||
| 48 | + os: [ubuntu-latest] | ||
| 49 | + | ||
| 50 | + steps: | ||
| 51 | + - uses: actions/checkout@v4 | ||
| 52 | + with: | ||
| 53 | + fetch-depth: 0 | ||
| 54 | + | ||
| 55 | + - name: ccache | ||
| 56 | + uses: hendrikmuhs/ccache-action@v1.2 | ||
| 57 | + with: | ||
| 58 | + key: ${{ matrix.os }}-aarch64-static | ||
| 59 | + | ||
| 60 | + - name: cache-qemu | ||
| 61 | + id: cache-qemu | ||
| 62 | + uses: actions/cache@v3 | ||
| 63 | + with: | ||
| 64 | + path: qemu-install | ||
| 65 | + key: qemu-aarch64-install-20220908 | ||
| 66 | + | ||
| 67 | + - name: install-qemu-build-deps | ||
| 68 | + if: steps.cache-qemu.outputs.cache-hit != 'true' | ||
| 69 | + run: | | ||
| 70 | + sudo apt-get update | ||
| 71 | + sudo apt-get install autoconf automake autotools-dev ninja-build | ||
| 72 | + | ||
| 73 | + - name: checkout-qemu | ||
| 74 | + if: steps.cache-qemu.outputs.cache-hit != 'true' | ||
| 75 | + uses: actions/checkout@v3 | ||
| 76 | + with: | ||
| 77 | + repository: qemu/qemu | ||
| 78 | + path: qemu | ||
| 79 | + ref: f5643914a9e8f79c606a76e6a9d7ea82a3fc3e65 | ||
| 80 | + | ||
| 81 | + - name: qemu | ||
| 82 | + if: steps.cache-qemu.outputs.cache-hit != 'true' | ||
| 83 | + run: | | ||
| 84 | + cd qemu | ||
| 85 | + ./configure --prefix=$GITHUB_WORKSPACE/qemu-install --target-list=aarch64-linux-user --disable-system | ||
| 86 | + make -j2 | ||
| 87 | + make install | ||
| 88 | + | ||
| 89 | + - name: cache-toolchain | ||
| 90 | + id: cache-toolchain | ||
| 91 | + uses: actions/cache@v3 | ||
| 92 | + with: | ||
| 93 | + path: toolchain | ||
| 94 | + key: gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz | ||
| 95 | + | ||
| 96 | + - name: Download toolchain | ||
| 97 | + if: steps.cache-toolchain.outputs.cache-hit != 'true' | ||
| 98 | + shell: bash | ||
| 99 | + run: | | ||
| 100 | + # wget wget https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz | ||
| 101 | + wget -qq https://huggingface.co/csukuangfj/sherpa-ncnn-toolchains/resolve/main/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz | ||
| 102 | + | ||
| 103 | + mkdir $GITHUB_WORKSPACE/toolchain | ||
| 104 | + tar xf ./gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz --strip-components 1 -C $GITHUB_WORKSPACE/toolchain | ||
| 105 | + | ||
| 106 | + - name: Display toolchain info | ||
| 107 | + shell: bash | ||
| 108 | + run: | | ||
| 109 | + export PATH=$GITHUB_WORKSPACE/toolchain/bin:$PATH | ||
| 110 | + aarch64-none-linux-gnu-gcc --version | ||
| 111 | + | ||
| 112 | + - name: Display qemu-aarch64 -h | ||
| 113 | + shell: bash | ||
| 114 | + run: | | ||
| 115 | + export PATH=$GITHUB_WORKSPACE/qemu-install/bin:$PATH | ||
| 116 | + export QEMU_LD_PREFIX=$GITHUB_WORKSPACE/toolchain/aarch64-none-linux-gnu/libc | ||
| 117 | + qemu-aarch64 -h | ||
| 118 | + | ||
| 119 | + - name: build aarch64-linux-gnu | ||
| 120 | + shell: bash | ||
| 121 | + run: | | ||
| 122 | + export PATH=$GITHUB_WORKSPACE/toolchain/bin:$PATH | ||
| 123 | + | ||
| 124 | + export CMAKE_CXX_COMPILER_LAUNCHER=ccache | ||
| 125 | + export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" | ||
| 126 | + | ||
| 127 | + cmake --version | ||
| 128 | + | ||
| 129 | + export BUILD_SHARED_LIBS=OFF | ||
| 130 | + | ||
| 131 | + ./build-aarch64-linux-gnu.sh | ||
| 132 | + | ||
| 133 | + ls -lh build-aarch64-linux-gnu/bin | ||
| 134 | + ls -lh build-aarch64-linux-gnu/lib | ||
| 135 | + | ||
| 136 | + file build-aarch64-linux-gnu/bin/sherpa-onnx | ||
| 137 | + | ||
| 138 | + - name: Test sherpa-onnx | ||
| 139 | + shell: bash | ||
| 140 | + run: | | ||
| 141 | + export PATH=$GITHUB_WORKSPACE/toolchain/bin:$PATH | ||
| 142 | + export PATH=$GITHUB_WORKSPACE/qemu-install/bin:$PATH | ||
| 143 | + export QEMU_LD_PREFIX=$GITHUB_WORKSPACE/toolchain/aarch64-none-linux-gnu/libc | ||
| 144 | + | ||
| 145 | + ls -lh ./build-aarch64-linux-gnu/bin | ||
| 146 | + | ||
| 147 | + qemu-aarch64 ./build-aarch64-linux-gnu/bin/sherpa-onnx --help | ||
| 148 | + | ||
| 149 | + readelf -d ./build-aarch64-linux-gnu/bin/sherpa-onnx | ||
| 150 | + | ||
| 151 | + - name: Copy files | ||
| 152 | + shell: bash | ||
| 153 | + run: | | ||
| 154 | + SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) | ||
| 155 | + | ||
| 156 | + dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-linux-aarch64-static | ||
| 157 | + mkdir $dst | ||
| 158 | + | ||
| 159 | + cp -a build-aarch64-linux-gnu/install/bin $dst/ | ||
| 160 | + cp -a build-aarch64-linux-gnu/install/lib $dst/ | ||
| 161 | + | ||
| 162 | + tree $dst | ||
| 163 | + | ||
| 164 | + tar cjvf ${dst}.tar.bz2 $dst | ||
| 165 | + | ||
| 166 | + - uses: actions/upload-artifact@v3 | ||
| 167 | + with: | ||
| 168 | + name: sherpa-onnx-linux-aarch64-static | ||
| 169 | + path: sherpa-onnx-*linux-aarch64-static.tar.bz2 | ||
| 170 | + | ||
| 171 | + - name: Release pre-compiled binaries and libs for aarch64 linux | ||
| 172 | + if: env.RELEASE == 'true' | ||
| 173 | + uses: svenstaro/upload-release-action@v2 | ||
| 174 | + with: | ||
| 175 | + file_glob: true | ||
| 176 | + overwrite: true | ||
| 177 | + file: sherpa-onnx-*linux-aarch64*.tar.bz2 |
| 1 | #!/usr/bin/env bash | 1 | #!/usr/bin/env bash |
| 2 | 2 | ||
| 3 | +if command -v aarch64-none-linux-gnu-gcc &> /dev/null; then | ||
| 4 | + ln -svf $(which aarch64-none-linux-gnu-gcc) ./aarch64-linux-gnu-gcc | ||
| 5 | + ln -svf $(which aarch64-none-linux-gnu-g++) ./aarch64-linux-gnu-g++ | ||
| 6 | + export PATH=$PWD:$PATH | ||
| 7 | +fi | ||
| 8 | + | ||
| 3 | if ! command -v aarch64-linux-gnu-gcc &> /dev/null; then | 9 | if ! command -v aarch64-linux-gnu-gcc &> /dev/null; then |
| 4 | echo "Please install a toolchain for cross-compiling." | 10 | echo "Please install a toolchain for cross-compiling." |
| 5 | echo "You can refer to: " | 11 | echo "You can refer to: " |
| @@ -33,10 +39,15 @@ fi | @@ -33,10 +39,15 @@ fi | ||
| 33 | export CPLUS_INCLUDE_PATH=$PWD/alsa-lib/include:$CPLUS_INCLUDE_PATH | 39 | export CPLUS_INCLUDE_PATH=$PWD/alsa-lib/include:$CPLUS_INCLUDE_PATH |
| 34 | export SHERPA_ONNX_ALSA_LIB_DIR=$PWD/alsa-lib/src/.libs | 40 | export SHERPA_ONNX_ALSA_LIB_DIR=$PWD/alsa-lib/src/.libs |
| 35 | 41 | ||
| 42 | +if [[ x"$BUILD_SHARED_LIBS" == x"" ]]; then | ||
| 43 | + # By default, use static link | ||
| 44 | + BUILD_SHARED_LIBS=OFF | ||
| 45 | +fi | ||
| 46 | + | ||
| 36 | cmake \ | 47 | cmake \ |
| 37 | -DCMAKE_INSTALL_PREFIX=./install \ | 48 | -DCMAKE_INSTALL_PREFIX=./install \ |
| 38 | -DCMAKE_BUILD_TYPE=Release \ | 49 | -DCMAKE_BUILD_TYPE=Release \ |
| 39 | - -DBUILD_SHARED_LIBS=OFF \ | 50 | + -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS \ |
| 40 | -DSHERPA_ONNX_ENABLE_TESTS=OFF \ | 51 | -DSHERPA_ONNX_ENABLE_TESTS=OFF \ |
| 41 | -DSHERPA_ONNX_ENABLE_PYTHON=OFF \ | 52 | -DSHERPA_ONNX_ENABLE_PYTHON=OFF \ |
| 42 | -DSHERPA_ONNX_ENABLE_CHECK=OFF \ | 53 | -DSHERPA_ONNX_ENABLE_CHECK=OFF \ |
cmake/onnxruntime-linux-aarch64-static.cmake
0 → 100644
| 1 | +# Copyright (c) 2022-2023 Xiaomi Corporation | ||
| 2 | +message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}") | ||
| 3 | +message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}") | ||
| 4 | + | ||
| 5 | +if(NOT CMAKE_SYSTEM_NAME STREQUAL Linux) | ||
| 6 | + message(FATAL_ERROR "This file is for Linux only. Given: ${CMAKE_SYSTEM_NAME}") | ||
| 7 | +endif() | ||
| 8 | + | ||
| 9 | +if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) | ||
| 10 | + message(FATAL_ERROR "This file is for aarch64 only. Given: ${CMAKE_SYSTEM_PROCESSOR}") | ||
| 11 | +endif() | ||
| 12 | + | ||
| 13 | +if(BUILD_SHARED_LIBS) | ||
| 14 | + message(FATAL_ERROR "This file is for building static libraries. BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}") | ||
| 15 | +endif() | ||
| 16 | + | ||
| 17 | +set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.16.0/onnxruntime-linux-aarch64-static_lib-1.16.0.zip") | ||
| 18 | +set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/onnxruntime-libs/resolve/main/onnxruntime-linux-aarch64-static_lib-1.16.0.zip") | ||
| 19 | +set(onnxruntime_HASH "SHA256=ddcb4e67bcdff53eb72265a12420c71f73acc8610054e06259e9b98770136bd5") | ||
| 20 | + | ||
| 21 | +# If you don't have access to the Internet, | ||
| 22 | +# please download onnxruntime to one of the following locations. | ||
| 23 | +# You can add more if you want. | ||
| 24 | +set(possible_file_locations | ||
| 25 | + $ENV{HOME}/Downloads/onnxruntime-linux-aarch64-static_lib-1.16.0.zip | ||
| 26 | + ${PROJECT_SOURCE_DIR}/onnxruntime-linux-aarch64-static_lib-1.16.0.zip | ||
| 27 | + ${PROJECT_BINARY_DIR}/onnxruntime-linux-aarch64-static_lib-1.16.0.zip | ||
| 28 | + /tmp/onnxruntime-linux-aarch64-static_lib-1.16.0.zip | ||
| 29 | + /star-fj/fangjun/download/github/onnxruntime-linux-aarch64-static_lib-1.16.0.zip | ||
| 30 | +) | ||
| 31 | + | ||
| 32 | +foreach(f IN LISTS possible_file_locations) | ||
| 33 | + if(EXISTS ${f}) | ||
| 34 | + set(onnxruntime_URL "${f}") | ||
| 35 | + file(TO_CMAKE_PATH "${onnxruntime_URL}" onnxruntime_URL) | ||
| 36 | + message(STATUS "Found local downloaded onnxruntime: ${onnxruntime_URL}") | ||
| 37 | + set(onnxruntime_URL2) | ||
| 38 | + break() | ||
| 39 | + endif() | ||
| 40 | +endforeach() | ||
| 41 | + | ||
| 42 | +FetchContent_Declare(onnxruntime | ||
| 43 | + URL | ||
| 44 | + ${onnxruntime_URL} | ||
| 45 | + ${onnxruntime_URL2} | ||
| 46 | + URL_HASH ${onnxruntime_HASH} | ||
| 47 | +) | ||
| 48 | + | ||
| 49 | +FetchContent_GetProperties(onnxruntime) | ||
| 50 | +if(NOT onnxruntime_POPULATED) | ||
| 51 | + message(STATUS "Downloading onnxruntime from ${onnxruntime_URL}") | ||
| 52 | + FetchContent_Populate(onnxruntime) | ||
| 53 | +endif() | ||
| 54 | +message(STATUS "onnxruntime is downloaded to ${onnxruntime_SOURCE_DIR}") | ||
| 55 | + | ||
| 56 | +# for static libraries, we use onnxruntime_lib_files directly below | ||
| 57 | +include_directories(${onnxruntime_SOURCE_DIR}/include) | ||
| 58 | + | ||
| 59 | +file(GLOB onnxruntime_lib_files "${onnxruntime_SOURCE_DIR}/lib/lib*.a") | ||
| 60 | + | ||
| 61 | +set(onnxruntime_lib_files ${onnxruntime_lib_files} PARENT_SCOPE) | ||
| 62 | + | ||
| 63 | +message(STATUS "onnxruntime lib files: ${onnxruntime_lib_files}") | ||
| 64 | +install(FILES ${onnxruntime_lib_files} DESTINATION lib) |
| @@ -10,6 +10,10 @@ if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) | @@ -10,6 +10,10 @@ if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) | ||
| 10 | message(FATAL_ERROR "This file is for aarch64 only. Given: ${CMAKE_SYSTEM_PROCESSOR}") | 10 | message(FATAL_ERROR "This file is for aarch64 only. Given: ${CMAKE_SYSTEM_PROCESSOR}") |
| 11 | endif() | 11 | endif() |
| 12 | 12 | ||
| 13 | +if(NOT BUILD_SHARED_LIBS) | ||
| 14 | + message(FATAL_ERROR "This file is for building shared libraries. BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}") | ||
| 15 | +endif() | ||
| 16 | + | ||
| 13 | set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.16.0/onnxruntime-linux-aarch64-1.16.0.tgz") | 17 | set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.16.0/onnxruntime-linux-aarch64-1.16.0.tgz") |
| 14 | set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/sherpa-onnx-cmake-deps/resolve/main/onnxruntime-linux-aarch64-1.16.0.tgz") | 18 | set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/sherpa-onnx-cmake-deps/resolve/main/onnxruntime-linux-aarch64-1.16.0.tgz") |
| 15 | set(onnxruntime_HASH "SHA256=8b15781d974803203c09df7d52c84d8c9f1ac7d949a97f515e4d2f5dc978d8af") | 19 | set(onnxruntime_HASH "SHA256=8b15781d974803203c09df7d52c84d8c9f1ac7d949a97f515e4d2f5dc978d8af") |
| @@ -53,14 +53,6 @@ if(NOT onnxruntime_POPULATED) | @@ -53,14 +53,6 @@ if(NOT onnxruntime_POPULATED) | ||
| 53 | endif() | 53 | endif() |
| 54 | message(STATUS "onnxruntime is downloaded to ${onnxruntime_SOURCE_DIR}") | 54 | message(STATUS "onnxruntime is downloaded to ${onnxruntime_SOURCE_DIR}") |
| 55 | 55 | ||
| 56 | -find_library(location_onnxruntime onnxruntime | ||
| 57 | - PATHS | ||
| 58 | - "${onnxruntime_SOURCE_DIR}/lib" | ||
| 59 | - NO_CMAKE_SYSTEM_PATH | ||
| 60 | -) | ||
| 61 | - | ||
| 62 | -message(STATUS "location_onnxruntime: ${location_onnxruntime}") | ||
| 63 | - | ||
| 64 | # for static libraries, we use onnxruntime_lib_files directly below | 56 | # for static libraries, we use onnxruntime_lib_files directly below |
| 65 | include_directories(${onnxruntime_SOURCE_DIR}/include) | 57 | include_directories(${onnxruntime_SOURCE_DIR}/include) |
| 66 | 58 |
| @@ -10,6 +10,10 @@ if(NOT (CMAKE_SYSTEM_PROCESSOR STREQUAL arm OR CMAKE_SYSTEM_PROCESSOR STREQUAL a | @@ -10,6 +10,10 @@ if(NOT (CMAKE_SYSTEM_PROCESSOR STREQUAL arm OR CMAKE_SYSTEM_PROCESSOR STREQUAL a | ||
| 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 | ||
| 13 | +if(NOT BUILD_SHARED_LIBS) | ||
| 14 | + message(FATAL_ERROR "This file is for building shared libraries. BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}") | ||
| 15 | +endif() | ||
| 16 | + | ||
| 13 | set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.16.0/onnxruntime-linux-arm-1.16.0.zip") | 17 | set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.16.0/onnxruntime-linux-arm-1.16.0.zip") |
| 14 | set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/onnxruntime-libs/resolve/main/onnxruntime-linux-arm-1.16.0.zip") | 18 | set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/onnxruntime-libs/resolve/main/onnxruntime-linux-arm-1.16.0.zip") |
| 15 | set(onnxruntime_HASH "SHA256=0a63ea99fbba3ee399d6626c36752844ae93ae19bab30e4bf00d45cc8a13da02") | 19 | set(onnxruntime_HASH "SHA256=0a63ea99fbba3ee399d6626c36752844ae93ae19bab30e4bf00d45cc8a13da02") |
| @@ -6,7 +6,11 @@ function(download_onnxruntime) | @@ -6,7 +6,11 @@ function(download_onnxruntime) | ||
| 6 | message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}") | 6 | message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}") |
| 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 | + if(BUILD_SHARED_LIBS) |
| 10 | + include(onnxruntime-linux-aarch64) | ||
| 11 | + else() | ||
| 12 | + include(onnxruntime-linux-aarch64-static) | ||
| 13 | + endif() | ||
| 10 | elseif(CMAKE_SYSTEM_NAME STREQUAL Linux AND (CMAKE_SYSTEM_PROCESSOR STREQUAL arm OR CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l)) | 14 | elseif(CMAKE_SYSTEM_NAME STREQUAL Linux AND (CMAKE_SYSTEM_PROCESSOR STREQUAL arm OR CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l)) |
| 11 | if(BUILD_SHARED_LIBS) | 15 | if(BUILD_SHARED_LIBS) |
| 12 | include(onnxruntime-linux-arm) | 16 | include(onnxruntime-linux-arm) |
| @@ -113,7 +113,7 @@ target_link_libraries(sherpa-onnx-core kaldi-native-fbank-core) | @@ -113,7 +113,7 @@ target_link_libraries(sherpa-onnx-core kaldi-native-fbank-core) | ||
| 113 | 113 | ||
| 114 | target_link_libraries(sherpa-onnx-core kaldi-decoder-core) | 114 | target_link_libraries(sherpa-onnx-core kaldi-decoder-core) |
| 115 | 115 | ||
| 116 | -if(BUILD_SHARED_LIBS OR APPLE OR CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) | 116 | +if(BUILD_SHARED_LIBS OR APPLE) |
| 117 | target_link_libraries(sherpa-onnx-core onnxruntime) | 117 | target_link_libraries(sherpa-onnx-core onnxruntime) |
| 118 | else() | 118 | else() |
| 119 | target_link_libraries(sherpa-onnx-core ${onnxruntime_lib_files}) | 119 | target_link_libraries(sherpa-onnx-core ${onnxruntime_lib_files}) |
-
请 注册 或 登录 后发表评论