aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2021-08-06 11:36:40 +0200
committerJakub Konka <kubkon@jakubkonka.com>2021-08-10 13:41:10 +0200
commite9bee08f8869bc97312f37a76cb00b98b8c6ee3d (patch)
treeb6d4b2e6153740ccb7f0503d13c7613a5a45f30b /src/main.zig
parent2371a63bd46cb1af7e3b9857136ea7677f6abdcc (diff)
downloadzig-e9bee08f8869bc97312f37a76cb00b98b8c6ee3d.tar.gz
zig-e9bee08f8869bc97312f37a76cb00b98b8c6ee3d.zip
Try audodetecting sysroot when building Darwin on Darwin
This is now no longer limited to targeting macOS natively but also tries to detect the sysroot when targeting different Apple platforms from macOS; for instance targeting iPhone Simulator from macOS. In this case, Zig will try detecting the SDK path by invoking `xcrun --sdk iphonesimulator --show-sdk-path`, and if the command fails because the SDK doesn't exist (case when having CLT installed only) or not having either Xcode or CLT installed, we simply return null signaling that the user has to provide the sysroot themselves.
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/main.zig b/src/main.zig
index 73c4560ddf..285b6d2316 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -1678,7 +1678,9 @@ fn buildOutputType(
want_native_include_dirs = true;
}
- if (sysroot == null and cross_target.isNativeOs() and
+ const is_darwin_on_darwin = (comptime std.Target.current.isDarwin()) and cross_target.isDarwin();
+
+ if (sysroot == null and (cross_target.isNativeOs() or is_darwin_on_darwin) and
(system_libs.items.len != 0 or want_native_include_dirs))
{
const paths = std.zig.system.NativePaths.detect(arena, target_info) catch |err| {
@@ -1689,16 +1691,18 @@ fn buildOutputType(
}
const has_sysroot = if (comptime std.Target.current.isDarwin()) outer: {
- const min = target_info.target.os.getVersionRange().semver.min;
- const at_least_mojave = min.major >= 11 or (min.major >= 10 and min.minor >= 14);
- if (at_least_mojave) {
- const sdk_path = try std.zig.system.getSDKPath(arena);
+ const should_get_sdk_path = if (cross_target.isNativeOs() and target_info.target.os.tag == .macos) inner: {
+ const min = target_info.target.os.getVersionRange().semver.min;
+ const at_least_mojave = min.major >= 11 or (min.major >= 10 and min.minor >= 14);
+ break :inner at_least_mojave;
+ } else true;
+ if (!should_get_sdk_path) break :outer false;
+ if (try std.zig.system.darwin.getSDKPath(arena, target_info.target)) |sdk_path| {
try clang_argv.ensureCapacity(clang_argv.items.len + 2);
clang_argv.appendAssumeCapacity("-isysroot");
clang_argv.appendAssumeCapacity(sdk_path);
break :outer true;
- }
- break :outer false;
+ } else break :outer false;
} else false;
try clang_argv.ensureCapacity(clang_argv.items.len + paths.include_dirs.items.len * 2);