authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2024-03-13 02:17:28-04:00
committergravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2024-03-13 02:17:28-04:00
log197ffff0b8d1c5257d66775d4cc46bcbfd570a90
treea2ae6a6a5944be7ba8391f19bc073691533cbdc8
parent22fd1851bd56dae5b61e5f170671f3af5ef54330
signaturelock-open Commit is signed but in an unrecognized format.

macos: add tbd-v3 zippered support

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

2 files changed, 15 insertions(+), 3 deletions(-)

src/link/MachO.zig+7-1
......@@ -4376,9 +4376,11 @@ pub const Platform = struct {
43764376 .IOS, .IOSSIMULATOR => .ios,
43774377 .TVOS, .TVOSSIMULATOR => .tvos,
43784378 .WATCHOS, .WATCHOSSIMULATOR => .watchos,
4379 .MACCATALYST => .ios,
43794380 else => @panic("TODO"),
43804381 },
43814382 .abi = switch (cmd.platform) {
4383 .MACCATALYST => .macabi,
43824384 .IOSSIMULATOR,
43834385 .TVOSSIMULATOR,
43844386 .WATCHOSSIMULATOR,
......@@ -4425,7 +4427,11 @@ pub const Platform = struct {
44254427 pub fn toApplePlatform(plat: Platform) macho.PLATFORM {
44264428 return switch (plat.os_tag) {
44274429 .macos => .MACOS,
4428 .ios => if (plat.abi == .simulator) .IOSSIMULATOR else .IOS,
4430 .ios => switch (plat.abi) {
4431 .simulator => .IOSSIMULATOR,
4432 .macabi => .MACCATALYST,
4433 else => .IOS,
4434 },
44294435 .tvos => if (plat.abi == .simulator) .TVOSSIMULATOR else .TVOS,
44304436 .watchos => if (plat.abi == .simulator) .WATCHOSSIMULATOR else .WATCHOS,
44314437 else => unreachable,
src/link/MachO/Dylib.zig+8-2
......@@ -751,8 +751,14 @@ pub const TargetMatcher = struct {
751751 .v3 => |v3| blk: {
752752 var targets = std.ArrayList([]const u8).init(arena.allocator());
753753 for (v3.archs) |arch| {
754 const target = try std.fmt.allocPrint(arena.allocator(), "{s}-{s}", .{ arch, v3.platform });
755 try targets.append(target);
754 if (mem.eql(u8, v3.platform, "zippered")) {
755 // From Xcode 10.3 → 11.3.1, macos SDK .tbd files specify platform as 'zippered'
756 // which should map to [ '<arch>-macos', '<arch>-maccatalyst' ]
757 try targets.append(try std.fmt.allocPrint(arena.allocator(), "{s}-macos", .{arch}));
758 try targets.append(try std.fmt.allocPrint(arena.allocator(), "{s}-maccatalyst", .{arch}));
759 } else {
760 try targets.append(try std.fmt.allocPrint(arena.allocator(), "{s}-{s}", .{ arch, v3.platform }));
761 }
756762 }
757763 break :blk targets.items;
758764 },