Skip to content

Commit

Permalink
Support MinSizeRel and RelWithDebInfo build on Windows. (k2-fsa#586)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Feb 20, 2024
1 parent 2e35035 commit 1eeb87a
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 36 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/windows-x64-debug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ concurrency:

jobs:
windows_x64_debug:
name: Windows x64 debug
name: Windows x64 ${{ matrix.build_type }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest]
shared_lib: [OFF]
build_type: [Debug, MinSizeRel, RelWithDebInfo]

steps:
- uses: actions/checkout@v4
Expand All @@ -58,21 +59,21 @@ jobs:
run: |
mkdir build
cd build
cmake -A x64 -D CMAKE_BUILD_TYPE=Debug -D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} -DCMAKE_INSTALL_PREFIX=./install ..
cmake -A x64 -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} -DCMAKE_INSTALL_PREFIX=./install ..
- name: Build sherpa-onnx for windows
shell: bash
run: |
cd build
cmake --build . --config Debug -- -m:2
cmake --build . --config Debug --target install -- -m:2
cmake --build . --config ${{ matrix.build_type }} -- -m:2
cmake --build . --config ${{ matrix.build_type }} --target install -- -m:2
ls -lh ./bin/Debug/sherpa-onnx.exe
ls -lh ./bin/${{ matrix.build_type }}/sherpa-onnx.exe
- name: Test online CTC
shell: bash
run: |
export PATH=$PWD/build/bin/Debug:$PATH
export PATH=$PWD/build/bin/${{ matrix.build_type }}:$PATH
export EXE=sherpa-onnx.exe
.github/scripts/test-online-ctc.sh
13 changes: 7 additions & 6 deletions .github/workflows/windows-x86-debug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ concurrency:

jobs:
windows_x86_debug:
name: Windows x86 debug
name: Windows x86 ${{ matrix.build_type }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest]
shared_lib: [OFF]
build_type: [Debug, MinSizeRel, RelWithDebInfo]

steps:
- uses: actions/checkout@v4
Expand All @@ -58,21 +59,21 @@ jobs:
run: |
mkdir build
cd build
cmake -A Win32 -D CMAKE_BUILD_TYPE=Debug -D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} -D CMAKE_INSTALL_PREFIX=./install ..
cmake -A Win32 -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} -D CMAKE_INSTALL_PREFIX=./install ..
- name: Build sherpa-onnx for windows
shell: bash
run: |
cd build
cmake --build . --config Debug -- -m:2
cmake --build . --config Debug --target install -- -m:2
cmake --build . --config ${{ matrix.build_type }} -- -m:2
cmake --build . --config ${{ matrix.build_type }} --target install -- -m:2
ls -lh ./bin/Debug/sherpa-onnx.exe
ls -lh ./bin/${{ matrix.build_type }}/sherpa-onnx.exe
- name: Test online CTC
shell: bash
run: |
export PATH=$PWD/build/bin/Debug:$PATH
export PATH=$PWD/build/bin/${{ matrix.build_type }}:$PATH
export EXE=sherpa-onnx.exe
.github/scripts/test-online-ctc.sh
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ if(NOT BUILD_SHARED_LIBS AND MSVC)
$<$<CONFIG:>:/MT> #---------|
$<$<CONFIG:Debug>:/MTd> #---|-- Statically link the runtime libraries
$<$<CONFIG:Release>:/MT> #--|
$<$<CONFIG:RelWithDebInfo>:/MT>
$<$<CONFIG:MinSizeRel>:/MT>
)
endif()
endif()
Expand Down
24 changes: 14 additions & 10 deletions cmake/onnxruntime-win-x64-static-debug.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,26 @@ if(BUILD_SHARED_LIBS)
message(FATAL_ERROR "This file is for building static libraries. BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}")
endif()

if(NOT CMAKE_BUILD_TYPE STREQUAL Debug)
message(FATAL_ERROR "This file is for building a debug version on Windows x64")
set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.17.0/onnxruntime-win-x64-static_lib-${CMAKE_BUILD_TYPE}-1.17.0.tar.bz2")
set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/onnxruntime-libs/resolve/main/onnxruntime-win-x64-static_lib-${CMAKE_BUILD_TYPE}-1.17.0.tar.bz2")
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(onnxruntime_HASH "SHA256=daef674f160044cf9f4c27d615eaa032f93c4ed6b8d2753bb91b4b37ba40349f")
elseif(CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo)
set(onnxruntime_HASH "SHA256=3b580429702e6f471b0899f4f1eede68c0c394aa01cd00376562c2a2e8224d72")
elseif(CMAKE_BUILD_TYPE STREQUAL MinSizeRel)
set(onnxruntime_HASH "SHA256=2777b1a01355b94760388eb48dbf9900f5decf2a0bd358418806138a687db6f0")
else()
message(FATAL_ERROR "This file is for building a debug version on Windows x64. Given ${CMAKE_BUILD_TYPE}")
endif()

set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.17.0/onnxruntime-win-x64-static_lib-debug-1.17.0.tar.bz2")
set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/onnxruntime-libs/resolve/main/onnxruntime-win-x64-static_lib-debug-1.17.0.tar.bz2")
set(onnxruntime_HASH "SHA256=6010bbab913cee3f11c421aeff9d173980623da6e72e88078396839a26d65c98")

# 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-win-x64-static_lib-debug-1.17.0.tar.bz2
${CMAKE_SOURCE_DIR}/onnxruntime-win-x64-static_lib-debug-1.17.0.tar.bz2
${CMAKE_BINARY_DIR}/onnxruntime-win-x64-static_lib-debug-1.17.0.tar.bz2
/tmp/onnxruntime-win-x64-static_lib-debug-1.17.0.tar.bz2
$ENV{HOME}/Downloads/onnxruntime-win-x64-static_lib-${CMAKE_BUILD_TYPE}-1.17.0.tar.bz2
${CMAKE_SOURCE_DIR}/onnxruntime-win-x64-static_lib-${CMAKE_BUILD_TYPE}-1.17.0.tar.bz2
${CMAKE_BINARY_DIR}/onnxruntime-win-x64-static_lib-${CMAKE_BUILD_TYPE}-1.17.0.tar.bz2
/tmp/onnxruntime-win-x64-static_lib-${CMAKE_BUILD_TYPE}-1.17.0.tar.bz2
)

foreach(f IN LISTS possible_file_locations)
Expand Down
25 changes: 15 additions & 10 deletions cmake/onnxruntime-win-x86-static-debug.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,27 @@ if(BUILD_SHARED_LIBS)
message(FATAL_ERROR "This file is for building static libraries. BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}")
endif()

if(NOT CMAKE_BUILD_TYPE STREQUAL Debug)
message(FATAL_ERROR "This file is for building a debug version on Windows x86")
endif()

set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.17.0/onnxruntime-win-x86-static_lib-debug-1.17.0.tar.bz2")
set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/onnxruntime-libs/resolve/main/onnxruntime-win-x86-static_lib-debug-1.17.0.tar.bz2")
set(onnxruntime_HASH "SHA256=aa18677dd45338a90fc1bc14c86fe1e8a21f63913d40b3644924f5b24654218e")
set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.17.0/onnxruntime-win-x86-static_lib-${CMAKE_BUILD_TYPE}-1.17.0.tar.bz2")
set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/onnxruntime-libs/resolve/main/onnxruntime-win-x86-static_lib-${CMAKE_BUILD_TYPE}-1.17.0.tar.bz2")
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(onnxruntime_HASH "SHA256=7ebf676b4cae50ae4c203ca54ae2341d7c7aeae66a965a85610b254d24effee3")
elseif(CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo)
set(onnxruntime_HASH "SHA256=bcb1dd68643baf011dc519f938c61b90556f354c6e6ce801e3f08a350d51b689")
elseif(CMAKE_BUILD_TYPE STREQUAL MinSizeRel)
set(onnxruntime_HASH "SHA256=a73a42cbff851b1ee2ec037dd3f4254978516252bc353a7ce86d12030ba73dec")
else()
message(FATAL_ERROR "This file is for building a debug version on Windows x86. Given ${CMAKE_BUILD_TYPE}")
endif()

# 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-win-x86-static_lib-debug-1.17.0.tar.bz2
${CMAKE_SOURCE_DIR}/onnxruntime-win-x86-static_lib-debug-1.17.0.tar.bz2
${CMAKE_BINARY_DIR}/onnxruntime-win-x86-static_lib-debug-1.17.0.tar.bz2
/tmp/onnxruntime-win-x86-static_lib-debug-1.17.0.tar.bz2
$ENV{HOME}/Downloads/onnxruntime-win-x86-static_lib-${CMAKE_BUILD_TYPE}-1.17.0.tar.bz2
${CMAKE_SOURCE_DIR}/onnxruntime-win-x86-static_lib-${CMAKE_BUILD_TYPE}-1.17.0.tar.bz2
${CMAKE_BINARY_DIR}/onnxruntime-win-x86-static_lib-${CMAKE_BUILD_TYPE}-1.17.0.tar.bz2
/tmp/onnxruntime-win-x86-static_lib-${CMAKE_BUILD_TYPE}-1.17.0.tar.bz2
)

foreach(f IN LISTS possible_file_locations)
Expand Down
9 changes: 5 additions & 4 deletions cmake/onnxruntime.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ function(download_onnxruntime)
else()
if(CMAKE_BUILD_TYPE STREQUAL Release)
include(onnxruntime-win-x86-static)
elseif(CMAKE_BUILD_TYPE STREQUAL Debug)
elseif(CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo OR CMAKE_BUILD_TYPE STREQUAL MinSizeRel)
include(onnxruntime-win-x86-static-debug)
else()
message(STATUS "Support only CMAKE_BUILD_TYPE Release or Debug. Given: ${CMAKE_BUILD_TYPE}")
message(FATAL_ERROR "Support only CMAKE_BUILD_TYPE being Release, Debug, RelWithDebInfo, or MinSizeRel. Given: ${CMAKE_BUILD_TYPE}")
endif()
endif()

Expand All @@ -85,6 +85,7 @@ function(download_onnxruntime)
# for 64-bit windows

if(BUILD_SHARED_LIBS)
message(STATUS "Use dynamic onnxruntime libraries")
if(SHERPA_ONNX_ENABLE_GPU)
include(onnxruntime-win-x64-gpu)
else()
Expand All @@ -95,10 +96,10 @@ function(download_onnxruntime)
message(STATUS "Use static onnxruntime libraries")
if(CMAKE_BUILD_TYPE STREQUAL Release)
include(onnxruntime-win-x64-static)
elseif(CMAKE_BUILD_TYPE STREQUAL Debug)
elseif(CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo OR CMAKE_BUILD_TYPE STREQUAL MinSizeRel)
include(onnxruntime-win-x64-static-debug)
else()
message(STATUS "Support only CMAKE_BUILD_TYPE Release or Debug. Given: ${CMAKE_BUILD_TYPE}")
message(FATAL_ERROR "Support only CMAKE_BUILD_TYPE being Release, Debug, RelWithDebInfo, or MinSizeRel. Given: ${CMAKE_BUILD_TYPE}")
endif()
endif()
endif()
Expand Down

0 comments on commit 1eeb87a

Please sign in to comment.