pkg/apple-sdk: only exec to get xcode path once per build

This commit is contained in:
Mitchell Hashimoto
2024-01-10 09:34:49 -08:00
parent 41de9c6e97
commit 5bca3a4044

View File

@ -15,12 +15,16 @@ pub fn addPaths(b: *std.Build, m: *std.Build.Module) !void {
const sdk = try SDK.fromTarget(m.resolved_target.?.result);
// Get the path to our active Xcode installation. If this fails then
// the zig build will fail.
const path = std.mem.trim(
u8,
b.run(&.{ "xcode-select", "--print-path" }),
" \r\n",
);
// the zig build will fail. We store this in a struct variable so its
// static and only calculated once per build.
const Path = struct {
var value: ?[]const u8 = null;
};
const path = Path.value orelse path: {
const path = std.mem.trim(u8, b.run(&.{ "xcode-select", "--print-path" }), " \r\n");
Path.value = path;
break :path path;
};
// Base path
const base = b.fmt("{s}/Platforms/{s}.platform/Developer/SDKs/{s}{s}.sdk", .{