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