| author | |
| committer | |
| log | 24b4e643f486ce803f758a6eab0c587c44b9cfa4 |
| tree | a462fbd4199453da809cb7239ed52bb81e26c8cc |
| parent | 7a2d7ff6280c4e75618b5d4de24c3ff4aedd8a18 |
| signature |
3 files changed, 35 insertions(+), 18 deletions(-)
lib/std/debug.zig+16-15| ... | ... | @@ -110,27 +110,28 @@ pub fn getSelfDebugInfo() !*DebugInfo { |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | pub fn detectTTYConfig(file: std.fs.File) TTY.Config { |
| 113 | if (process.hasEnvVarConstant("ZIG_DEBUG_COLOR")) { | |
| 113 | if (builtin.os.tag == .wasi) { | |
| 114 | // Per https://github.com/WebAssembly/WASI/issues/162 ANSI codes | |
| 115 | // aren't currently supported. | |
| 116 | return .no_color; | |
| 117 | } else if (process.hasEnvVarConstant("ZIG_DEBUG_COLOR")) { | |
| 114 | 118 | return .escape_codes; |
| 115 | 119 | } else if (process.hasEnvVarConstant("NO_COLOR")) { |
| 116 | 120 | return .no_color; |
| 117 | } else { | |
| 118 | if (file.supportsAnsiEscapeCodes()) { | |
| 119 | return .escape_codes; | |
| 120 | } else if (native_os == .windows and file.isTty()) { | |
| 121 | var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined; | |
| 122 | if (windows.kernel32.GetConsoleScreenBufferInfo(file.handle, &info) != windows.TRUE) { | |
| 123 | // TODO: Should this return an error instead? | |
| 124 | return .no_color; | |
| 125 | } | |
| 126 | return .{ .windows_api = .{ | |
| 127 | .handle = file.handle, | |
| 128 | .reset_attributes = info.wAttributes, | |
| 129 | } }; | |
| 130 | } else { | |
| 121 | } else if (file.supportsAnsiEscapeCodes()) { | |
| 122 | return .escape_codes; | |
| 123 | } else if (native_os == .windows and file.isTty()) { | |
| 124 | var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined; | |
| 125 | if (windows.kernel32.GetConsoleScreenBufferInfo(file.handle, &info) != windows.TRUE) { | |
| 126 | // TODO: Should this return an error instead? | |
| 131 | 127 | return .no_color; |
| 132 | 128 | } |
| 129 | return .{ .windows_api = .{ | |
| 130 | .handle = file.handle, | |
| 131 | .reset_attributes = info.wAttributes, | |
| 132 | } }; | |
| 133 | 133 | } |
| 134 | return .no_color; | |
| 134 | 135 | } |
| 135 | 136 | |
| 136 | 137 | /// Tries to print the current stack trace to stderr, unbuffered, and ignores any error returned. |
lib/std/process.zig+11| ... | ... | @@ -369,6 +369,11 @@ pub fn getEnvVarOwned(allocator: Allocator, key: []const u8) GetEnvVarOwnedError |
| 369 | 369 | error.UnexpectedSecondSurrogateHalf => return error.InvalidUtf8, |
| 370 | 370 | else => |e| return e, |
| 371 | 371 | }; |
| 372 | } else if (builtin.os.tag == .wasi and !builtin.link_libc) { | |
| 373 | var envmap = getEnvMap(allocator) catch return error.OutOfMemory; | |
| 374 | defer envmap.deinit(); | |
| 375 | const val = envmap.get(key) orelse return error.EnvironmentVariableNotFound; | |
| 376 | return allocator.dupe(u8, val); | |
| 372 | 377 | } else { |
| 373 | 378 | const result = os.getenv(key) orelse return error.EnvironmentVariableNotFound; |
| 374 | 379 | return allocator.dupe(u8, result); |
| ... | ... | @@ -379,6 +384,8 @@ pub fn hasEnvVarConstant(comptime key: []const u8) bool { |
| 379 | 384 | if (builtin.os.tag == .windows) { |
| 380 | 385 | const key_w = comptime std.unicode.utf8ToUtf16LeStringLiteral(key); |
| 381 | 386 | return std.os.getenvW(key_w) != null; |
| 387 | } else if (builtin.os.tag == .wasi and !builtin.link_libc) { | |
| 388 | @compileError("hasEnvVarConstant is not supported for WASI without libc"); | |
| 382 | 389 | } else { |
| 383 | 390 | return os.getenv(key) != null; |
| 384 | 391 | } |
| ... | ... | @@ -390,6 +397,10 @@ pub fn hasEnvVar(allocator: Allocator, key: []const u8) error{OutOfMemory}!bool |
| 390 | 397 | const key_w = try std.unicode.utf8ToUtf16LeWithNull(stack_alloc.get(), key); |
| 391 | 398 | defer stack_alloc.allocator.free(key_w); |
| 392 | 399 | return std.os.getenvW(key_w) != null; |
| 400 | } else if (builtin.os.tag == .wasi and !builtin.link_libc) { | |
| 401 | var envmap = getEnvMap(allocator) catch return error.OutOfMemory; | |
| 402 | defer envmap.deinit(); | |
| 403 | return envmap.getPtr(key) != null; | |
| 393 | 404 | } else { |
| 394 | 405 | return os.getenv(key) != null; |
| 395 | 406 | } |
src/main.zig+8-3| ... | ... | @@ -637,6 +637,10 @@ const Emit = union(enum) { |
| 637 | 637 | }; |
| 638 | 638 | |
| 639 | 639 | fn optionalStringEnvVar(arena: Allocator, name: []const u8) !?[]const u8 { |
| 640 | // Env vars aren't used in the bootstrap stage. | |
| 641 | if (build_options.only_c) { | |
| 642 | return null; | |
| 643 | } | |
| 640 | 644 | if (std.process.getEnvVarOwned(arena, name)) |value| { |
| 641 | 645 | return value; |
| 642 | 646 | } else |err| switch (err) { |
| ... | ... | @@ -676,8 +680,8 @@ fn buildOutputType( |
| 676 | 680 | var no_builtin = false; |
| 677 | 681 | var watch = false; |
| 678 | 682 | var debug_compile_errors = false; |
| 679 | var verbose_link = std.process.hasEnvVarConstant("ZIG_VERBOSE_LINK"); | |
| 680 | var verbose_cc = std.process.hasEnvVarConstant("ZIG_VERBOSE_CC"); | |
| 683 | var verbose_link = (builtin.os.tag != .wasi or builtin.link_libc) and std.process.hasEnvVarConstant("ZIG_VERBOSE_LINK"); | |
| 684 | var verbose_cc = (builtin.os.tag != .wasi or builtin.link_libc) and std.process.hasEnvVarConstant("ZIG_VERBOSE_CC"); | |
| 681 | 685 | var verbose_air = false; |
| 682 | 686 | var verbose_llvm_ir = false; |
| 683 | 687 | var verbose_cimport = false; |
| ... | ... | @@ -859,7 +863,8 @@ fn buildOutputType( |
| 859 | 863 | // before arg parsing, check for the NO_COLOR environment variable |
| 860 | 864 | // if it exists, default the color setting to .off |
| 861 | 865 | // explicit --color arguments will still override this setting. |
| 862 | color = if (std.process.hasEnvVarConstant("NO_COLOR")) .off else .auto; | |
| 866 | // Disable color on WASI per https://github.com/WebAssembly/WASI/issues/162 | |
| 867 | color = if (builtin.os.tag == .wasi or std.process.hasEnvVarConstant("NO_COLOR")) .off else .auto; | |
| 863 | 868 | |
| 864 | 869 | switch (arg_mode) { |
| 865 | 870 | .build, .translate_c, .zig_test, .run => { |