From d682e150908e10caa4c15883c633d7902d385237 Mon Sep 17 00:00:00 2001 From: Judd Date: Thu, 6 Feb 2025 15:37:21 +0800 Subject: [PATCH] Fixes for Windows (#2790) Fixes for Windows: * MSVC default to utf-8 without BOM. * Console output code page changed to utf-8. --------- Co-authored-by: Judd --- cmake/build-info.cmake | 2 ++ examples/cli/cli.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/cmake/build-info.cmake b/cmake/build-info.cmake index ea3dc55c..b293c9b5 100644 --- a/cmake/build-info.cmake +++ b/cmake/build-info.cmake @@ -42,6 +42,8 @@ endif() if(MSVC) set(BUILD_COMPILER "${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}") set(BUILD_TARGET ${CMAKE_VS_PLATFORM_NAME}) + add_compile_options("$<$:/utf-8>") + add_compile_options("$<$:/utf-8>") else() execute_process( COMMAND sh -c "$@ --version | head -1" _ ${CMAKE_C_COMPILER} diff --git a/examples/cli/cli.cpp b/examples/cli/cli.cpp index 57fbf5bf..36ce2682 100644 --- a/examples/cli/cli.cpp +++ b/examples/cli/cli.cpp @@ -12,6 +12,11 @@ #include #include +#if defined(_WIN32) +#define NOMINMAX +#include +#endif + #if defined(_MSC_VER) #pragma warning(disable: 4244 4267) // possible loss of data #endif @@ -916,6 +921,13 @@ static bool output_lrc(struct whisper_context * ctx, const char * fname, const w static void cb_log_disable(enum ggml_log_level , const char * , void * ) { } int main(int argc, char ** argv) { +#if defined(_WIN32) + // Set the console output code page to UTF-8, while command line arguments + // are still encoded in the system's code page. In this way, we can print + // non-ASCII characters to the console, and access files with non-ASCII paths. + SetConsoleOutputCP(CP_UTF8); +#endif + whisper_params params; // If the only argument starts with "@", read arguments line-by-line