| ... | ... | @@ -773,6 +773,8 @@ pub const InitOptions = struct { |
| 773 | 773 | wasi_exec_model: ?std.builtin.WasiExecModel = null, |
| 774 | 774 | /// (Zig compiler development) Enable dumping linker's state as JSON. |
| 775 | 775 | enable_link_snapshots: bool = false, |
| 776 | /// (Darwin). Path to native macOS SDK if detected. |
| 777 | native_macos_sdk_path: ?[]const u8 = null, |
| 776 | 778 | }; |
| 777 | 779 | |
| 778 | 780 | fn addPackageTableToCacheHash( |
| ... | ... | @@ -962,18 +964,11 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 962 | 964 | break :blk false; |
| 963 | 965 | }; |
| 964 | 966 | |
| 965 | | const darwin_use_system_sdk = blk: { |
| 966 | | if (comptime !builtin.target.isDarwin()) break :blk false; |
| 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; |
| 970 | | }; |
| 971 | | |
| 972 | 967 | const sysroot = blk: { |
| 973 | 968 | if (options.sysroot) |sysroot| { |
| 974 | 969 | break :blk sysroot; |
| 975 | | } else if (darwin_use_system_sdk) { |
| 976 | | break :blk try std.zig.system.darwin.getSDKPath(arena, options.target); |
| 970 | } else if (options.native_macos_sdk_path) |sdk_path| { |
| 971 | break :blk sdk_path; |
| 977 | 972 | } else { |
| 978 | 973 | break :blk null; |
| 979 | 974 | } |
| ... | ... | @@ -1060,6 +1055,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 1060 | 1055 | link_libc, |
| 1061 | 1056 | options.system_lib_names.len != 0 or options.frameworks.len != 0, |
| 1062 | 1057 | options.libc_installation, |
| 1058 | options.native_macos_sdk_path != null, |
| 1063 | 1059 | ); |
| 1064 | 1060 | |
| 1065 | 1061 | const must_pie = target_util.requiresPIE(options.target); |
| ... | ... | @@ -3776,6 +3772,37 @@ const LibCDirs = struct { |
| 3776 | 3772 | libc_installation: ?*const LibCInstallation, |
| 3777 | 3773 | }; |
| 3778 | 3774 | |
| 3775 | fn getZigShippedLibCIncludeDirsDarwin(arena: *Allocator, zig_lib_dir: []const u8, target: Target) !LibCDirs { |
| 3776 | const arch_name = @tagName(target.cpu.arch); |
| 3777 | const os_name = try std.fmt.allocPrint(arena, "{s}.{d}", .{ |
| 3778 | @tagName(target.os.tag), |
| 3779 | target.os.version_range.semver.min.major, |
| 3780 | }); |
| 3781 | const s = std.fs.path.sep_str; |
| 3782 | const list = try arena.alloc([]const u8, 3); |
| 3783 | |
| 3784 | list[0] = try std.fmt.allocPrint( |
| 3785 | arena, |
| 3786 | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-gnu", |
| 3787 | .{ zig_lib_dir, arch_name, os_name }, |
| 3788 | ); |
| 3789 | list[1] = try std.fmt.allocPrint( |
| 3790 | arena, |
| 3791 | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "any-{s}-any", |
| 3792 | .{ zig_lib_dir, os_name }, |
| 3793 | ); |
| 3794 | list[2] = try std.fmt.allocPrint( |
| 3795 | arena, |
| 3796 | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "any-macos-any", |
| 3797 | .{zig_lib_dir}, |
| 3798 | ); |
| 3799 | |
| 3800 | return LibCDirs{ |
| 3801 | .libc_include_dir_list = list, |
| 3802 | .libc_installation = null, |
| 3803 | }; |
| 3804 | } |
| 3805 | |
| 3779 | 3806 | fn detectLibCIncludeDirs( |
| 3780 | 3807 | arena: *Allocator, |
| 3781 | 3808 | zig_lib_dir: []const u8, |
| ... | ... | @@ -3784,6 +3811,7 @@ fn detectLibCIncludeDirs( |
| 3784 | 3811 | link_libc: bool, |
| 3785 | 3812 | link_system_libs: bool, |
| 3786 | 3813 | libc_installation: ?*const LibCInstallation, |
| 3814 | has_macos_sdk: bool, |
| 3787 | 3815 | ) !LibCDirs { |
| 3788 | 3816 | if (!link_libc) { |
| 3789 | 3817 | return LibCDirs{ |
| ... | ... | @@ -3800,11 +3828,14 @@ fn detectLibCIncludeDirs( |
| 3800 | 3828 | // using the system libc installation. |
| 3801 | 3829 | if (link_system_libs and is_native_abi and !target.isMinGW()) { |
| 3802 | 3830 | if (target.isDarwin()) { |
| 3803 | | // For Darwin/macOS, we are all set with getSDKPath found earlier. |
| 3804 | | return LibCDirs{ |
| 3805 | | .libc_include_dir_list = &[0][]u8{}, |
| 3806 | | .libc_installation = null, |
| 3807 | | }; |
| 3831 | return if (has_macos_sdk) |
| 3832 | // For Darwin/macOS, we are all set with getSDKPath found earlier. |
| 3833 | LibCDirs{ |
| 3834 | .libc_include_dir_list = &[0][]u8{}, |
| 3835 | .libc_installation = null, |
| 3836 | } |
| 3837 | else |
| 3838 | getZigShippedLibCIncludeDirsDarwin(arena, zig_lib_dir, target); |
| 3808 | 3839 | } |
| 3809 | 3840 | const libc = try arena.create(LibCInstallation); |
| 3810 | 3841 | libc.* = try LibCInstallation.findNative(.{ .allocator = arena, .verbose = true }); |
| ... | ... | @@ -3815,36 +3846,7 @@ fn detectLibCIncludeDirs( |
| 3815 | 3846 | // default if possible. |
| 3816 | 3847 | if (target_util.canBuildLibC(target)) { |
| 3817 | 3848 | switch (target.os.tag) { |
| 3818 | | .macos => { |
| 3819 | | const arch_name = @tagName(target.cpu.arch); |
| 3820 | | const os_name = try std.fmt.allocPrint(arena, "{s}.{d}", .{ |
| 3821 | | @tagName(target.os.tag), |
| 3822 | | target.os.version_range.semver.min.major, |
| 3823 | | }); |
| 3824 | | const s = std.fs.path.sep_str; |
| 3825 | | const list = try arena.alloc([]const u8, 3); |
| 3826 | | |
| 3827 | | list[0] = try std.fmt.allocPrint( |
| 3828 | | arena, |
| 3829 | | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-gnu", |
| 3830 | | .{ zig_lib_dir, arch_name, os_name }, |
| 3831 | | ); |
| 3832 | | list[1] = try std.fmt.allocPrint( |
| 3833 | | arena, |
| 3834 | | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "any-{s}-any", |
| 3835 | | .{ zig_lib_dir, os_name }, |
| 3836 | | ); |
| 3837 | | list[2] = try std.fmt.allocPrint( |
| 3838 | | arena, |
| 3839 | | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "any-macos-any", |
| 3840 | | .{zig_lib_dir}, |
| 3841 | | ); |
| 3842 | | |
| 3843 | | return LibCDirs{ |
| 3844 | | .libc_include_dir_list = list, |
| 3845 | | .libc_installation = null, |
| 3846 | | }; |
| 3847 | | }, |
| 3849 | .macos => return getZigShippedLibCIncludeDirsDarwin(arena, zig_lib_dir, target), |
| 3848 | 3850 | else => { |
| 3849 | 3851 | const generic_name = target_util.libCGenericName(target); |
| 3850 | 3852 | // Some architectures are handled by the same set of headers. |