const std = @import("std");
const mem = std.mem;
const Allocator = mem.Allocator;
const Target = std.Target;
const Version = std.SemanticVersion;
pub const macos = @import("darwin/macos.zig");
pub fn isSdkInstalled(allocator: Allocator) bool {
const result = std.process.Child.run(.{
.allocator = allocator,
.argv = &.{ "/usr/bin/xcode-select", "--print-path" },
}) catch return false;
defer {
allocator.free(result.stderr);
allocator.free(result.stdout);
}
return switch (result.term) {
.Exited => |code| if (code == 0) result.stdout.len > 0 else false,
else => false,
};
}
pub fn getSdk(allocator: Allocator, target: Target) ?[]const u8 {
const is_simulator_abi = target.abi == .simulator;
const sdk = switch (target.os.tag) {
.macos => "macosx",
.ios => if (is_simulator_abi) "iphonesimulator" else "iphoneos",
.watchos => if (is_simulator_abi) "watchsimulator" else "watchos",
.tvos => if (is_simulator_abi) "appletvsimulator" else "appletvos",
else => return null,
};
const argv = &[_][]const u8{ "/usr/bin/xcrun", "--sdk", sdk, "--show-sdk-path" };
const result = std.process.Child.run(.{ .allocator = allocator, .argv = argv }) catch return null;
defer {
allocator.free(result.stderr);
allocator.free(result.stdout);
}
switch (result.term) {
.Exited => |code| if (code != 0) return null,
else => return null,
}
return allocator.dupe(u8, mem.trimRight(u8, result.stdout, "\r\n")) catch null;
}
test {
_ = macos;
}