| ... | ... | @@ -8,27 +8,33 @@ pub const macos = @import("darwin/macos.zig"); |
| 8 | 8 | |
| 9 | 9 | /// Check if SDK is installed on Darwin without triggering CLT installation popup window. |
| 10 | 10 | /// Note: simply invoking `xcrun` will inevitably trigger the CLT installation popup. |
| 11 | | /// Therefore, we resort to the same tool used by Homebrew, namely, invoking `xcode-select --print-path` |
| 12 | | /// and checking if the status is nonzero or the returned string in nonempty. |
| 13 | | /// https://github.com/Homebrew/brew/blob/e119bdc571dcb000305411bc1e26678b132afb98/Library/Homebrew/brew.sh#L630 |
| 11 | /// Therefore, we resort to invoking `xcode-select --print-path` and checking |
| 12 | /// if the status is nonzero. |
| 13 | /// stderr from xcode-select is ignored. |
| 14 | /// If error.OutOfMemory occurs in Allocator, this function returns null. |
| 14 | 15 | pub fn isSdkInstalled(allocator: Allocator) bool { |
| 15 | | const argv = &[_][]const u8{ "/usr/bin/xcode-select", "--print-path" }; |
| 16 | | const result = std.ChildProcess.exec(.{ .allocator = allocator, .argv = argv }) catch return false; |
| 16 | const result = std.process.Child.exec(.{ |
| 17 | .allocator = allocator, |
| 18 | .argv = &.{ "/usr/bin/xcode-select", "--print-path" }, |
| 19 | }) catch return false; |
| 20 | |
| 17 | 21 | defer { |
| 18 | 22 | allocator.free(result.stderr); |
| 19 | 23 | allocator.free(result.stdout); |
| 20 | 24 | } |
| 21 | | if (result.stderr.len != 0 or result.term.Exited != 0) { |
| 22 | | // We don't actually care if there were errors as this is best-effort check anyhow. |
| 23 | | return false; |
| 24 | | } |
| 25 | | return result.stdout.len > 0; |
| 25 | |
| 26 | return switch (result.term) { |
| 27 | .Exited => |code| if (code == 0) result.stdout.len > 0 else false, |
| 28 | else => false, |
| 29 | }; |
| 26 | 30 | } |
| 27 | 31 | |
| 28 | 32 | /// Detect SDK on Darwin. |
| 29 | 33 | /// Calls `xcrun --sdk <target_sdk> --show-sdk-path` which fetches the path to the SDK sysroot (if any). |
| 30 | 34 | /// Subsequently calls `xcrun --sdk <target_sdk> --show-sdk-version` which fetches version of the SDK. |
| 31 | 35 | /// The caller needs to deinit the resulting struct. |
| 36 | /// stderr from xcrun is ignored. |
| 37 | /// If error.OutOfMemory occurs in Allocator, this function returns null. |
| 32 | 38 | pub fn getSdk(allocator: Allocator, target: Target) ?Sdk { |
| 33 | 39 | const is_simulator_abi = target.abi == .simulator; |
| 34 | 40 | const sdk = switch (target.os.tag) { |
| ... | ... | @@ -40,30 +46,28 @@ pub fn getSdk(allocator: Allocator, target: Target) ?Sdk { |
| 40 | 46 | }; |
| 41 | 47 | const path = path: { |
| 42 | 48 | const argv = &[_][]const u8{ "/usr/bin/xcrun", "--sdk", sdk, "--show-sdk-path" }; |
| 43 | | const result = std.ChildProcess.exec(.{ .allocator = allocator, .argv = argv }) catch return null; |
| 49 | const result = std.process.Child.exec(.{ .allocator = allocator, .argv = argv }) catch return null; |
| 44 | 50 | defer { |
| 45 | 51 | allocator.free(result.stderr); |
| 46 | 52 | allocator.free(result.stdout); |
| 47 | 53 | } |
| 48 | | if (result.stderr.len != 0 or result.term.Exited != 0) { |
| 49 | | // We don't actually care if there were errors as this is best-effort check anyhow |
| 50 | | // and in the worst case the user can specify the sysroot manually. |
| 51 | | return null; |
| 54 | switch (result.term) { |
| 55 | .Exited => |code| if (code != 0) return null, |
| 56 | else => return null, |
| 52 | 57 | } |
| 53 | 58 | const path = allocator.dupe(u8, mem.trimRight(u8, result.stdout, "\r\n")) catch return null; |
| 54 | 59 | break :path path; |
| 55 | 60 | }; |
| 56 | 61 | const version = version: { |
| 57 | 62 | const argv = &[_][]const u8{ "/usr/bin/xcrun", "--sdk", sdk, "--show-sdk-version" }; |
| 58 | | const result = std.ChildProcess.exec(.{ .allocator = allocator, .argv = argv }) catch return null; |
| 63 | const result = std.process.Child.exec(.{ .allocator = allocator, .argv = argv }) catch return null; |
| 59 | 64 | defer { |
| 60 | 65 | allocator.free(result.stderr); |
| 61 | 66 | allocator.free(result.stdout); |
| 62 | 67 | } |
| 63 | | if (result.stderr.len != 0 or result.term.Exited != 0) { |
| 64 | | // We don't actually care if there were errors as this is best-effort check anyhow |
| 65 | | // and in the worst case the user can specify the sysroot manually. |
| 66 | | return null; |
| 68 | switch (result.term) { |
| 69 | .Exited => |code| if (code != 0) return null, |
| 70 | else => return null, |
| 67 | 71 | } |
| 68 | 72 | const raw_version = mem.trimRight(u8, result.stdout, "\r\n"); |
| 69 | 73 | const version = parseSdkVersion(raw_version) orelse Version{ |