commit f25de4c7a238d46a20c6a22e3b951ee09ecfb962 (tree)
parent 17c7a339d87b8029436c676582e9c54720e6c180
Author: Andrew Kelley <andrew@ziglang.org>
Date: Fri, 2 Jan 2026 20:46:24 -0800
fix native path lookup on macOS
Diffstat:
3 files changed, 6 insertions(+), 10 deletions(-)
diff --git 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
@@ -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
@@ -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;