Function getSdk [src]

Detect SDK on Darwin. Calls xcrun --sdk --show-sdk-path which fetches the path to the SDK. Caller owns the memory. stderr from xcrun is ignored. If error.OutOfMemory occurs in Allocator, this function returns null.

Prototype

pub fn getSdk(allocator: Allocator, target: Target) ?[]const u8

Parameters

allocator: Allocatortarget: Target

Source

pub fn getSdk(allocator: Allocator, target: Target) ?[]const u8 { const is_simulator_abi = target.abi == .simulator; const sdk = switch (target.os.tag) { .ios => switch (target.abi) { .macabi => "macosx", .simulator => "iphonesimulator", else => "iphoneos", }, .driverkit => "driverkit", .macos => "macosx", .tvos => if (is_simulator_abi) "appletvsimulator" else "appletvos", .visionos => if (is_simulator_abi) "xrsimulator" else "xros", .watchos => if (is_simulator_abi) "watchsimulator" else "watchos", else => return null, }; const argv = &[_][]const u8{ "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; }