Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/std/start.zig
Original file line numberDiff line numberDiff line change
Expand Up@@ -210,6 +210,14 @@ extern "kernel32" fn ExitProcess(exit_code: u32) callconv(.C) noreturn;

////////////////////////////////////////////////////////////////////////////////

/// Contains any logic that should be run on exe startup to bully Windows
/// into being a sane environment
inline fn setupWindows() void {
if (std.options.windows_force_utf8_codepage) {
_ = std.os.windows.kernel32.SetConsoleOutputCP(65001); // use UTF-8 codepage
}

@expikrexpikrNov 21, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that this would be on the same level of prescription as enabling ansi escape codes here, could sneak in something like

Suggested change
}
}
if (std.options.windows_force_virtual_terminal) {
constENABLE_VIRTUAL_TERMINAL_PROCESSING=4;
varstdout_mode: u32=undefined;
_=std.os.windows.kernel32.GetConsoleMode(std.io.getStdOut().handle, &stdout_mode);
stdout_mode|=ENABLE_VIRTUAL_TERMINAL_PROCESSING;
_=std.os.windows.kernel32.SetConsoleMode(std.io.getStdOut().handle, stdout_mode);
}

}

fn _DllMainCRTStartup(
hinstDLL: std.os.windows.HINSTANCE,
fdwReason: std.os.windows.DWORD,
Expand DownExpand Up@@ -382,6 +390,7 @@ fn WinStartup() callconv(std.os.windows.WINAPI) noreturn {
_ = @import("start_windows_tls.zig");
}

setupWindows();
std.debug.maybeEnableSegfaultHandler();

std.os.windows.kernel32.ExitProcess(initEventLoopAndCallMain());
Expand All@@ -393,6 +402,7 @@ fn wWinMainCRTStartup() callconv(std.os.windows.WINAPI) noreturn {
_ = @import("start_windows_tls.zig");
}

setupWindows();
std.debug.maybeEnableSegfaultHandler();

const result: std.os.windows.INT = initEventLoopAndCallWinMain();
Expand DownExpand Up@@ -495,6 +505,9 @@ fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [][*:0]u8) u8 {
std.os.argv = argv[0..argc];
std.os.environ = envp;

if (builtin.os.tag == .windows) {
setupWindows();
}
std.debug.maybeEnableSegfaultHandler();

return initEventLoopAndCallMain();
Expand Down
5 changes: 5 additions & 0 deletions lib/std/std.zig
Original file line numberDiff line numberDiff line change
Expand Up@@ -159,6 +159,11 @@ pub const options = struct {
options_override.crypto_always_getrandom
else
false;

pub const windows_force_utf8_codepage: bool = if (@hasDecl(options_override, "windows_force_utf8_codepage"))
options_override.windows_force_utf8_codepage
else
true;
};

// This forces the start.zig file to be imported, and the comptime logic inside that
Expand Down