zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 13b1050d4c898d472d424f9067d990df12eff3fb (tree)
parent 6bdb45beafbd72a4f70092257dd1e15a5c356558
Author: Alex Rønne Petersen <alex@alexrp.com>
Date:   Thu, 26 Mar 2026 01:06:14 +0100

link.MachO.Dylib: allow aarch64-macos to match arm64e-macos TBD entries

closes https://codeberg.org/ziglang/zig/issues/31658

Diffstat:
Msrc/link/MachO/Dylib.zig | 50+++++++++++++++++++++++++-------------------------
1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/src/link/MachO/Dylib.zig b/src/link/MachO/Dylib.zig @@ -707,34 +707,36 @@ pub const TargetMatcher = struct { .cpu_arch = cpu_arch, .platform = platform, }; - const apple_string = try targetToAppleString(allocator, cpu_arch, platform); - try self.target_strings.append(allocator, apple_string); - switch (platform) { - .IOSSIMULATOR, .TVOSSIMULATOR, .WATCHOSSIMULATOR, .VISIONOSSIMULATOR => { - // For Apple simulator targets, linking gets tricky as we need to link against the simulator - // hosts dylibs too. - const host_target = try targetToAppleString(allocator, cpu_arch, .MACOS); - try self.target_strings.append(allocator, host_target); - }, + try self.addTargetStrings(cpuArchToAppleString(cpu_arch)); + // In Xcode 26.4, Apple unified their TBD files from having separate `arm64-macos` and `arm64e-macos` + // entries to having just the latter, presumably because the symbol lists are identical anyway. It + // sure would have been nice if they settled on the former as the unified name so as not to break the + // world, but evidently we can't have nice things. + if (cpu_arch == .aarch64) try self.addTargetStrings("arm64e"); + + return self; + } + + fn addTargetStrings(self: *TargetMatcher, arch: []const u8) !void { + try self.target_strings.append(self.allocator, try std.fmt.allocPrint( + self.allocator, + "{s}-{s}", + .{ arch, platformToAppleString(self.platform) }, + )); + + switch (self.platform) { .MACCATALYST => { // Mac Catalyst is allowed to link macOS libraries in a TBD because Apple were apparently too lazy // to add the proper target strings despite doing so in other places in the format??? - try self.target_strings.append(allocator, try targetToAppleString(allocator, cpu_arch, .MACOS)); + try self.target_strings.append(self.allocator, try std.fmt.allocPrint(self.allocator, "{s}-macos", .{arch})); }, - .MACOS => { - // Turns out that around 10.13/10.14 macOS release version, Apple changed the target tags in - // tbd files from `macosx` to `macos`. In order to be compliant and therefore actually support - // linking on older platforms against `libSystem.tbd`, we add `<cpu_arch>-macosx` to target_strings. - const fallback_target = try std.fmt.allocPrint(allocator, "{s}-macosx", .{ - cpuArchToAppleString(cpu_arch), - }); - try self.target_strings.append(allocator, fallback_target); + .IOSSIMULATOR, .TVOSSIMULATOR, .WATCHOSSIMULATOR, .VISIONOSSIMULATOR => { + // For Apple simulator targets, we need to link against the simulator host's libraries too. + try self.target_strings.append(self.allocator, try std.fmt.allocPrint(self.allocator, "{s}-macos", .{arch})); }, else => {}, } - - return self; } pub fn deinit(self: *TargetMatcher) void { @@ -744,7 +746,7 @@ pub const TargetMatcher = struct { self.target_strings.deinit(self.allocator); } - inline fn cpuArchToAppleString(cpu_arch: std.Target.Cpu.Arch) []const u8 { + fn cpuArchToAppleString(cpu_arch: std.Target.Cpu.Arch) []const u8 { return switch (cpu_arch) { .aarch64 => "arm64", .x86_64 => "x86_64", @@ -752,9 +754,8 @@ pub const TargetMatcher = struct { }; } - pub fn targetToAppleString(allocator: Allocator, cpu_arch: std.Target.Cpu.Arch, platform: macho.PLATFORM) ![]const u8 { - const arch = cpuArchToAppleString(cpu_arch); - const plat = switch (platform) { + fn platformToAppleString(platform: macho.PLATFORM) []const u8 { + return switch (platform) { .MACOS => "macos", .IOS => "ios", .TVOS => "tvos", @@ -769,7 +770,6 @@ pub const TargetMatcher = struct { .DRIVERKIT => "driverkit", else => unreachable, }; - return std.fmt.allocPrint(allocator, "{s}-{s}", .{ arch, plat }); } fn hasValue(stack: []const []const u8, needle: []const u8) bool {