authorgravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2026-04-08 00:56:58+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-11 12:28:24-07:00
log81be7f62ecbeca828543bff3a28af4c183e1054c
tree49f87ea24bb3efcf4ef7a0b15857598908ccae91
parentc61e18006fb6d2beb58c07962a6a8a009806c2f4

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.

2 files changed, 18 insertions(+), 14 deletions(-)

lib/std/Io/Threaded.zig+17-14
...@@ -1671,20 +1671,23 @@ pub fn init(...@@ -1671,20 +1671,23 @@ pub fn init(
1671/// When initialized this way:1671/// When initialized this way:
1672/// * cancel requests have no effect.1672/// * cancel requests have no effect.
1673/// * `deinit` is safe, but unnecessary to call.1673/// * `deinit` is safe, but unnecessary to call.
1674pub const init_single_threaded: Threaded = .{1674pub const init_single_threaded: Threaded = init: {
1675 .allocator = .failing,1675 const env_block: process.Environ.Block = if (is_windows) .global else .empty;
1676 .stack_size = std.Thread.SpawnConfig.default_stack_size,1676 break :init .{
1677 .async_limit = .nothing,1677 .allocator = .failing,
1678 .cpu_count_error = null,1678 .stack_size = std.Thread.SpawnConfig.default_stack_size,
1679 .concurrent_limit = .nothing,1679 .async_limit = .nothing,
1680 .old_sig_io = undefined,1680 .cpu_count_error = null,
1681 .old_sig_pipe = undefined,1681 .concurrent_limit = .nothing,
1682 .have_signal_handler = false,1682 .old_sig_io = undefined,
1683 .argv0 = .empty,1683 .old_sig_pipe = undefined,
1684 .environ_initialized = true,1684 .have_signal_handler = false,
1685 .environ = .empty,1685 .argv0 = .empty,
1686 .worker_threads = .init(null),1686 .environ_initialized = env_block.isEmpty(),
1687 .disable_memory_mapping = false,1687 .environ = .{ .process_environ = .{ .block = env_block } },
1688 .worker_threads = .init(null),
1689 .disable_memory_mapping = false,
1690 };
1688};1691};
16891692
1690var global_single_threaded_instance: Threaded = .init_single_threaded;1693var global_single_threaded_instance: Threaded = .init_single_threaded;
lib/std/start.zig+1
...@@ -631,6 +631,7 @@ inline fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [:null]?[*:0]u8)...@@ -631,6 +631,7 @@ inline fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [:null]?[*:0]u8)
631 if (std.Options.debug_threaded_io) |t| {631 if (std.Options.debug_threaded_io) |t| {
632 if (@sizeOf(std.Io.Threaded.Argv0) != 0) t.argv0.value = argv[0];632 if (@sizeOf(std.Io.Threaded.Argv0) != 0) t.argv0.value = argv[0];
633 t.environ = .{ .process_environ = .{ .block = env_block } };633 t.environ = .{ .process_environ = .{ .block = env_block } };
634 t.environ_initialized = env_block.isEmpty();
634 }635 }
635 std.Thread.maybeAttachSignalStack();636 std.Thread.maybeAttachSignalStack();
636 std.debug.maybeEnableSegfaultHandler();637 std.debug.maybeEnableSegfaultHandler();