From 2b70a1c0dcaf662e4b0da21a823e541251f11e49 Mon Sep 17 00:00:00 2001 From: Judd Date: Wed, 5 Feb 2025 12:00:59 +0800 Subject: [PATCH 1/3] Fixes for Windows: * MSVC default to utf-8 without BOM. * Console output code page changed to utf-8. --- cmake/build-info.cmake | 1 + examples/cli/cli.cpp | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cmake/build-info.cmake b/cmake/build-info.cmake index ea3dc55c834..a90c9de577e 100644 --- a/cmake/build-info.cmake +++ b/cmake/build-info.cmake @@ -42,6 +42,7 @@ 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") 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 57fbf5bff57..1c0ba857e78 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 @@ -915,7 +920,14 @@ 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) { +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 From 586e511529f5b050b8086617c1c3e2128f6c0326 Mon Sep 17 00:00:00 2001 From: Judd Date: Wed, 5 Feb 2025 14:53:05 +0800 Subject: [PATCH 2/3] undo editing. --- examples/cli/cli.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/cli/cli.cpp b/examples/cli/cli.cpp index 1c0ba857e78..36ce26827ce 100644 --- a/examples/cli/cli.cpp +++ b/examples/cli/cli.cpp @@ -920,7 +920,7 @@ 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) { +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 From 24a70a817b18a3802f0005980d2edc67f462c0c8 Mon Sep 17 00:00:00 2001 From: Judd Date: Wed, 5 Feb 2025 17:10:38 +0800 Subject: [PATCH 3/3] fix utf-8 option for MSVC --- cmake/build-info.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/build-info.cmake b/cmake/build-info.cmake index a90c9de577e..b293c9b5d83 100644 --- a/cmake/build-info.cmake +++ b/cmake/build-info.cmake @@ -42,7 +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>") + add_compile_options("$<$:/utf-8>") else() execute_process( COMMAND sh -c "$@ --version | head -1" _ ${CMAKE_C_COMPILER}