-
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 linking onnxruntime statically for macOS (#403)
- Loading branch information
1 parent
fabbc70
commit b80b7e5
Showing
9 changed files
with
239 additions
and
10 deletions.
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 |
---|---|---|
|
@@ -39,11 +39,13 @@ concurrency: | |
jobs: | ||
macos: | ||
runs-on: ${{ matrix.os }} | ||
name: ${{ matrix.build_type }} ${{ matrix.lib_type }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [macos-latest] | ||
build_type: [Release, Debug] | ||
lib_type: [static, shared] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
@@ -53,7 +55,7 @@ jobs: | |
- name: ccache | ||
uses: hendrikmuhs/[email protected] | ||
with: | ||
key: ${{ matrix.os }}-${{ matrix.build_type }} | ||
key: ${{ matrix.os }}-${{ matrix.build_type }}-${{ matrix.lib_type }} | ||
|
||
- name: Configure CMake | ||
shell: bash | ||
|
@@ -64,7 +66,14 @@ jobs: | |
mkdir build | ||
cd build | ||
cmake -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_OSX_ARCHITECTURES='arm64;x86_64' -DCMAKE_INSTALL_PREFIX=./install .. | ||
lib_type=${{ matrix.lib_type }} | ||
if [[ $lib_type == "static" ]]; then | ||
BUILD_SHARED_LIBS=OFF | ||
else | ||
BUILD_SHARED_LIBS=ON | ||
fi | ||
cmake -D BUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_OSX_ARCHITECTURES='arm64;x86_64' -DCMAKE_INSTALL_PREFIX=./install .. | ||
- name: Build sherpa-onnx for macos | ||
shell: bash | ||
|
@@ -149,7 +158,7 @@ jobs: | |
run: | | ||
SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) | ||
dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-osx-universal2 | ||
dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-osx-universal2-${{ matrix.lib_type }} | ||
mkdir $dst | ||
cp -a build/install/bin $dst/ | ||
|
@@ -167,4 +176,4 @@ jobs: | |
with: | ||
file_glob: true | ||
overwrite: true | ||
file: sherpa-onnx-*osx-universal2.tar.bz2 | ||
file: sherpa-onnx-*osx-universal2*.tar.bz2 |
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,61 @@ | ||
# Copyright (c) 2022-2023 Xiaomi Corporation | ||
message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}") | ||
message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}") | ||
message(STATUS "CMAKE_OSX_ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}") | ||
message(STATUS "CMAKE_APPLE_SILICON_PROCESSOR : ${CMAKE_APPLE_SILICON_PROCESSOR}") | ||
|
||
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) | ||
message(FATAL_ERROR "This file is for macOS only. Given: ${CMAKE_SYSTEM_NAME}") | ||
endif() | ||
|
||
if(BUILD_SHARED_LIBS) | ||
message(FATAL_ERROR "This file is for building static libraries. BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}") | ||
endif() | ||
|
||
set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.16.0/onnxruntime-osx-arm64-static_lib-1.16.0.zip") | ||
set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/onnxruntime-libs/resolve/main/onnxruntime-osx-arm64-static_lib-1.16.0.zip") | ||
set(onnxruntime_HASH "SHA256=5f99c9a51d91e751ac20fcbb73dfa31a379438381c5357fd3f37bda816934e3e") | ||
|
||
# If you don't have access to the Internet, | ||
# please download onnxruntime to one of the following locations. | ||
# You can add more if you want. | ||
set(possible_file_locations | ||
$ENV{HOME}/Downloads/onnxruntime-osx-arm64-static_lib-1.16.0.zip | ||
${PROJECT_SOURCE_DIR}/onnxruntime-osx-arm64-static_lib-1.16.0.zip | ||
${PROJECT_BINARY_DIR}/onnxruntime-osx-arm64-static_lib-1.16.0.zip | ||
/tmp/onnxruntime-osx-arm64-static_lib-1.16.0.zip | ||
) | ||
|
||
foreach(f IN LISTS possible_file_locations) | ||
if(EXISTS ${f}) | ||
set(onnxruntime_URL "${f}") | ||
file(TO_CMAKE_PATH "${onnxruntime_URL}" onnxruntime_URL) | ||
message(STATUS "Found local downloaded onnxruntime: ${onnxruntime_URL}") | ||
set(onnxruntime_URL2) | ||
break() | ||
endif() | ||
endforeach() | ||
|
||
FetchContent_Declare(onnxruntime | ||
URL | ||
${onnxruntime_URL} | ||
${onnxruntime_URL2} | ||
URL_HASH ${onnxruntime_HASH} | ||
) | ||
|
||
FetchContent_GetProperties(onnxruntime) | ||
if(NOT onnxruntime_POPULATED) | ||
message(STATUS "Downloading onnxruntime from ${onnxruntime_URL}") | ||
FetchContent_Populate(onnxruntime) | ||
endif() | ||
message(STATUS "onnxruntime is downloaded to ${onnxruntime_SOURCE_DIR}") | ||
|
||
# for static libraries, we use onnxruntime_lib_files directly below | ||
include_directories(${onnxruntime_SOURCE_DIR}/include) | ||
|
||
file(GLOB onnxruntime_lib_files "${onnxruntime_SOURCE_DIR}/lib/lib*.a") | ||
|
||
set(onnxruntime_lib_files ${onnxruntime_lib_files} PARENT_SCOPE) | ||
|
||
message(STATUS "onnxruntime lib files: ${onnxruntime_lib_files}") | ||
install(FILES ${onnxruntime_lib_files} DESTINATION lib) |
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,62 @@ | ||
# Possible values for CMAKE_SYSTEM_NAME: Linux, Windows, Darwin | ||
|
||
message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}") | ||
message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}") | ||
message(STATUS "CMAKE_OSX_ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}") | ||
message(STATUS "CMAKE_APPLE_SILICON_PROCESSOR : ${CMAKE_APPLE_SILICON_PROCESSOR}") | ||
|
||
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) | ||
message(FATAL_ERROR "This file is for macOS only. Given: ${CMAKE_SYSTEM_NAME}") | ||
endif() | ||
|
||
if(BUILD_SHARED_LIBS) | ||
message(FATAL_ERROR "This file is for building static libraries. BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}") | ||
endif() | ||
|
||
set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.16.0/onnxruntime-osx-universal2-static_lib-1.16.0.zip") | ||
set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/onnxruntime-libs/resolve/main/onnxruntime-osx-universal2-static_lib-1.16.0.zip") | ||
set(onnxruntime_HASH "SHA256=6df205fb519d311ff57131d35ed43374f4fe483eb665baa38bfbc00034595b35") | ||
|
||
# If you don't have access to the Internet, | ||
# please download onnxruntime to one of the following locations. | ||
# You can add more if you want. | ||
set(possible_file_locations | ||
$ENV{HOME}/Downloads/onnxruntime-osx-universal2-static_lib-1.16.0.zip | ||
${PROJECT_SOURCE_DIR}/onnxruntime-osx-universal2-static_lib-1.16.0.zip | ||
${PROJECT_BINARY_DIR}/onnxruntime-osx-universal2-static_lib-1.16.0.zip | ||
/tmp/onnxruntime-osx-universal2-static_lib-1.16.0.zip | ||
) | ||
|
||
foreach(f IN LISTS possible_file_locations) | ||
if(EXISTS ${f}) | ||
set(onnxruntime_URL "${f}") | ||
file(TO_CMAKE_PATH "${onnxruntime_URL}" onnxruntime_URL) | ||
message(STATUS "Found local downloaded onnxruntime: ${onnxruntime_URL}") | ||
set(onnxruntime_URL2) | ||
break() | ||
endif() | ||
endforeach() | ||
|
||
FetchContent_Declare(onnxruntime | ||
URL | ||
${onnxruntime_URL} | ||
${onnxruntime_URL2} | ||
URL_HASH ${onnxruntime_HASH} | ||
) | ||
|
||
FetchContent_GetProperties(onnxruntime) | ||
if(NOT onnxruntime_POPULATED) | ||
message(STATUS "Downloading onnxruntime from ${onnxruntime_URL}") | ||
FetchContent_Populate(onnxruntime) | ||
endif() | ||
message(STATUS "onnxruntime is downloaded to ${onnxruntime_SOURCE_DIR}") | ||
|
||
# for static libraries, we use onnxruntime_lib_files directly below | ||
include_directories(${onnxruntime_SOURCE_DIR}/include) | ||
|
||
file(GLOB onnxruntime_lib_files "${onnxruntime_SOURCE_DIR}/lib/lib*.a") | ||
|
||
set(onnxruntime_lib_files ${onnxruntime_lib_files} PARENT_SCOPE) | ||
|
||
message(STATUS "onnxruntime lib files: ${onnxruntime_lib_files}") | ||
install(FILES ${onnxruntime_lib_files} DESTINATION lib) |
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,61 @@ | ||
# Copyright (c) 2022-2023 Xiaomi Corporation | ||
message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}") | ||
message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}") | ||
message(STATUS "CMAKE_OSX_ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}") | ||
message(STATUS "CMAKE_APPLE_SILICON_PROCESSOR : ${CMAKE_APPLE_SILICON_PROCESSOR}") | ||
|
||
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) | ||
message(FATAL_ERROR "This file is for macOS only. Given: ${CMAKE_SYSTEM_NAME}") | ||
endif() | ||
|
||
if(BUILD_SHARED_LIBS) | ||
message(FATAL_ERROR "This file is for building static libraries. BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}") | ||
endif() | ||
|
||
set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.16.0/onnxruntime-osx-x86_64-static_lib-1.16.0.zip") | ||
set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/onnxruntime-libs/resolve/main/onnxruntime-osx-x86_64-static_lib-1.16.0.zip") | ||
set(onnxruntime_HASH "SHA256=1686a1b6778483371d29106d8c7300a8960e3db084ab84ac4f870b7685cf5259") | ||
|
||
# If you don't have access to the Internet, | ||
# please download onnxruntime to one of the following locations. | ||
# You can add more if you want. | ||
set(possible_file_locations | ||
$ENV{HOME}/Downloads/onnxruntime-osx-x86_64-static_lib-1.16.0.zip | ||
${PROJECT_SOURCE_DIR}/onnxruntime-osx-x86_64-static_lib-1.16.0.zip | ||
${PROJECT_BINARY_DIR}/onnxruntime-osx-x86_64-static_lib-1.16.0.zip | ||
/tmp/onnxruntime-osx-x86_64-static_lib-1.16.0.zip | ||
) | ||
|
||
foreach(f IN LISTS possible_file_locations) | ||
if(EXISTS ${f}) | ||
set(onnxruntime_URL "${f}") | ||
file(TO_CMAKE_PATH "${onnxruntime_URL}" onnxruntime_URL) | ||
message(STATUS "Found local downloaded onnxruntime: ${onnxruntime_URL}") | ||
set(onnxruntime_URL2) | ||
break() | ||
endif() | ||
endforeach() | ||
|
||
FetchContent_Declare(onnxruntime | ||
URL | ||
${onnxruntime_URL} | ||
${onnxruntime_URL2} | ||
URL_HASH ${onnxruntime_HASH} | ||
) | ||
|
||
FetchContent_GetProperties(onnxruntime) | ||
if(NOT onnxruntime_POPULATED) | ||
message(STATUS "Downloading onnxruntime from ${onnxruntime_URL}") | ||
FetchContent_Populate(onnxruntime) | ||
endif() | ||
message(STATUS "onnxruntime is downloaded to ${onnxruntime_SOURCE_DIR}") | ||
|
||
# for static libraries, we use onnxruntime_lib_files directly below | ||
include_directories(${onnxruntime_SOURCE_DIR}/include) | ||
|
||
file(GLOB onnxruntime_lib_files "${onnxruntime_SOURCE_DIR}/lib/lib*.a") | ||
|
||
set(onnxruntime_lib_files ${onnxruntime_lib_files} PARENT_SCOPE) | ||
|
||
message(STATUS "onnxruntime lib files: ${onnxruntime_lib_files}") | ||
install(FILES ${onnxruntime_lib_files} DESTINATION lib) |
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
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