| ... | @@ -773,6 +773,8 @@ pub const InitOptions = struct { | ... | @@ -773,6 +773,8 @@ pub const InitOptions = struct { |
| 773 | wasi_exec_model: ?std.builtin.WasiExecModel = null, | 773 | wasi_exec_model: ?std.builtin.WasiExecModel = null, |
| 774 | /// (Zig compiler development) Enable dumping linker's state as JSON. | 774 | /// (Zig compiler development) Enable dumping linker's state as JSON. |
| 775 | enable_link_snapshots: bool = false, | 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 | fn addPackageTableToCacheHash( | 780 | fn addPackageTableToCacheHash( |
| ... | @@ -962,18 +964,11 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -962,18 +964,11 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 962 | break :blk false; | 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 | const sysroot = blk: { | 967 | const sysroot = blk: { |
| 973 | if (options.sysroot) |sysroot| { | 968 | if (options.sysroot) |sysroot| { |
| 974 | break :blk sysroot; | 969 | break :blk sysroot; |
| 975 | } else if (darwin_use_system_sdk) { | 970 | } else if (options.native_macos_sdk_path) |sdk_path| { |
| 976 | break :blk try std.zig.system.darwin.getSDKPath(arena, options.target); | 971 | break :blk sdk_path; |
| 977 | } else { | 972 | } else { |
| 978 | break :blk null; | 973 | break :blk null; |
| 979 | } | 974 | } |
| ... | @@ -1060,6 +1055,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -1060,6 +1055,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 1060 | link_libc, | 1055 | link_libc, |
| 1061 | options.system_lib_names.len != 0 or options.frameworks.len != 0, | 1056 | options.system_lib_names.len != 0 or options.frameworks.len != 0, |
| 1062 | options.libc_installation, | 1057 | options.libc_installation, |
| | 1058 | options.native_macos_sdk_path != null, |
| 1063 | ); | 1059 | ); |
| 1064 | | 1060 | |
| 1065 | const must_pie = target_util.requiresPIE(options.target); | 1061 | const must_pie = target_util.requiresPIE(options.target); |
| ... | @@ -3776,6 +3772,37 @@ const LibCDirs = struct { | ... | @@ -3776,6 +3772,37 @@ const LibCDirs = struct { |
| 3776 | libc_installation: ?*const LibCInstallation, | 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 | fn detectLibCIncludeDirs( | 3806 | fn detectLibCIncludeDirs( |
| 3780 | arena: *Allocator, | 3807 | arena: *Allocator, |
| 3781 | zig_lib_dir: []const u8, | 3808 | zig_lib_dir: []const u8, |
| ... | @@ -3784,6 +3811,7 @@ fn detectLibCIncludeDirs( | ... | @@ -3784,6 +3811,7 @@ fn detectLibCIncludeDirs( |
| 3784 | link_libc: bool, | 3811 | link_libc: bool, |
| 3785 | link_system_libs: bool, | 3812 | link_system_libs: bool, |
| 3786 | libc_installation: ?*const LibCInstallation, | 3813 | libc_installation: ?*const LibCInstallation, |
| | 3814 | has_macos_sdk: bool, |
| 3787 | ) !LibCDirs { | 3815 | ) !LibCDirs { |
| 3788 | if (!link_libc) { | 3816 | if (!link_libc) { |
| 3789 | return LibCDirs{ | 3817 | return LibCDirs{ |
| ... | @@ -3800,11 +3828,14 @@ fn detectLibCIncludeDirs( | ... | @@ -3800,11 +3828,14 @@ fn detectLibCIncludeDirs( |
| 3800 | // using the system libc installation. | 3828 | // using the system libc installation. |
| 3801 | if (link_system_libs and is_native_abi and !target.isMinGW()) { | 3829 | if (link_system_libs and is_native_abi and !target.isMinGW()) { |
| 3802 | if (target.isDarwin()) { | 3830 | if (target.isDarwin()) { |
| 3803 | // For Darwin/macOS, we are all set with getSDKPath found earlier. | 3831 | return if (has_macos_sdk) |
| 3804 | return LibCDirs{ | 3832 | // For Darwin/macOS, we are all set with getSDKPath found earlier. |
| 3805 | .libc_include_dir_list = &[0][]u8{}, | 3833 | LibCDirs{ |
| 3806 | .libc_installation = null, | 3834 | .libc_include_dir_list = &[0][]u8{}, |
| 3807 | }; | 3835 | .libc_installation = null, |
| | 3836 | } |
| | 3837 | else |
| | 3838 | getZigShippedLibCIncludeDirsDarwin(arena, zig_lib_dir, target); |
| 3808 | } | 3839 | } |
| 3809 | const libc = try arena.create(LibCInstallation); | 3840 | const libc = try arena.create(LibCInstallation); |
| 3810 | libc.* = try LibCInstallation.findNative(.{ .allocator = arena, .verbose = true }); | 3841 | libc.* = try LibCInstallation.findNative(.{ .allocator = arena, .verbose = true }); |
| ... | @@ -3815,36 +3846,7 @@ fn detectLibCIncludeDirs( | ... | @@ -3815,36 +3846,7 @@ fn detectLibCIncludeDirs( |
| 3815 | // default if possible. | 3846 | // default if possible. |
| 3816 | if (target_util.canBuildLibC(target)) { | 3847 | if (target_util.canBuildLibC(target)) { |
| 3817 | switch (target.os.tag) { | 3848 | switch (target.os.tag) { |
| 3818 | .macos => { | 3849 | .macos => return getZigShippedLibCIncludeDirsDarwin(arena, zig_lib_dir, target), |
| 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 | }, | | |
| 3848 | else => { | 3850 | else => { |
| 3849 | const generic_name = target_util.libCGenericName(target); | 3851 | const generic_name = target_util.libCGenericName(target); |
| 3850 | // Some architectures are handled by the same set of headers. | 3852 | // Some architectures are handled by the same set of headers. |