diff --git a/lib/std/zig.zig b/lib/std/zig.zig index 0a24a242d7..4f0f47b11f 100644 --- a/lib/std/zig.zig +++ b/lib/std/zig.zig @@ -763,6 +763,9 @@ pub const EnvVar = enum { // Windows SDK integration PROGRAMDATA, + // Homebrew integration + HOMEBREW_PREFIX, + pub fn isSet(ev: EnvVar, map: *const std.process.Environ.Map) bool { return map.contains(@tagName(ev)); } diff --git a/lib/std/zig/system/NativePaths.zig b/lib/std/zig/system/NativePaths.zig index 02f59d4b03..fd717f38b3 100644 --- a/lib/std/zig/system/NativePaths.zig +++ b/lib/std/zig/system/NativePaths.zig @@ -121,7 +121,7 @@ pub fn detect( } // Check for homebrew paths - if (std.posix.getenv("HOMEBREW_PREFIX")) |prefix| { + if (std.zig.EnvVar.HOMEBREW_PREFIX.get(env_map)) |prefix| { try self.addLibDir(try std.fs.path.join(arena, &.{ prefix, "/lib" })); try self.addIncludeDir(try std.fs.path.join(arena, &.{ prefix, "/include" })); } @@ -177,8 +177,6 @@ pub fn detect( // Distros like guix don't use FHS, so they rely on environment // variables to search for headers and libraries. - // We use os.getenv here since this part won't be executed on - // windows, to get rid of unnecessary error handling. if (std.zig.EnvVar.C_INCLUDE_PATH.get(env_map)) |c_include_path| { var it = mem.tokenizeScalar(u8, c_include_path, ':'); while (it.next()) |dir| { diff --git a/test/standalone/posix/getenv.zig b/test/standalone/posix/getenv.zig index ea4f9c4877..62c348e085 100644 --- a/test/standalone/posix/getenv.zig +++ b/test/standalone/posix/getenv.zig @@ -4,13 +4,8 @@ const std = @import("std"); const builtin = @import("builtin"); pub fn main(init: std.process.Init.Minimal) !void { - if (builtin.target.os.tag == .windows) { - return; // Windows env strings are WTF-16, so not supported by Zig's std.posix.getenv() - } - - if (builtin.target.os.tag == .wasi and !builtin.link_libc) { - return; // std.posix.getenv is not supported on WASI due to the need of allocation - } + if (builtin.target.os.tag == .windows) return; + if (builtin.target.os.tag == .wasi and !builtin.link_libc) return; const environ = init.environ;