We already have a LICENSE file that covers the Zig Standard Library. We no longer need to remind everyone that the license is MIT in every single file. Previously this was introduced to clarify the situation for a fork of Zig that made Zig's LICENSE file harder to find, and replaced it with their own license that required annual payments to their company. However that fork now appears to be dead. So there is no need to reinforce the copyright notice in every single file.
40 lines
1.5 KiB
Zig
40 lines
1.5 KiB
Zig
const std = @import("std");
|
|
const mem = std.mem;
|
|
const Allocator = mem.Allocator;
|
|
const Target = std.Target;
|
|
|
|
pub const macos = @import("darwin/macos.zig");
|
|
|
|
/// Detect SDK path on Darwin.
|
|
/// Calls `xcrun --sdk <target_sdk> --show-sdk-path` which result can be used to specify
|
|
/// `--sysroot` of the compiler.
|
|
/// The caller needs to free the resulting path slice.
|
|
pub fn getSDKPath(allocator: *Allocator, target: Target) !?[]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{ "xcrun", "--sdk", sdk, "--show-sdk-path" };
|
|
const result = try std.ChildProcess.exec(.{ .allocator = allocator, .argv = argv });
|
|
defer {
|
|
allocator.free(result.stderr);
|
|
allocator.free(result.stdout);
|
|
}
|
|
if (result.stderr.len != 0 or result.term.Exited != 0) {
|
|
// We don't actually care if there were errors as this is best-effort check anyhow
|
|
// and in the worst case the user can specify the sysroot manually.
|
|
return null;
|
|
}
|
|
const sysroot = try allocator.dupe(u8, mem.trimRight(u8, result.stdout, "\r\n"));
|
|
return sysroot;
|
|
}
|
|
|
|
test "" {
|
|
_ = @import("darwin/macos.zig");
|
|
}
|