authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-11-24 23:41:09+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-11-25 12:19:16+01:00
log1954cdc1066f2d59961e4cdd24a9d80fd6eb86c3
treea445b605f63b4951328ce6da925ce32a07296d05
parentc42439dff9bdfa1ff90e4243ec7eaad94f4241ca

Autofetch macOS SDK if native target on macOS only

This means that I am purposefully regressing linking iOS and related which will require manual specification of the sysroot path, etc.

2 files changed, 6 insertions(+), 14 deletions(-)

src/Compilation.zig+5-3
......@@ -962,15 +962,17 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
962962 break :blk false;
963963 };
964964
965 const darwin_can_use_system_sdk = blk: {
965 const darwin_use_system_sdk = blk: {
966966 if (comptime !builtin.target.isDarwin()) break :blk false;
967 break :blk builtin.os.tag == .macos and options.target.isDarwin();
967 if (!options.is_native_os) break :blk false;
968 if (builtin.os.tag != .macos or !options.target.isDarwin()) break :blk false;
969 break :blk options.frameworks.len > 0 or options.framework_dirs.len > 0;
968970 };
969971
970972 const sysroot = blk: {
971973 if (options.sysroot) |sysroot| {
972974 break :blk sysroot;
973 } else if (darwin_can_use_system_sdk) {
975 } else if (darwin_use_system_sdk) {
974976 break :blk try std.zig.system.darwin.getSDKPath(arena, options.target);
975977 } else {
976978 break :blk null;
src/main.zig+1-11
......@@ -1848,11 +1848,7 @@ fn buildOutputType(
18481848 want_native_include_dirs = true;
18491849 }
18501850
1851 const is_darwin_on_darwin = (comptime builtin.target.isDarwin()) and cross_target.isDarwin();
1852
1853 if (sysroot == null and (cross_target.isNativeOs() or is_darwin_on_darwin) and
1854 (system_libs.count() != 0 or want_native_include_dirs))
1855 {
1851 if (sysroot == null and cross_target.isNativeOs() and (system_libs.count() != 0 or want_native_include_dirs)) {
18561852 const paths = std.zig.system.NativePaths.detect(arena, target_info) catch |err| {
18571853 fatal("unable to detect native system paths: {s}", .{@errorName(err)});
18581854 };
......@@ -1861,12 +1857,6 @@ fn buildOutputType(
18611857 }
18621858
18631859 const has_sysroot = if (comptime builtin.target.isDarwin()) outer: {
1864 const should_get_sdk_path = if (cross_target.isNativeOs() and target_info.target.os.tag == .macos) inner: {
1865 const min = target_info.target.os.getVersionRange().semver.min;
1866 const at_least_mojave = min.major >= 11 or (min.major >= 10 and min.minor >= 14);
1867 break :inner at_least_mojave;
1868 } else true;
1869 if (!should_get_sdk_path) break :outer false;
18701860 if (try std.zig.system.darwin.getSDKPath(arena, target_info.target)) |sdk_path| {
18711861 try clang_argv.ensureUnusedCapacity(2);
18721862 clang_argv.appendAssumeCapacity("-isysroot");