Fangjun Kuang
Committed by GitHub

Support Windows arm64 (#911)

  1 +name: windows-arm64
  2 +
  3 +on:
  4 + push:
  5 + branches:
  6 + - master
  7 + tags:
  8 + - '*'
  9 + paths:
  10 + - '.github/workflows/windows-arm64.yaml'
  11 + - 'CMakeLists.txt'
  12 + - 'cmake/**'
  13 + - 'sherpa-onnx/csrc/*'
  14 + pull_request:
  15 + branches:
  16 + - master
  17 + paths:
  18 + - '.github/workflows/windows-arm64.yaml'
  19 + - 'CMakeLists.txt'
  20 + - 'cmake/**'
  21 + - 'sherpa-onnx/csrc/*'
  22 +
  23 + workflow_dispatch:
  24 +
  25 +concurrency:
  26 + group: windows-arm64-${{ github.ref }}
  27 + cancel-in-progress: true
  28 +
  29 +jobs:
  30 + windows_arm64:
  31 + name: shared-${{ matrix.shared_lib }} tts-${{ matrix.with_tts }}
  32 + runs-on: ${{ matrix.os }}
  33 + strategy:
  34 + fail-fast: false
  35 + matrix:
  36 + os: [windows-latest]
  37 + shared_lib: [ON]
  38 + with_tts: [ON, OFF]
  39 +
  40 + steps:
  41 + - uses: actions/checkout@v4
  42 + with:
  43 + fetch-depth: 0
  44 +
  45 + - name: Configure CMake
  46 + shell: bash
  47 + run: |
  48 + mkdir build
  49 + cd build
  50 + cmake -A ARM64 -DSHERPA_ONNX_ENABLE_TTS=${{ matrix.with_tts }} -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} -DCMAKE_INSTALL_PREFIX=./install -DBUILD_ESPEAK_NG_EXE=OFF ..
  51 +
  52 + - name: Build sherpa-onnx for windows
  53 + shell: bash
  54 + run: |
  55 + cd build
  56 + cmake --build . --config Release -- -m:2
  57 + cmake --build . --config Release --target install -- -m:2
  58 +
  59 + ls -lh ./bin/Release/sherpa-onnx.exe
  1 +# Copyright (c) 2022-2024 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(NOT BUILD_SHARED_LIBS)
  15 + message(FATAL_ERROR "This file is for building shared libraries. BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}")
  16 +endif()
  17 +
  18 +set(onnxruntime_URL "https://github.com/microsoft/onnxruntime/releases/download/v1.17.1/onnxruntime-win-arm64-1.17.1.zip")
  19 +set(onnxruntime_URL2 "https://hub.nuaa.cf/microsoft/onnxruntime/releases/download/v1.17.1/onnxruntime-win-arm64-1.17.1.zip")
  20 +set(onnxruntime_HASH "SHA256=47782cebcab0fd7a1f0a3f0676b088c1bc0f4fbf21666f6fe57570dc362fa5a8")
  21 +
  22 +# If you don't have access to the Internet,
  23 +# please download onnxruntime to one of the following locations.
  24 +# You can add more if you want.
  25 +set(possible_file_locations
  26 + $ENV{HOME}/Downloads/onnxruntime-win-arm64-1.17.1.zip
  27 + ${CMAKE_SOURCE_DIR}/onnxruntime-win-arm64-1.17.1.zip
  28 + ${CMAKE_BINARY_DIR}/onnxruntime-win-arm64-1.17.1.zip
  29 + /tmp/onnxruntime-win-arm64-1.17.1.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 +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 +add_library(onnxruntime SHARED IMPORTED)
  65 +
  66 +set_target_properties(onnxruntime PROPERTIES
  67 + IMPORTED_LOCATION ${location_onnxruntime}
  68 + INTERFACE_INCLUDE_DIRECTORIES "${onnxruntime_SOURCE_DIR}/include"
  69 +)
  70 +
  71 +set_property(TARGET onnxruntime
  72 + PROPERTY
  73 + IMPORTED_IMPLIB "${onnxruntime_SOURCE_DIR}/lib/onnxruntime.lib"
  74 +)
  75 +
  76 +file(COPY ${onnxruntime_SOURCE_DIR}/lib/onnxruntime.dll
  77 + DESTINATION
  78 + ${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}
  79 +)
  80 +
  81 +file(GLOB onnxruntime_lib_files "${onnxruntime_SOURCE_DIR}/lib/*.dll")
  82 +
  83 +message(STATUS "onnxruntime lib files: ${onnxruntime_lib_files}")
  84 +
  85 +if(SHERPA_ONNX_ENABLE_PYTHON)
  86 + install(FILES ${onnxruntime_lib_files} DESTINATION ..)
  87 +else()
  88 + install(FILES ${onnxruntime_lib_files} DESTINATION lib)
  89 +endif()
  90 +
  91 +install(FILES ${onnxruntime_lib_files} DESTINATION bin)
@@ -87,9 +87,14 @@ function(download_onnxruntime) @@ -87,9 +87,14 @@ function(download_onnxruntime)
87 if(SHERPA_ONNX_ENABLE_GPU) 87 if(SHERPA_ONNX_ENABLE_GPU)
88 message(FATAL_ERROR "GPU support for Win32 is not supported!") 88 message(FATAL_ERROR "GPU support for Win32 is not supported!")
89 endif() 89 endif()
  90 + elseif(CMAKE_VS_PLATFORM_NAME STREQUAL ARM64 OR CMAKE_VS_PLATFORM_NAME STREQUAL arm64)
  91 + # for 64-bit windows (arm64)
  92 + if(NOT BUILD_SHARED_LIBS)
  93 + message(FATAL_ERROR "Please pass -DBUILD_SHARED_LIBS=ON to cmake")
  94 + endif()
  95 + include(onnxruntime-win-arm64)
90 else() 96 else()
91 - # for 64-bit windows  
92 - 97 + # for 64-bit windows (x64)
93 if(BUILD_SHARED_LIBS) 98 if(BUILD_SHARED_LIBS)
94 message(STATUS "Use dynamic onnxruntime libraries") 99 message(STATUS "Use dynamic onnxruntime libraries")
95 if(SHERPA_ONNX_ENABLE_GPU) 100 if(SHERPA_ONNX_ENABLE_GPU)