From 197ffff0b8d1c5257d66775d4cc46bcbfd570a90 Mon Sep 17 00:00:00 2001 From: Michael Dusan Date: Wed, 13 Mar 2024 02:17:28 -0400 Subject: [PATCH] macos: add tbd-v3 zippered support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Support linking against tbd-v3 SDKs such as those bundled with Xcode 10.3 → 11.3.1 . - Map target os=`ios` and abi=`macabi` to macho.PLATFORM.MACCATALYST. This allows for matches against tbdv4 targets, eg. `x86_64-maccatalyst`. - When parsing old tbdv3 files with `zippered` platform, we append [`ARCH-macos`, `ARCH-maccatalyst`] to list of "tbd" targets. This enables linking for standard targets like `ARCH-macos-none` and maccatalyst targets `ARCH-ios-macabi`. - Update mappings for macho platform and zig target macabi. While this is not full maccatalyst support, a basic exe can be built as follows: ``` zig libc > libc.txt zig build-exe z0.zig --libc libc.txt -target x86_64-ios-macabi ``` closes #19110 --- src/link/MachO.zig | 8 +++++++- src/link/MachO/Dylib.zig | 10 ++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/link/MachO.zig b/src/link/MachO.zig index cc488b7541..475bd02b24 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -4376,9 +4376,11 @@ pub const Platform = struct { .IOS, .IOSSIMULATOR => .ios, .TVOS, .TVOSSIMULATOR => .tvos, .WATCHOS, .WATCHOSSIMULATOR => .watchos, + .MACCATALYST => .ios, else => @panic("TODO"), }, .abi = switch (cmd.platform) { + .MACCATALYST => .macabi, .IOSSIMULATOR, .TVOSSIMULATOR, .WATCHOSSIMULATOR, @@ -4425,7 +4427,11 @@ pub const Platform = struct { pub fn toApplePlatform(plat: Platform) macho.PLATFORM { return switch (plat.os_tag) { .macos => .MACOS, - .ios => if (plat.abi == .simulator) .IOSSIMULATOR else .IOS, + .ios => switch (plat.abi) { + .simulator => .IOSSIMULATOR, + .macabi => .MACCATALYST, + else => .IOS, + }, .tvos => if (plat.abi == .simulator) .TVOSSIMULATOR else .TVOS, .watchos => if (plat.abi == .simulator) .WATCHOSSIMULATOR else .WATCHOS, else => unreachable, diff --git a/src/link/MachO/Dylib.zig b/src/link/MachO/Dylib.zig index 9da3456c6c..6acfb2080c 100644 --- a/src/link/MachO/Dylib.zig +++ b/src/link/MachO/Dylib.zig @@ -751,8 +751,14 @@ pub const TargetMatcher = struct { .v3 => |v3| blk: { var targets = std.ArrayList([]const u8).init(arena.allocator()); for (v3.archs) |arch| { - const target = try std.fmt.allocPrint(arena.allocator(), "{s}-{s}", .{ arch, v3.platform }); - try targets.append(target); + if (mem.eql(u8, v3.platform, "zippered")) { + // From Xcode 10.3 → 11.3.1, macos SDK .tbd files specify platform as 'zippered' + // which should map to [ '-macos', '-maccatalyst' ] + try targets.append(try std.fmt.allocPrint(arena.allocator(), "{s}-macos", .{arch})); + try targets.append(try std.fmt.allocPrint(arena.allocator(), "{s}-maccatalyst", .{arch})); + } else { + try targets.append(try std.fmt.allocPrint(arena.allocator(), "{s}-{s}", .{ arch, v3.platform })); + } } break :blk targets.items; },