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); const sdk = try SDK.fromTarget(m.resolved_target.?.result);
// Get the path to our active Xcode installation. If this fails then // Get the path to our active Xcode installation. If this fails then
// the zig build will fail. // the zig build will fail. We store this in a struct variable so its
const path = std.mem.trim( // static and only calculated once per build.
u8, const Path = struct {
b.run(&.{ "xcode-select", "--print-path" }), var value: ?[]const u8 = null;
" \r\n", };
); 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 // Base path
const base = b.fmt("{s}/Platforms/{s}.platform/Developer/SDKs/{s}{s}.sdk", .{ const base = b.fmt("{s}/Platforms/{s}.platform/Developer/SDKs/{s}{s}.sdk", .{