aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Compilation.zig142
-rw-r--r--src/libc_installation.zig4
-rw-r--r--src/link/MachO.zig5
-rw-r--r--src/main.zig12
-rw-r--r--src/stage1/codegen.cpp2
-rw-r--r--src/target.zig12
6 files changed, 112 insertions, 65 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 15b8f7c3f2..9da855789f 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -962,15 +962,17 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
break :blk false;
};
- const darwin_can_use_system_sdk = blk: {
+ const darwin_use_system_sdk = blk: {
if (comptime !builtin.target.isDarwin()) break :blk false;
- break :blk builtin.os.tag == .macos and options.target.isDarwin();
+ if (!options.is_native_os) break :blk false;
+ if (builtin.os.tag != .macos or !options.target.isDarwin()) break :blk false;
+ break :blk options.frameworks.len > 0 or options.framework_dirs.len > 0;
};
const sysroot = blk: {
if (options.sysroot) |sysroot| {
break :blk sysroot;
- } else if (darwin_can_use_system_sdk) {
+ } else if (darwin_use_system_sdk) {
break :blk try std.zig.system.darwin.getSDKPath(arena, options.target);
} else {
break :blk null;
@@ -3790,6 +3792,13 @@ fn detectLibCIncludeDirs(
// If linking system libraries and targeting the native abi, default to
// using the system libc installation.
if (link_system_libs and is_native_abi and !target.isMinGW()) {
+ if (target.isDarwin()) {
+ // For Darwin/macOS, we are all set with getSDKPath found earlier.
+ return LibCDirs{
+ .libc_include_dir_list = &[0][]u8{},
+ .libc_installation = null,
+ };
+ }
const libc = try arena.create(LibCInstallation);
libc.* = try LibCInstallation.findNative(.{ .allocator = arena, .verbose = true });
return detectLibCFromLibCInstallation(arena, target, libc);
@@ -3798,53 +3807,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
diff --git a/src/libc_installation.zig b/src/libc_installation.zig
index 3567f2e22f..615f9436e6 100644
--- a/src/libc_installation.zig
+++ b/src/libc_installation.zig
@@ -185,7 +185,9 @@ pub const LibCInstallation = struct {
pub fn findNative(args: FindNativeOptions) FindError!LibCInstallation {
var self: LibCInstallation = .{};
- if (is_windows) {
+ if (is_darwin) {
+ @panic("Darwin is handled separately via std.zig.system.darwin module");
+ } else if (is_windows) {
if (!build_options.have_llvm)
return error.WindowsSdkNotFound;
var sdk: *ZigWindowsSDK = undefined;
diff --git a/src/link/MachO.zig b/src/link/MachO.zig
index 483c5c8371..4d5133a959 100644
--- a/src/link/MachO.zig
+++ b/src/link/MachO.zig
@@ -727,8 +727,11 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
}
}
if (!libsystem_available) {
+ const libsystem_name = try std.fmt.allocPrint(arena, "libSystem.{d}.tbd", .{
+ self.base.options.target.os.version_range.semver.min.major,
+ });
const full_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
- "libc", "darwin", "libSystem.B.tbd",
+ "libc", "darwin", libsystem_name,
});
try libs.append(full_path);
}
diff --git a/src/main.zig b/src/main.zig
index 87086bf874..20ea5caded 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -1848,11 +1848,7 @@ fn buildOutputType(
want_native_include_dirs = true;
}
- const is_darwin_on_darwin = (comptime builtin.target.isDarwin()) and cross_target.isDarwin();
-
- if (sysroot == null and (cross_target.isNativeOs() or is_darwin_on_darwin) and
- (system_libs.count() != 0 or want_native_include_dirs))
- {
+ if (sysroot == null and cross_target.isNativeOs() and (system_libs.count() != 0 or want_native_include_dirs)) {
const paths = std.zig.system.NativePaths.detect(arena, target_info) catch |err| {
fatal("unable to detect native system paths: {s}", .{@errorName(err)});
};
@@ -1861,12 +1857,6 @@ fn buildOutputType(
}
const has_sysroot = if (comptime builtin.target.isDarwin()) outer: {
- const should_get_sdk_path = if (cross_target.isNativeOs() and target_info.target.os.tag == .macos) inner: {
- const min = target_info.target.os.getVersionRange().semver.min;
- const at_least_mojave = min.major >= 11 or (min.major >= 10 and min.minor >= 14);
- break :inner at_least_mojave;
- } else true;
- if (!should_get_sdk_path) break :outer false;
if (try std.zig.system.darwin.getSDKPath(arena, target_info.target)) |sdk_path| {
try clang_argv.ensureUnusedCapacity(2);
clang_argv.appendAssumeCapacity("-isysroot");
diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp
index 76e9b3edc2..163813194b 100644
--- a/src/stage1/codegen.cpp
+++ b/src/stage1/codegen.cpp
@@ -9305,7 +9305,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
buf_appendf(contents, "pub const abi = std.Target.Abi.%s;\n", cur_abi);
buf_appendf(contents, "pub const cpu = std.Target.Cpu.baseline(.%s);\n", cur_arch);
buf_appendf(contents, "pub const stage2_arch: std.Target.Cpu.Arch = .%s;\n", cur_arch);
- buf_appendf(contents, "pub const os = std.Target.Os.Tag.defaultVersionRange(.%s);\n", cur_os);
+ buf_appendf(contents, "pub const os = std.Target.Os.Tag.defaultVersionRange(.%s, .%s);\n", cur_os, cur_arch);
buf_appendf(contents,
"pub const target = std.Target{\n"
" .cpu = cpu,\n"
diff --git a/src/target.zig b/src/target.zig
index 6b6ed2fbc5..6f6d9f811d 100644
--- a/src/target.zig
+++ b/src/target.zig
@@ -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;
}
}