authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-04-05 23:37:51+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-04-05 23:37:51+02:00
log23f729aec96cec68be15436db2a38e37d54fbe8f
treedfc1e929aa4cbad0336cfd9da703aa7e2417d37b
parentdf1f8b0ae6ee493262f4244e3af0fb604ccd0a0f
parent197ffff0b8d1c5257d66775d4cc46bcbfd570a90
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #19260 from mikdusan/macos-zippered

macos: add zippered support

6 files changed, 39 insertions(+), 11 deletions(-)

lib/compiler/libc.zig+1-1
......@@ -113,7 +113,7 @@ pub fn main() !void {
113113 };
114114 defer libc.deinit(gpa);
115115 } else {
116 if (!target_query.isNative()) {
116 if (!target_query.canDetectLibC()) {
117117 fatal("unable to detect libc for non-native target", .{});
118118 }
119119 var libc = LibCInstallation.findNative(.{
lib/std/Target/Query.zig+9
......@@ -415,6 +415,15 @@ pub fn isNative(self: Query) bool {
415415 return self.isNativeCpu() and self.isNativeOs() and self.isNativeAbi();
416416}
417417
418pub fn canDetectLibC(self: Query) bool {
419 if (self.isNative()) return true;
420 if (self.os_tag) |os| {
421 if (builtin.os.tag == .macos and os.isDarwin()) return true;
422 if (os == .linux and self.abi == .android) return true;
423 }
424 return false;
425}
426
418427/// Formats a version with the patch component omitted if it is zero,
419428/// unlike SemanticVersion.format which formats all its version components regardless.
420429fn formatVersion(version: SemanticVersion, writer: anytype) !void {
lib/std/zig/LibCInstallation.zig+7-4
......@@ -167,7 +167,7 @@ pub const FindNativeOptions = struct {
167167pub fn findNative(args: FindNativeOptions) FindError!LibCInstallation {
168168 var self: LibCInstallation = .{};
169169
170 if (is_darwin) {
170 if (is_darwin and args.target.isDarwin()) {
171171 if (!std.zig.system.darwin.isSdkInstalled(args.allocator))
172172 return error.DarwinSdkNotFound;
173173 const sdk = std.zig.system.darwin.getSdk(args.allocator, args.target) orelse
......@@ -196,7 +196,7 @@ pub fn findNative(args: FindNativeOptions) FindError!LibCInstallation {
196196 try self.findNativeCrtDirWindows(args, &sdk);
197197 } else if (is_haiku) {
198198 try self.findNativeIncludeDirPosix(args);
199 try self.findNativeCrtBeginDirHaiku(args);
199 try self.findNativeGccDirHaiku(args);
200200 self.crt_dir = try args.allocator.dupeZ(u8, "/system/develop/lib");
201201 } else if (builtin.target.os.tag.isSolarish()) {
202202 // There is only one libc, and its headers/libraries are always in the same spot.
......@@ -443,13 +443,16 @@ fn findNativeCrtDirWindows(
443443fn findNativeCrtDirPosix(self: *LibCInstallation, args: FindNativeOptions) FindError!void {
444444 self.crt_dir = try ccPrintFileName(.{
445445 .allocator = args.allocator,
446 .search_basename = "crt1.o",
446 .search_basename = switch (args.target.os.tag) {
447 .linux => if (args.target.isAndroid()) "crtbegin_dynamic.o" else "crt1.o",
448 else => "crt1.o",
449 },
447450 .want_dirname = .only_dir,
448451 .verbose = args.verbose,
449452 });
450453}
451454
452fn findNativeCrtBeginDirHaiku(self: *LibCInstallation, args: FindNativeOptions) FindError!void {
455fn findNativeGccDirHaiku(self: *LibCInstallation, args: FindNativeOptions) FindError!void {
453456 self.gcc_dir = try ccPrintFileName(.{
454457 .allocator = args.allocator,
455458 .search_basename = "crtbeginS.o",
lib/std/zig/system/darwin.zig+5-1
......@@ -38,7 +38,11 @@ pub fn getSdk(allocator: Allocator, target: Target) ?[]const u8 {
3838 const is_simulator_abi = target.abi == .simulator;
3939 const sdk = switch (target.os.tag) {
4040 .macos => "macosx",
41 .ios => if (is_simulator_abi) "iphonesimulator" else "iphoneos",
41 .ios => switch (target.abi) {
42 .simulator => "iphonesimulator",
43 .macabi => "macosx",
44 else => "iphoneos",
45 },
4246 .watchos => if (is_simulator_abi) "watchsimulator" else "watchos",
4347 .tvos => if (is_simulator_abi) "appletvsimulator" else "appletvos",
4448 else => return null,
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+10-4
......@@ -54,7 +54,7 @@ pub fn parse(self: *Dylib, macho_file: *MachO, file: std.fs.File, fat_arch: ?fat
5454 const gpa = macho_file.base.comp.gpa;
5555 const offset = if (fat_arch) |ar| ar.offset else 0;
5656
57 log.debug("parsing dylib from binary", .{});
57 log.debug("parsing dylib from binary: {s}", .{self.path});
5858
5959 var header_buffer: [@sizeOf(macho.mach_header_64)]u8 = undefined;
6060 {
......@@ -266,7 +266,7 @@ pub fn parseTbd(
266266
267267 const gpa = macho_file.base.comp.gpa;
268268
269 log.debug("parsing dylib from stub", .{});
269 log.debug("parsing dylib from stub: {s}", .{self.path});
270270
271271 const umbrella_lib = lib_stub.inner[0];
272272
......@@ -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 },