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 {...@@ -763,6 +763,9 @@ pub const EnvVar = enum {
763 // Windows SDK integration763 // Windows SDK integration
764 PROGRAMDATA,764 PROGRAMDATA,
765765
766 // Homebrew integration
767 HOMEBREW_PREFIX,
768
766 pub fn isSet(ev: EnvVar, map: *const std.process.Environ.Map) bool {769 pub fn isSet(ev: EnvVar, map: *const std.process.Environ.Map) bool {
767 return map.contains(@tagName(ev));770 return map.contains(@tagName(ev));
768 }771 }
lib/std/zig/system/NativePaths.zig+1-3
...@@ -121,7 +121,7 @@ pub fn detect(...@@ -121,7 +121,7 @@ pub fn detect(
121 }121 }
122122
123 // Check for homebrew paths123 // Check for homebrew paths
124 if (std.posix.getenv("HOMEBREW_PREFIX")) |prefix| {124 if (std.zig.EnvVar.HOMEBREW_PREFIX.get(env_map)) |prefix| {
125 try self.addLibDir(try std.fs.path.join(arena, &.{ prefix, "/lib" }));125 try self.addLibDir(try std.fs.path.join(arena, &.{ prefix, "/lib" }));
126 try self.addIncludeDir(try std.fs.path.join(arena, &.{ prefix, "/include" }));126 try self.addIncludeDir(try std.fs.path.join(arena, &.{ prefix, "/include" }));
127 }127 }
...@@ -177,8 +177,6 @@ pub fn detect(...@@ -177,8 +177,6 @@ pub fn detect(
177177
178 // Distros like guix don't use FHS, so they rely on environment178 // Distros like guix don't use FHS, so they rely on environment
179 // variables to search for headers and libraries.179 // 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.
182 if (std.zig.EnvVar.C_INCLUDE_PATH.get(env_map)) |c_include_path| {180 if (std.zig.EnvVar.C_INCLUDE_PATH.get(env_map)) |c_include_path| {
183 var it = mem.tokenizeScalar(u8, c_include_path, ':');181 var it = mem.tokenizeScalar(u8, c_include_path, ':');
184 while (it.next()) |dir| {182 while (it.next()) |dir| {
test/standalone/posix/getenv.zig+2-7
...@@ -4,13 +4,8 @@ const std = @import("std");...@@ -4,13 +4,8 @@ const std = @import("std");
4const builtin = @import("builtin");4const builtin = @import("builtin");
55
6pub fn main(init: std.process.Init.Minimal) !void {6pub fn main(init: std.process.Init.Minimal) !void {
7 if (builtin.target.os.tag == .windows) {7 if (builtin.target.os.tag == .windows) return;
8 return; // Windows env strings are WTF-16, so not supported by Zig's std.posix.getenv()8 if (builtin.target.os.tag == .wasi and !builtin.link_libc) return;
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 }
149
15 const environ = init.environ;10 const environ = init.environ;
1611