@@ -210,6 +210,14 @@ extern "kernel32" fn ExitProcess(exit_code: u32) callconv(.C) noreturn;
210210
211211////////////////////////////////////////////////////////////////////////////////
212212
213+ /// Contains any logic that should be run on exe startup to bully Windows
214+ /// into being a sane environment
215+ inline fn setupWindows () void {
216+ if (std .options .windows_force_utf8_codepage ) {
217+ _ = std .os .windows .kernel32 .SetConsoleOutputCP (65001 ); // use UTF-8 codepage
218+ }
219+ }
220+
213221fn _DllMainCRTStartup (
214222 hinstDLL : std.os.windows.HINSTANCE ,
215223 fdwReason : std.os.windows.DWORD ,
@@ -382,6 +390,7 @@ fn WinStartup() callconv(std.os.windows.WINAPI) noreturn {
382390 _ = @import ("start_windows_tls.zig" );
383391 }
384392
393+ setupWindows ();
385394 std .debug .maybeEnableSegfaultHandler ();
386395
387396 std .os .windows .kernel32 .ExitProcess (initEventLoopAndCallMain ());
@@ -393,6 +402,7 @@ fn wWinMainCRTStartup() callconv(std.os.windows.WINAPI) noreturn {
393402 _ = @import ("start_windows_tls.zig" );
394403 }
395404
405+ setupWindows ();
396406 std .debug .maybeEnableSegfaultHandler ();
397407
398408 const result : std.os.windows.INT = initEventLoopAndCallWinMain ();
@@ -495,6 +505,9 @@ fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [][*:0]u8) u8 {
495505 std .os .argv = argv [0.. argc ];
496506 std .os .environ = envp ;
497507
508+ if (builtin .os .tag == .windows ) {
509+ setupWindows ();
510+ }
498511 std .debug .maybeEnableSegfaultHandler ();
499512
500513 return initEventLoopAndCallMain ();
0 commit comments