| ... | @@ -637,8 +637,6 @@ pub const InitOptions = struct { | ... | @@ -637,8 +637,6 @@ pub const InitOptions = struct { |
| 637 | wasi_exec_model: ?std.builtin.WasiExecModel = null, | 637 | wasi_exec_model: ?std.builtin.WasiExecModel = null, |
| 638 | /// (Zig compiler development) Enable dumping linker's state as JSON. | 638 | /// (Zig compiler development) Enable dumping linker's state as JSON. |
| 639 | enable_link_snapshots: bool = false, | 639 | enable_link_snapshots: bool = false, |
| 640 | /// (Darwin) Path and version of the native SDK if detected. | | |
| 641 | native_darwin_sdk: ?std.zig.system.darwin.DarwinSDK = null, | | |
| 642 | /// (Darwin) Install name of the dylib | 640 | /// (Darwin) Install name of the dylib |
| 643 | install_name: ?[]const u8 = null, | 641 | install_name: ?[]const u8 = null, |
| 644 | /// (Darwin) Path to entitlements file | 642 | /// (Darwin) Path to entitlements file |
| ... | @@ -945,7 +943,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -945,7 +943,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 945 | options.is_native_abi, | 943 | options.is_native_abi, |
| 946 | link_libc, | 944 | link_libc, |
| 947 | options.libc_installation, | 945 | options.libc_installation, |
| 948 | options.native_darwin_sdk != null, | | |
| 949 | ); | 946 | ); |
| 950 | | 947 | |
| 951 | const must_pie = target_util.requiresPIE(options.target); | 948 | const must_pie = target_util.requiresPIE(options.target); |
| ... | @@ -1560,7 +1557,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -1560,7 +1557,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1560 | .wasi_exec_model = wasi_exec_model, | 1557 | .wasi_exec_model = wasi_exec_model, |
| 1561 | .hash_style = options.hash_style, | 1558 | .hash_style = options.hash_style, |
| 1562 | .enable_link_snapshots = options.enable_link_snapshots, | 1559 | .enable_link_snapshots = options.enable_link_snapshots, |
| 1563 | .native_darwin_sdk = options.native_darwin_sdk, | | |
| 1564 | .install_name = options.install_name, | 1560 | .install_name = options.install_name, |
| 1565 | .entitlements = options.entitlements, | 1561 | .entitlements = options.entitlements, |
| 1566 | .pagezero_size = options.pagezero_size, | 1562 | .pagezero_size = options.pagezero_size, |
| ... | @@ -4865,7 +4861,6 @@ fn detectLibCIncludeDirs( | ... | @@ -4865,7 +4861,6 @@ fn detectLibCIncludeDirs( |
| 4865 | is_native_abi: bool, | 4861 | is_native_abi: bool, |
| 4866 | link_libc: bool, | 4862 | link_libc: bool, |
| 4867 | libc_installation: ?*const LibCInstallation, | 4863 | libc_installation: ?*const LibCInstallation, |
| 4868 | has_macos_sdk: bool, | | |
| 4869 | ) !LibCDirs { | 4864 | ) !LibCDirs { |
| 4870 | if (!link_libc) { | 4865 | if (!link_libc) { |
| 4871 | return LibCDirs{ | 4866 | return LibCDirs{ |
| ... | @@ -4881,28 +4876,19 @@ fn detectLibCIncludeDirs( | ... | @@ -4881,28 +4876,19 @@ fn detectLibCIncludeDirs( |
| 4881 | // If linking system libraries and targeting the native abi, default to | 4876 | // If linking system libraries and targeting the native abi, default to |
| 4882 | // using the system libc installation. | 4877 | // using the system libc installation. |
| 4883 | if (is_native_abi and !target.isMinGW()) { | 4878 | if (is_native_abi and !target.isMinGW()) { |
| 4884 | if (target.isDarwin()) { | | |
| 4885 | return if (has_macos_sdk) | | |
| 4886 | // For Darwin/macOS, we are all set with getDarwinSDK found earlier. | | |
| 4887 | LibCDirs{ | | |
| 4888 | .libc_include_dir_list = &[0][]u8{}, | | |
| 4889 | .libc_installation = null, | | |
| 4890 | } | | |
| 4891 | else | | |
| 4892 | getZigShippedLibCIncludeDirsDarwin(arena, zig_lib_dir, target); | | |
| 4893 | } | | |
| 4894 | const libc = try arena.create(LibCInstallation); | 4879 | const libc = try arena.create(LibCInstallation); |
| 4895 | libc.* = LibCInstallation.findNative(.{ .allocator = arena }) catch |err| switch (err) { | 4880 | libc.* = LibCInstallation.findNative(.{ .allocator = arena, .target = target }) catch |err| switch (err) { |
| 4896 | error.CCompilerExitCode, | 4881 | error.CCompilerExitCode, |
| 4897 | error.CCompilerCrashed, | 4882 | error.CCompilerCrashed, |
| 4898 | error.CCompilerCannotFindHeaders, | 4883 | error.CCompilerCannotFindHeaders, |
| 4899 | error.UnableToSpawnCCompiler, | 4884 | error.UnableToSpawnCCompiler, |
| | 4885 | error.DarwinSdkNotFound, |
| 4900 | => |e| { | 4886 | => |e| { |
| 4901 | // We tried to integrate with the native system C compiler, | 4887 | // We tried to integrate with the native system C compiler, |
| 4902 | // however, it is not installed. So we must rely on our bundled | 4888 | // however, it is not installed. So we must rely on our bundled |
| 4903 | // libc files. | 4889 | // libc files. |
| 4904 | if (target_util.canBuildLibC(target)) { | 4890 | if (target_util.canBuildLibC(target)) { |
| 4905 | return detectLibCFromBuilding(arena, zig_lib_dir, target, has_macos_sdk); | 4891 | return detectLibCFromBuilding(arena, zig_lib_dir, target); |
| 4906 | } | 4892 | } |
| 4907 | return e; | 4893 | return e; |
| 4908 | }, | 4894 | }, |
| ... | @@ -4914,7 +4900,7 @@ fn detectLibCIncludeDirs( | ... | @@ -4914,7 +4900,7 @@ fn detectLibCIncludeDirs( |
| 4914 | // If not linking system libraries, build and provide our own libc by | 4900 | // If not linking system libraries, build and provide our own libc by |
| 4915 | // default if possible. | 4901 | // default if possible. |
| 4916 | if (target_util.canBuildLibC(target)) { | 4902 | if (target_util.canBuildLibC(target)) { |
| 4917 | return detectLibCFromBuilding(arena, zig_lib_dir, target, has_macos_sdk); | 4903 | return detectLibCFromBuilding(arena, zig_lib_dir, target); |
| 4918 | } | 4904 | } |
| 4919 | | 4905 | |
| 4920 | // If zig can't build the libc for the target and we are targeting the | 4906 | // If zig can't build the libc for the target and we are targeting the |
| ... | @@ -4928,7 +4914,7 @@ fn detectLibCIncludeDirs( | ... | @@ -4928,7 +4914,7 @@ fn detectLibCIncludeDirs( |
| 4928 | | 4914 | |
| 4929 | if (use_system_abi) { | 4915 | if (use_system_abi) { |
| 4930 | const libc = try arena.create(LibCInstallation); | 4916 | const libc = try arena.create(LibCInstallation); |
| 4931 | libc.* = try LibCInstallation.findNative(.{ .allocator = arena, .verbose = true }); | 4917 | libc.* = try LibCInstallation.findNative(.{ .allocator = arena, .verbose = true, .target = target }); |
| 4932 | return detectLibCFromLibCInstallation(arena, target, libc); | 4918 | return detectLibCFromLibCInstallation(arena, target, libc); |
| 4933 | } | 4919 | } |
| 4934 | | 4920 | |
| ... | @@ -4977,69 +4963,59 @@ fn detectLibCFromBuilding( | ... | @@ -4977,69 +4963,59 @@ fn detectLibCFromBuilding( |
| 4977 | arena: Allocator, | 4963 | arena: Allocator, |
| 4978 | zig_lib_dir: []const u8, | 4964 | zig_lib_dir: []const u8, |
| 4979 | target: std.Target, | 4965 | target: std.Target, |
| 4980 | has_macos_sdk: bool, | | |
| 4981 | ) !LibCDirs { | 4966 | ) !LibCDirs { |
| 4982 | switch (target.os.tag) { | 4967 | if (target.isDarwin()) |
| 4983 | .macos => return if (has_macos_sdk) | 4968 | return getZigShippedLibCIncludeDirsDarwin(arena, zig_lib_dir, target); |
| 4984 | // For Darwin/macOS, we are all set with getDarwinSDK found earlier. | 4969 | |
| 4985 | LibCDirs{ | 4970 | const generic_name = target_util.libCGenericName(target); |
| 4986 | .libc_include_dir_list = &[0][]u8{}, | 4971 | // Some architectures are handled by the same set of headers. |
| 4987 | .libc_installation = null, | 4972 | const arch_name = if (target.abi.isMusl()) |
| 4988 | } | 4973 | musl.archNameHeaders(target.cpu.arch) |
| 4989 | else | 4974 | else if (target.cpu.arch.isThumb()) |
| 4990 | getZigShippedLibCIncludeDirsDarwin(arena, zig_lib_dir, target), | 4975 | // ARM headers are valid for Thumb too. |
| 4991 | else => { | 4976 | switch (target.cpu.arch) { |
| 4992 | const generic_name = target_util.libCGenericName(target); | 4977 | .thumb => "arm", |
| 4993 | // Some architectures are handled by the same set of headers. | 4978 | .thumbeb => "armeb", |
| 4994 | const arch_name = if (target.abi.isMusl()) | 4979 | else => unreachable, |
| 4995 | musl.archNameHeaders(target.cpu.arch) | 4980 | } |
| 4996 | else if (target.cpu.arch.isThumb()) | 4981 | else |
| 4997 | // ARM headers are valid for Thumb too. | 4982 | @tagName(target.cpu.arch); |
| 4998 | switch (target.cpu.arch) { | 4983 | const os_name = @tagName(target.os.tag); |
| 4999 | .thumb => "arm", | 4984 | // Musl's headers are ABI-agnostic and so they all have the "musl" ABI name. |
| 5000 | .thumbeb => "armeb", | 4985 | const abi_name = if (target.abi.isMusl()) "musl" else @tagName(target.abi); |
| 5001 | else => unreachable, | 4986 | const s = std.fs.path.sep_str; |
| 5002 | } | 4987 | const arch_include_dir = try std.fmt.allocPrint( |
| 5003 | else | 4988 | arena, |
| 5004 | @tagName(target.cpu.arch); | 4989 | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-{s}", |
| 5005 | const os_name = @tagName(target.os.tag); | 4990 | .{ zig_lib_dir, arch_name, os_name, abi_name }, |
| 5006 | // Musl's headers are ABI-agnostic and so they all have the "musl" ABI name. | 4991 | ); |
| 5007 | const abi_name = if (target.abi.isMusl()) "musl" else @tagName(target.abi); | 4992 | const generic_include_dir = try std.fmt.allocPrint( |
| 5008 | const s = std.fs.path.sep_str; | 4993 | arena, |
| 5009 | const arch_include_dir = try std.fmt.allocPrint( | 4994 | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "generic-{s}", |
| 5010 | arena, | 4995 | .{ zig_lib_dir, generic_name }, |
| 5011 | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-{s}", | 4996 | ); |
| 5012 | .{ zig_lib_dir, arch_name, os_name, abi_name }, | 4997 | const generic_arch_name = target_util.osArchName(target); |
| 5013 | ); | 4998 | const arch_os_include_dir = try std.fmt.allocPrint( |
| 5014 | const generic_include_dir = try std.fmt.allocPrint( | 4999 | arena, |
| 5015 | arena, | 5000 | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-any", |
| 5016 | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "generic-{s}", | 5001 | .{ zig_lib_dir, generic_arch_name, os_name }, |
| 5017 | .{ zig_lib_dir, generic_name }, | 5002 | ); |
| 5018 | ); | 5003 | const generic_os_include_dir = try std.fmt.allocPrint( |
| 5019 | const generic_arch_name = target_util.osArchName(target); | 5004 | arena, |
| 5020 | const arch_os_include_dir = try std.fmt.allocPrint( | 5005 | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "any-{s}-any", |
| 5021 | arena, | 5006 | .{ zig_lib_dir, os_name }, |
| 5022 | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-any", | 5007 | ); |
| 5023 | .{ zig_lib_dir, generic_arch_name, os_name }, | | |
| 5024 | ); | | |
| 5025 | const generic_os_include_dir = try std.fmt.allocPrint( | | |
| 5026 | arena, | | |
| 5027 | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "any-{s}-any", | | |
| 5028 | .{ zig_lib_dir, os_name }, | | |
| 5029 | ); | | |
| 5030 | | 5008 | |
| 5031 | const list = try arena.alloc([]const u8, 4); | 5009 | const list = try arena.alloc([]const u8, 4); |
| 5032 | list[0] = arch_include_dir; | 5010 | list[0] = arch_include_dir; |
| 5033 | list[1] = generic_include_dir; | 5011 | list[1] = generic_include_dir; |
| 5034 | list[2] = arch_os_include_dir; | 5012 | list[2] = arch_os_include_dir; |
| 5035 | list[3] = generic_os_include_dir; | 5013 | list[3] = generic_os_include_dir; |
| 5036 | | 5014 | |
| 5037 | return LibCDirs{ | 5015 | return LibCDirs{ |
| 5038 | .libc_include_dir_list = list, | 5016 | .libc_include_dir_list = list, |
| 5039 | .libc_installation = null, | 5017 | .libc_installation = null, |
| 5040 | }; | 5018 | }; |
| 5041 | }, | | |
| 5042 | } | | |
| 5043 | } | 5019 | } |
| 5044 | | 5020 | |
| 5045 | pub fn get_libc_crt_file(comp: *Compilation, arena: Allocator, basename: []const u8) ![]const u8 { | 5021 | pub fn get_libc_crt_file(comp: *Compilation, arena: Allocator, basename: []const u8) ![]const u8 { |