authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-02 20:46:24-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-04 00:27:08-08:00
logf25de4c7a238d46a20c6a22e3b951ee09ecfb962
tree4471537c73338973f1cb50bd97ab629b019aa491
parent17c7a339d87b8029436c676582e9c54720e6c180

fix native path lookup on macOS


3 files changed, 6 insertions(+), 10 deletions(-)

lib/std/zig.zig+3
......@@ -763,6 +763,9 @@ pub const EnvVar = enum {
763763 // Windows SDK integration
764764 PROGRAMDATA,
765765
766 // Homebrew integration
767 HOMEBREW_PREFIX,
768
766769 pub fn isSet(ev: EnvVar, map: *const std.process.Environ.Map) bool {
767770 return map.contains(@tagName(ev));
768771 }
lib/std/zig/system/NativePaths.zig+1-3
......@@ -121,7 +121,7 @@ pub fn detect(
121121 }
122122
123123 // Check for homebrew paths
124 if (std.posix.getenv("HOMEBREW_PREFIX")) |prefix| {
124 if (std.zig.EnvVar.HOMEBREW_PREFIX.get(env_map)) |prefix| {
125125 try self.addLibDir(try std.fs.path.join(arena, &.{ prefix, "/lib" }));
126126 try self.addIncludeDir(try std.fs.path.join(arena, &.{ prefix, "/include" }));
127127 }
......@@ -177,8 +177,6 @@ pub fn detect(
177177
178178 // Distros like guix don't use FHS, so they rely on environment
179179 // variables to search for headers and libraries.
180 // We use os.getenv here since this part won't be executed on
181 // windows, to get rid of unnecessary error handling.
182180 if (std.zig.EnvVar.C_INCLUDE_PATH.get(env_map)) |c_include_path| {
183181 var it = mem.tokenizeScalar(u8, c_include_path, ':');
184182 while (it.next()) |dir| {
test/standalone/posix/getenv.zig+2-7
......@@ -4,13 +4,8 @@ const std = @import("std");
44const builtin = @import("builtin");
55
66pub fn main(init: std.process.Init.Minimal) !void {
7 if (builtin.target.os.tag == .windows) {
8 return; // Windows env strings are WTF-16, so not supported by Zig's std.posix.getenv()
9 }
10
11 if (builtin.target.os.tag == .wasi and !builtin.link_libc) {
12 return; // std.posix.getenv is not supported on WASI due to the need of allocation
13 }
7 if (builtin.target.os.tag == .windows) return;
8 if (builtin.target.os.tag == .wasi and !builtin.link_libc) return;
149
1510 const environ = init.environ;
1611