Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

getSdk

Detect SDK on Darwin. Calls xcrun --sdk <target_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.

darwin.getSdk
pub fn getSdk(gpa: Allocator, io: Io, target: *const Target) ?[]const u8

File

lib/std/zig/system/darwin.zig:38

Code

pub fn getSdk(gpa: Allocator, io: Io, target: *const Target) ?[]const u8 {
    const is_simulator_abi = target.abi == .simulator;
    const sdk = switch (target.os.tag) {
        .driverkit => "driverkit",
        .ios => if (is_simulator_abi) "iphonesimulator" else "iphoneos",
        .maccatalyst, .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.run(gpa, io, .{ .argv = argv }) catch return null;
    defer {
        gpa.free(result.stderr);
        gpa.free(result.stdout);
    }
    switch (result.term) {
        .exited => |code| if (code != 0) return null,
        else => return null,
    }
    return gpa.dupe(u8, mem.trimEnd(u8, result.stdout, "\r\n")) catch null;
}