From 81be7f62ecbeca828543bff3a28af4c183e1054c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20=C3=85stholm?= Date: Wed, 8 Apr 2026 00:56:58 +0200 Subject: [PATCH] Fix debug I/O color detection for most targets On POSIX, start.zig did not reset the `environ_initialized` field, which prevented the environment variables from ever actually getting scanned. On Windows, environment variable scanning is allocation-free, so it's okay for `std.Io.Threaded.init_single_threaded` to use the global environment block. --- lib/std/Io/Threaded.zig | 31 +++++++++++++++++-------------- lib/std/start.zig | 1 + 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig index 937f75a531..f004a56ca9 100644 --- a/lib/std/Io/Threaded.zig +++ b/lib/std/Io/Threaded.zig @@ -1671,20 +1671,23 @@ pub fn init( /// When initialized this way: /// * cancel requests have no effect. /// * `deinit` is safe, but unnecessary to call. -pub const init_single_threaded: Threaded = .{ - .allocator = .failing, - .stack_size = std.Thread.SpawnConfig.default_stack_size, - .async_limit = .nothing, - .cpu_count_error = null, - .concurrent_limit = .nothing, - .old_sig_io = undefined, - .old_sig_pipe = undefined, - .have_signal_handler = false, - .argv0 = .empty, - .environ_initialized = true, - .environ = .empty, - .worker_threads = .init(null), - .disable_memory_mapping = false, +pub const init_single_threaded: Threaded = init: { + const env_block: process.Environ.Block = if (is_windows) .global else .empty; + break :init .{ + .allocator = .failing, + .stack_size = std.Thread.SpawnConfig.default_stack_size, + .async_limit = .nothing, + .cpu_count_error = null, + .concurrent_limit = .nothing, + .old_sig_io = undefined, + .old_sig_pipe = undefined, + .have_signal_handler = false, + .argv0 = .empty, + .environ_initialized = env_block.isEmpty(), + .environ = .{ .process_environ = .{ .block = env_block } }, + .worker_threads = .init(null), + .disable_memory_mapping = false, + }; }; var global_single_threaded_instance: Threaded = .init_single_threaded; diff --git a/lib/std/start.zig b/lib/std/start.zig index 8735042738..29c76fdfad 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -631,6 +631,7 @@ inline fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [:null]?[*:0]u8) if (std.Options.debug_threaded_io) |t| { if (@sizeOf(std.Io.Threaded.Argv0) != 0) t.argv0.value = argv[0]; t.environ = .{ .process_environ = .{ .block = env_block } }; + t.environ_initialized = env_block.isEmpty(); } std.Thread.maybeAttachSignalStack(); std.debug.maybeEnableSegfaultHandler();