]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
Fixes for Windows (#2790)
authorJudd <redacted>
Thu, 6 Feb 2025 07:37:21 +0000 (15:37 +0800)
committerGitHub <redacted>
Thu, 6 Feb 2025 07:37:21 +0000 (15:37 +0800)
Fixes for Windows:

* MSVC default to utf-8 without BOM.
* Console output code page changed to utf-8.

---------

Co-authored-by: Judd <redacted>
cmake/build-info.cmake
examples/cli/cli.cpp

index ea3dc55c83439a91c9289760bc17b1b0dcd69aa1..b293c9b5d834cd382a5c69910f184ae77cb041a5 100644 (file)
@@ -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("$<$<COMPILE_LANGUAGE:C>:/utf-8>")
+    add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/utf-8>")
 else()
     execute_process(
         COMMAND sh -c "$@ --version | head -1" _ ${CMAKE_C_COMPILER}
index 57fbf5bff578e5c93d1f4130fea9943c99616109..36ce26827ce53ffc35ca0fd42590c97f66953830 100644 (file)
 #include <vector>
 #include <cstring>
 
+#if defined(_WIN32)
+#define NOMINMAX
+#include <windows.h>
+#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