Fangjun Kuang
Committed by GitHub

Support static build for windows arm64. (#1539)

@@ -34,7 +34,7 @@ jobs: @@ -34,7 +34,7 @@ jobs:
34 fail-fast: false 34 fail-fast: false
35 matrix: 35 matrix:
36 os: [windows-latest] 36 os: [windows-latest]
37 - shared_lib: [ON] 37 + shared_lib: [ON, OFF]
38 with_tts: [ON, OFF] 38 with_tts: [ON, OFF]
39 39
40 steps: 40 steps:
  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 +message(STATUS "CMAKE_VS_PLATFORM_NAME: ${CMAKE_VS_PLATFORM_NAME}")
  5 +
  6 +if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
  7 + message(FATAL_ERROR "This file is for Windows only. Given: ${CMAKE_SYSTEM_NAME}")
  8 +endif()
  9 +
  10 +if(NOT (CMAKE_VS_PLATFORM_NAME STREQUAL ARM64 OR CMAKE_VS_PLATFORM_NAME STREQUAL arm64))
  11 + message(FATAL_ERROR "This file is for Windows arm64 only. Given: ${CMAKE_VS_PLATFORM_NAME}")
  12 +endif()
  13 +
  14 +if(BUILD_SHARED_LIBS)
  15 + message(FATAL_ERROR "This file is for building static libraries. BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}")
  16 +endif()
  17 +
  18 +if(NOT CMAKE_BUILD_TYPE STREQUAL Release)
  19 + message(FATAL_ERROR "This file is for building a release version on Windows arm64")
  20 +endif()
  21 +
  22 +set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.17.1/onnxruntime-win-arm64-static_lib-1.17.1.tar.bz2")
  23 +set(onnxruntime_URL2 "https://hf-mirror.com/csukuangfj/onnxruntime-libs/resolve/main/onnxruntime-win-arm64-static_lib-1.17.1.tar.bz2")
  24 +set(onnxruntime_HASH "SHA256=534ab5bb8b5495ce45fed866cf3ec9034f89f2057a0152e49120b1088003a17e")
  25 +
  26 +# If you don't have access to the Internet,
  27 +# please download onnxruntime to one of the following locations.
  28 +# You can add more if you want.
  29 +set(possible_file_locations
  30 + $ENV{HOME}/Downloads/onnxruntime-win-arm64-static_lib-1.17.1.tar.bz2
  31 + ${CMAKE_SOURCE_DIR}/onnxruntime-win-arm64-static_lib-1.17.1.tar.bz2
  32 + ${CMAKE_BINARY_DIR}/onnxruntime-win-arm64-static_lib-1.17.1.tar.bz2
  33 + /tmp/onnxruntime-win-arm64-static_lib-1.17.1.tar.bz2
  34 +)
  35 +
  36 +foreach(f IN LISTS possible_file_locations)
  37 + if(EXISTS ${f})
  38 + set(onnxruntime_URL "${f}")
  39 + file(TO_CMAKE_PATH "${onnxruntime_URL}" onnxruntime_URL)
  40 + message(STATUS "Found local downloaded onnxruntime: ${onnxruntime_URL}")
  41 + set(onnxruntime_URL2)
  42 + break()
  43 + endif()
  44 +endforeach()
  45 +
  46 +FetchContent_Declare(onnxruntime
  47 + URL
  48 + ${onnxruntime_URL}
  49 + ${onnxruntime_URL2}
  50 + URL_HASH ${onnxruntime_HASH}
  51 +)
  52 +
  53 +FetchContent_GetProperties(onnxruntime)
  54 +if(NOT onnxruntime_POPULATED)
  55 + message(STATUS "Downloading onnxruntime from ${onnxruntime_URL}")
  56 + FetchContent_Populate(onnxruntime)
  57 +endif()
  58 +message(STATUS "onnxruntime is downloaded to ${onnxruntime_SOURCE_DIR}")
  59 +
  60 +# for static libraries, we use onnxruntime_lib_files directly below
  61 +include_directories(${onnxruntime_SOURCE_DIR}/include)
  62 +
  63 +file(GLOB onnxruntime_lib_files "${onnxruntime_SOURCE_DIR}/lib/*.lib")
  64 +
  65 +set(onnxruntime_lib_files ${onnxruntime_lib_files} PARENT_SCOPE)
  66 +
  67 +message(STATUS "onnxruntime lib files: ${onnxruntime_lib_files}")
  68 +if(SHERPA_ONNX_ENABLE_PYTHON)
  69 + install(FILES ${onnxruntime_lib_files} DESTINATION ..)
  70 +else()
  71 + install(FILES ${onnxruntime_lib_files} DESTINATION lib)
  72 +endif()
@@ -91,11 +91,12 @@ function(download_onnxruntime) @@ -91,11 +91,12 @@ function(download_onnxruntime)
91 endif() 91 endif()
92 elseif(CMAKE_VS_PLATFORM_NAME STREQUAL ARM64 OR CMAKE_VS_PLATFORM_NAME STREQUAL arm64) 92 elseif(CMAKE_VS_PLATFORM_NAME STREQUAL ARM64 OR CMAKE_VS_PLATFORM_NAME STREQUAL arm64)
93 # for 64-bit windows (arm64) 93 # for 64-bit windows (arm64)
94 - if(NOT BUILD_SHARED_LIBS)  
95 - message(FATAL_ERROR "Please pass -DBUILD_SHARED_LIBS=ON to cmake")  
96 - endif() 94 + if(BUILD_SHARED_LIBS)
97 include(onnxruntime-win-arm64) 95 include(onnxruntime-win-arm64)
98 else() 96 else()
  97 + include(onnxruntime-win-arm64-static)
  98 + endif()
  99 + else()
99 # for 64-bit windows (x64) 100 # for 64-bit windows (x64)
100 if(SHERPA_ONNX_ENABLE_DIRECTML) 101 if(SHERPA_ONNX_ENABLE_DIRECTML)
101 message(STATUS "Use DirectML") 102 message(STATUS "Use DirectML")