mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 14:25:16 +00:00
infer and match macos sdk version for libc headers
This commit is contained in:
parent
2dcfa486fe
commit
42a351e099
@ -269,7 +269,7 @@ pub const Target = struct {
|
||||
.macos => return .{
|
||||
.semver = .{
|
||||
.min = .{ .major = 10, .minor = 13 },
|
||||
.max = .{ .major = 11, .minor = 2 },
|
||||
.max = .{ .major = 12, .minor = 0 },
|
||||
},
|
||||
},
|
||||
.ios => return .{
|
||||
|
||||
@ -3798,53 +3798,88 @@ fn detectLibCIncludeDirs(
|
||||
// If not linking system libraries, build and provide our own libc by
|
||||
// default if possible.
|
||||
if (target_util.canBuildLibC(target)) {
|
||||
const generic_name = target_util.libCGenericName(target);
|
||||
// Some architectures are handled by the same set of headers.
|
||||
const arch_name = if (target.abi.isMusl())
|
||||
musl.archName(target.cpu.arch)
|
||||
else if (target.cpu.arch.isThumb())
|
||||
// ARM headers are valid for Thumb too.
|
||||
switch (target.cpu.arch) {
|
||||
.thumb => "arm",
|
||||
.thumbeb => "armeb",
|
||||
else => unreachable,
|
||||
}
|
||||
else
|
||||
@tagName(target.cpu.arch);
|
||||
const os_name = @tagName(target.os.tag);
|
||||
// Musl's headers are ABI-agnostic and so they all have the "musl" ABI name.
|
||||
const abi_name = if (target.abi.isMusl()) "musl" else @tagName(target.abi);
|
||||
const s = std.fs.path.sep_str;
|
||||
const arch_include_dir = try std.fmt.allocPrint(
|
||||
arena,
|
||||
"{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-{s}",
|
||||
.{ zig_lib_dir, arch_name, os_name, abi_name },
|
||||
);
|
||||
const generic_include_dir = try std.fmt.allocPrint(
|
||||
arena,
|
||||
"{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "generic-{s}",
|
||||
.{ zig_lib_dir, generic_name },
|
||||
);
|
||||
const arch_os_include_dir = try std.fmt.allocPrint(
|
||||
arena,
|
||||
"{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-any",
|
||||
.{ zig_lib_dir, @tagName(target.cpu.arch), os_name },
|
||||
);
|
||||
const generic_os_include_dir = try std.fmt.allocPrint(
|
||||
arena,
|
||||
"{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "any-{s}-any",
|
||||
.{ zig_lib_dir, os_name },
|
||||
);
|
||||
switch (target.os.tag) {
|
||||
.macos => {
|
||||
const arch_name = @tagName(target.cpu.arch);
|
||||
const os_name = try std.fmt.allocPrint(arena, "{s}.{d}", .{
|
||||
@tagName(target.os.tag),
|
||||
target.os.version_range.semver.min.major,
|
||||
});
|
||||
const s = std.fs.path.sep_str;
|
||||
const list = try arena.alloc([]const u8, 3);
|
||||
|
||||
const list = try arena.alloc([]const u8, 4);
|
||||
list[0] = arch_include_dir;
|
||||
list[1] = generic_include_dir;
|
||||
list[2] = arch_os_include_dir;
|
||||
list[3] = generic_os_include_dir;
|
||||
return LibCDirs{
|
||||
.libc_include_dir_list = list,
|
||||
.libc_installation = null,
|
||||
};
|
||||
list[0] = try std.fmt.allocPrint(
|
||||
arena,
|
||||
"{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-gnu",
|
||||
.{ zig_lib_dir, arch_name, os_name },
|
||||
);
|
||||
list[1] = try std.fmt.allocPrint(
|
||||
arena,
|
||||
"{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "any-{s}-any",
|
||||
.{ zig_lib_dir, os_name },
|
||||
);
|
||||
list[2] = try std.fmt.allocPrint(
|
||||
arena,
|
||||
"{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "any-macos-any",
|
||||
.{zig_lib_dir},
|
||||
);
|
||||
|
||||
return LibCDirs{
|
||||
.libc_include_dir_list = list,
|
||||
.libc_installation = null,
|
||||
};
|
||||
},
|
||||
else => {
|
||||
const generic_name = target_util.libCGenericName(target);
|
||||
// Some architectures are handled by the same set of headers.
|
||||
const arch_name = if (target.abi.isMusl())
|
||||
musl.archName(target.cpu.arch)
|
||||
else if (target.cpu.arch.isThumb())
|
||||
// ARM headers are valid for Thumb too.
|
||||
switch (target.cpu.arch) {
|
||||
.thumb => "arm",
|
||||
.thumbeb => "armeb",
|
||||
else => unreachable,
|
||||
}
|
||||
else
|
||||
@tagName(target.cpu.arch);
|
||||
const os_name = @tagName(target.os.tag);
|
||||
// Musl's headers are ABI-agnostic and so they all have the "musl" ABI name.
|
||||
const abi_name = if (target.abi.isMusl()) "musl" else @tagName(target.abi);
|
||||
const s = std.fs.path.sep_str;
|
||||
const arch_include_dir = try std.fmt.allocPrint(
|
||||
arena,
|
||||
"{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-{s}",
|
||||
.{ zig_lib_dir, arch_name, os_name, abi_name },
|
||||
);
|
||||
const generic_include_dir = try std.fmt.allocPrint(
|
||||
arena,
|
||||
"{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "generic-{s}",
|
||||
.{ zig_lib_dir, generic_name },
|
||||
);
|
||||
const arch_os_include_dir = try std.fmt.allocPrint(
|
||||
arena,
|
||||
"{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-any",
|
||||
.{ zig_lib_dir, @tagName(target.cpu.arch), os_name },
|
||||
);
|
||||
const generic_os_include_dir = try std.fmt.allocPrint(
|
||||
arena,
|
||||
"{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "any-{s}-any",
|
||||
.{ zig_lib_dir, os_name },
|
||||
);
|
||||
|
||||
const list = try arena.alloc([]const u8, 4);
|
||||
list[0] = arch_include_dir;
|
||||
list[1] = generic_include_dir;
|
||||
list[2] = arch_os_include_dir;
|
||||
list[3] = generic_os_include_dir;
|
||||
|
||||
return LibCDirs{
|
||||
.libc_include_dir_list = list,
|
||||
.libc_installation = null,
|
||||
};
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// If zig can't build the libc for the target and we are targeting the
|
||||
|
||||
@ -5,6 +5,7 @@ pub const ArchOsAbi = struct {
|
||||
arch: std.Target.Cpu.Arch,
|
||||
os: std.Target.Os.Tag,
|
||||
abi: std.Target.Abi,
|
||||
os_ver: ?std.builtin.Version = null,
|
||||
};
|
||||
|
||||
pub const available_libcs = [_]ArchOsAbi{
|
||||
@ -14,7 +15,8 @@ pub const available_libcs = [_]ArchOsAbi{
|
||||
.{ .arch = .aarch64, .os = .linux, .abi = .gnu },
|
||||
.{ .arch = .aarch64, .os = .linux, .abi = .musl },
|
||||
.{ .arch = .aarch64, .os = .windows, .abi = .gnu },
|
||||
.{ .arch = .aarch64, .os = .macos, .abi = .gnu },
|
||||
.{ .arch = .aarch64, .os = .macos, .abi = .gnu, .os_ver = .{ .major = 11, .minor = 0 } },
|
||||
.{ .arch = .aarch64, .os = .macos, .abi = .gnu, .os_ver = .{ .major = 12, .minor = 0 } },
|
||||
.{ .arch = .armeb, .os = .linux, .abi = .gnueabi },
|
||||
.{ .arch = .armeb, .os = .linux, .abi = .gnueabihf },
|
||||
.{ .arch = .armeb, .os = .linux, .abi = .musleabi },
|
||||
@ -64,7 +66,9 @@ pub const available_libcs = [_]ArchOsAbi{
|
||||
.{ .arch = .x86_64, .os = .linux, .abi = .gnux32 },
|
||||
.{ .arch = .x86_64, .os = .linux, .abi = .musl },
|
||||
.{ .arch = .x86_64, .os = .windows, .abi = .gnu },
|
||||
.{ .arch = .x86_64, .os = .macos, .abi = .gnu },
|
||||
.{ .arch = .x86_64, .os = .macos, .abi = .gnu, .os_ver = .{ .major = 10, .minor = 0 } },
|
||||
.{ .arch = .x86_64, .os = .macos, .abi = .gnu, .os_ver = .{ .major = 11, .minor = 0 } },
|
||||
.{ .arch = .x86_64, .os = .macos, .abi = .gnu, .os_ver = .{ .major = 12, .minor = 0 } },
|
||||
};
|
||||
|
||||
pub fn libCGenericName(target: std.Target) [:0]const u8 {
|
||||
@ -105,6 +109,10 @@ pub fn libCGenericName(target: std.Target) [:0]const u8 {
|
||||
pub fn canBuildLibC(target: std.Target) bool {
|
||||
for (available_libcs) |libc| {
|
||||
if (target.cpu.arch == libc.arch and target.os.tag == libc.os and target.abi == libc.abi) {
|
||||
if (target.os.tag == .macos) {
|
||||
const ver = target.os.version_range.semver;
|
||||
if (ver.min.major != libc.os_ver.?.major) continue; // no match, keep going
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user