diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig index 2fcd455110..937f75a531 100644 --- a/lib/std/Io/Threaded.zig +++ b/lib/std/Io/Threaded.zig @@ -8729,13 +8729,6 @@ fn supportsAnsiEscapeCodes(file: File) Io.Cancelable!bool { } } - if (native_os == .wasi) { - // WASI sanitizes stdout when fd is a tty so ANSI escape codes will not - // be interpreted as actual cursor commands, and stderr is always - // sanitized. - return false; - } - if (try isTty(file)) return true; return false; diff --git a/lib/std/process/Environ.zig b/lib/std/process/Environ.zig index d9ef7aec2d..57d5ea0271 100644 --- a/lib/std/process/Environ.zig +++ b/lib/std/process/Environ.zig @@ -24,7 +24,7 @@ pub const empty: Environ = .{ .block = .empty }; /// operating system `void` is also used. pub const Block = switch (native_os) { .windows => GlobalBlock, - .wasi => switch (builtin.link_libc) { + .wasi, .emscripten => switch (builtin.link_libc) { false => GlobalBlock, true => PosixBlock, }, diff --git a/lib/std/start.zig b/lib/std/start.zig index f6b4064ebd..8735042738 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -664,10 +664,22 @@ fn main(c_argc: c_int, c_argv: [*][*:0]c_char, c_envp: [*:null]?[*:0]c_char) cal fn mainWithoutEnv(c_argc: c_int, c_argv: [*][*:0]c_char) callconv(.c) c_int { const argv = @as([*][*:0]u8, @ptrCast(c_argv))[0..@intCast(c_argc)]; - if (@sizeOf(std.Io.Threaded.Argv0) != 0) { - if (std.Options.debug_threaded_io) |t| t.argv0.value = argv[0]; + const environ: [:null]?[*:0]u8 = switch (builtin.os.tag) { + .wasi, .emscripten => environ: { + const c_environ = std.c.environ; + var env_count: usize = 0; + while (c_environ[env_count] != null) : (env_count += 1) {} + break :environ c_environ[0..env_count :null]; + }, + else => &.{}, + }; + const env_block: std.process.Environ.Block = .{ .slice = environ }; + 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(); } - return callMain(argv, .empty); + return callMain(argv, env_block); } /// General error message for a malformed return type