authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-05-09 14:09:31+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-05-09 14:09:31+02:00
log8f202ba7c7c446da9dff4b9ca2bbfb5b21c0aa18
treeded686a53e8e1bc8d69d640d2f4508de09d99455
parentbcb534c295d5cc6fd63caa570cc08e6b148a507c

link/macho: add support for VisionOS


2 files changed, 25 insertions(+), 12 deletions(-)

src/link/MachO.zig+22-11
...@@ -3676,10 +3676,16 @@ pub inline fn getPageSize(self: MachO) u16 {...@@ -3676,10 +3676,16 @@ pub inline fn getPageSize(self: MachO) u16 {
36763676
3677pub fn requiresCodeSig(self: MachO) bool {3677pub fn requiresCodeSig(self: MachO) bool {
3678 if (self.entitlements) |_| return true;3678 if (self.entitlements) |_| return true;
3679 // if (self.options.adhoc_codesign) |cs| return cs;3679 if (self.options.adhoc_codesign) |cs| return cs;
3680 return switch (self.getTarget().cpu.arch) {3680 const target = self.getTarget();
3681 .aarch64 => true,3681 return switch (target.cpu.arch) {
3682 else => false,3682 .aarch64 => switch (target.os.tag) {
3683 .macos => true,
3684 .watchos, .tvos, .ios, .visionos => target.abi == .simulator,
3685 else => false,
3686 },
3687 .x86_64 => false,
3688 else => unreachable,
3683 };3689 };
3684}3690}
36853691
...@@ -4424,6 +4430,7 @@ pub const Platform = struct {...@@ -4424,6 +4430,7 @@ pub const Platform = struct {
4424 .TVOS, .TVOSSIMULATOR => .tvos,4430 .TVOS, .TVOSSIMULATOR => .tvos,
4425 .WATCHOS, .WATCHOSSIMULATOR => .watchos,4431 .WATCHOS, .WATCHOSSIMULATOR => .watchos,
4426 .MACCATALYST => .ios,4432 .MACCATALYST => .ios,
4433 .VISIONOS, .VISIONOSSIMULATOR => .visionos,
4427 else => @panic("TODO"),4434 else => @panic("TODO"),
4428 },4435 },
4429 .abi = switch (cmd.platform) {4436 .abi = switch (cmd.platform) {
...@@ -4431,6 +4438,7 @@ pub const Platform = struct {...@@ -4431,6 +4438,7 @@ pub const Platform = struct {
4431 .IOSSIMULATOR,4438 .IOSSIMULATOR,
4432 .TVOSSIMULATOR,4439 .TVOSSIMULATOR,
4433 .WATCHOSSIMULATOR,4440 .WATCHOSSIMULATOR,
4441 .VISIONOSSIMULATOR,
4434 => .simulator,4442 => .simulator,
4435 else => .none,4443 else => .none,
4436 },4444 },
...@@ -4481,6 +4489,7 @@ pub const Platform = struct {...@@ -4481,6 +4489,7 @@ pub const Platform = struct {
4481 },4489 },
4482 .tvos => if (plat.abi == .simulator) .TVOSSIMULATOR else .TVOS,4490 .tvos => if (plat.abi == .simulator) .TVOSSIMULATOR else .TVOS,
4483 .watchos => if (plat.abi == .simulator) .WATCHOSSIMULATOR else .WATCHOS,4491 .watchos => if (plat.abi == .simulator) .WATCHOSSIMULATOR else .WATCHOS,
4492 .visionos => if (plat.abi == .simulator) .VISIONOSSIMULATOR else .VISIONOS,
4484 else => unreachable,4493 else => unreachable,
4485 };4494 };
4486 }4495 }
...@@ -4549,13 +4558,15 @@ const SupportedPlatforms = struct {...@@ -4549,13 +4558,15 @@ const SupportedPlatforms = struct {
4549// Source: https://github.com/apple-oss-distributions/ld64/blob/59a99ab60399c5e6c49e6945a9e1049c42b71135/src/ld/PlatformSupport.cpp#L524558// Source: https://github.com/apple-oss-distributions/ld64/blob/59a99ab60399c5e6c49e6945a9e1049c42b71135/src/ld/PlatformSupport.cpp#L52
4550// zig fmt: off4559// zig fmt: off
4551const supported_platforms = [_]SupportedPlatforms{4560const supported_platforms = [_]SupportedPlatforms{
4552 .{ .macos, .none, 0xA0E00, 0xA0800 },4561 .{ .macos, .none, 0xA0E00, 0xA0800 },
4553 .{ .ios, .none, 0xC0000, 0x70000 },4562 .{ .ios, .none, 0xC0000, 0x70000 },
4554 .{ .tvos, .none, 0xC0000, 0x70000 },4563 .{ .tvos, .none, 0xC0000, 0x70000 },
4555 .{ .watchos, .none, 0x50000, 0x20000 },4564 .{ .watchos, .none, 0x50000, 0x20000 },
4556 .{ .ios, .simulator, 0xD0000, 0x80000 },4565 .{ .visionos, .none, 0x10000, 0x10000 },
4557 .{ .tvos, .simulator, 0xD0000, 0x80000 },4566 .{ .ios, .simulator, 0xD0000, 0x80000 },
4558 .{ .watchos, .simulator, 0x60000, 0x20000 },4567 .{ .tvos, .simulator, 0xD0000, 0x80000 },
4568 .{ .watchos, .simulator, 0x60000, 0x20000 },
4569 .{ .visionos, .simulator, 0x10000, 0x10000 },
4559};4570};
4560// zig fmt: on4571// zig fmt: on
45614572
src/link/MachO/Dylib.zig+3-1
...@@ -671,7 +671,7 @@ pub const TargetMatcher = struct {...@@ -671,7 +671,7 @@ pub const TargetMatcher = struct {
671 try self.target_strings.append(allocator, apple_string);671 try self.target_strings.append(allocator, apple_string);
672672
673 switch (platform) {673 switch (platform) {
674 .IOSSIMULATOR, .TVOSSIMULATOR, .WATCHOSSIMULATOR => {674 .IOSSIMULATOR, .TVOSSIMULATOR, .WATCHOSSIMULATOR, .VISIONOSSIMULATOR => {
675 // For Apple simulator targets, linking gets tricky as we need to link against the simulator675 // For Apple simulator targets, linking gets tricky as we need to link against the simulator
676 // hosts dylibs too.676 // hosts dylibs too.
677 const host_target = try targetToAppleString(allocator, cpu_arch, .MACOS);677 const host_target = try targetToAppleString(allocator, cpu_arch, .MACOS);
...@@ -714,9 +714,11 @@ pub const TargetMatcher = struct {...@@ -714,9 +714,11 @@ pub const TargetMatcher = struct {
714 .IOS => "ios",714 .IOS => "ios",
715 .TVOS => "tvos",715 .TVOS => "tvos",
716 .WATCHOS => "watchos",716 .WATCHOS => "watchos",
717 .VISIONOS => "xros",
717 .IOSSIMULATOR => "ios-simulator",718 .IOSSIMULATOR => "ios-simulator",
718 .TVOSSIMULATOR => "tvos-simulator",719 .TVOSSIMULATOR => "tvos-simulator",
719 .WATCHOSSIMULATOR => "watchos-simulator",720 .WATCHOSSIMULATOR => "watchos-simulator",
721 .VISIONOSSIMULATOR => "xros-simulator",
720 .BRIDGEOS => "bridgeos",722 .BRIDGEOS => "bridgeos",
721 .MACCATALYST => "maccatalyst",723 .MACCATALYST => "maccatalyst",
722 .DRIVERKIT => "driverkit",724 .DRIVERKIT => "driverkit",