authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-06 09:12:43+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-10 13:41:10+02:00
log2371a63bd46cb1af7e3b9857136ea7677f6abdcc
treef61b6942619db0e5b26f590da36822f10ab62178
parent700768498488dbae1c737b484f330b86f116cb62

macho: allow .simulator ABI when targeting Apple simulator env

For example, in order to run a binary on an iPhone Simulator, you need to specify that explicitly as part of the target as `aarch64-ios-simulator` rather than `aarch64-ios-gnu` or `aarch64-ios` for short.

2 files changed, 17 insertions(+), 9 deletions(-)

src/link/MachO.zig+8-6
...@@ -2736,14 +2736,15 @@ fn populateMetadata(self: *MachO) !void {...@@ -2736,14 +2736,15 @@ fn populateMetadata(self: *MachO) !void {
2736 ));2736 ));
2737 const ver = self.base.options.target.os.version_range.semver.min;2737 const ver = self.base.options.target.os.version_range.semver.min;
2738 const version = ver.major << 16 | ver.minor << 8 | ver.patch;2738 const version = ver.major << 16 | ver.minor << 8 | ver.patch;
2739 const is_simulator_abi = self.base.options.target.abi == .simulator;
2739 var cmd = commands.emptyGenericCommandWithData(macho.build_version_command{2740 var cmd = commands.emptyGenericCommandWithData(macho.build_version_command{
2740 .cmd = macho.LC_BUILD_VERSION,2741 .cmd = macho.LC_BUILD_VERSION,
2741 .cmdsize = cmdsize,2742 .cmdsize = cmdsize,
2742 .platform = switch (self.base.options.target.os.tag) {2743 .platform = switch (self.base.options.target.os.tag) {
2743 .macos => macho.PLATFORM_MACOS,2744 .macos => macho.PLATFORM_MACOS,
2744 .ios => macho.PLATFORM_IOSSIMULATOR,2745 .ios => if (is_simulator_abi) macho.PLATFORM_IOSSIMULATOR else macho.PLATFORM_IOS,
2745 .watchos => macho.PLATFORM_WATCHOS,2746 .watchos => if (is_simulator_abi) macho.PLATFORM_WATCHOSSIMULATOR else macho.PLATFORM_WATCHOS,
2746 .tvos => macho.PLATFORM_TVOS,2747 .tvos => if (is_simulator_abi) macho.PLATFORM_TVOSSIMULATOR else macho.PLATFORM_TVOS,
2747 else => unreachable,2748 else => unreachable,
2748 },2749 },
2749 .minos = version,2750 .minos = version,
...@@ -4355,14 +4356,15 @@ pub fn populateMissingMetadata(self: *MachO) !void {...@@ -4355,14 +4356,15 @@ pub fn populateMissingMetadata(self: *MachO) !void {
4355 ));4356 ));
4356 const ver = self.base.options.target.os.version_range.semver.min;4357 const ver = self.base.options.target.os.version_range.semver.min;
4357 const version = ver.major << 16 | ver.minor << 8 | ver.patch;4358 const version = ver.major << 16 | ver.minor << 8 | ver.patch;
4359 const is_simulator_abi = self.base.options.target.abi == .simulator;
4358 var cmd = commands.emptyGenericCommandWithData(macho.build_version_command{4360 var cmd = commands.emptyGenericCommandWithData(macho.build_version_command{
4359 .cmd = macho.LC_BUILD_VERSION,4361 .cmd = macho.LC_BUILD_VERSION,
4360 .cmdsize = cmdsize,4362 .cmdsize = cmdsize,
4361 .platform = switch (self.base.options.target.os.tag) {4363 .platform = switch (self.base.options.target.os.tag) {
4362 .macos => macho.PLATFORM_MACOS,4364 .macos => macho.PLATFORM_MACOS,
4363 .ios => macho.PLATFORM_IOSSIMULATOR,4365 .ios => if (is_simulator_abi) macho.PLATFORM_IOSSIMULATOR else macho.PLATFORM_IOS,
4364 .watchos => macho.PLATFORM_WATCHOS,4366 .watchos => if (is_simulator_abi) macho.PLATFORM_WATCHOSSIMULATOR else macho.PLATFORM_WATCHOS,
4365 .tvos => macho.PLATFORM_TVOS,4367 .tvos => if (is_simulator_abi) macho.PLATFORM_TVOSSIMULATOR else macho.PLATFORM_TVOS,
4366 else => unreachable,4368 else => unreachable,
4367 },4369 },
4368 .minos = version,4370 .minos = version,
src/link/MachO/Dylib.zig+9-3
...@@ -340,10 +340,16 @@ fn targetToAppleString(allocator: *Allocator, target: std.Target) ![]const u8 {...@@ -340,10 +340,16 @@ fn targetToAppleString(allocator: *Allocator, target: std.Target) ![]const u8 {
340 .x86_64 => "x86_64",340 .x86_64 => "x86_64",
341 else => unreachable,341 else => unreachable,
342 };342 };
343 if (target.os.tag == .ios) {343 const os = @tagName(target.os.tag);
344 return std.fmt.allocPrint(allocator, "{s}-{s}-simulator", .{ arch, @tagName(target.os.tag) });344 const abi: ?[]const u8 = switch (target.abi) {
345 .gnu => null,
346 .simulator => "simulator",
347 else => unreachable,
348 };
349 if (abi) |x| {
350 return std.fmt.allocPrint(allocator, "{s}-{s}-{s}", .{ arch, os, x });
345 }351 }
346 return std.fmt.allocPrint(allocator, "{s}-{s}", .{ arch, @tagName(target.os.tag) });352 return std.fmt.allocPrint(allocator, "{s}-{s}", .{ arch, os });
347}353}
348354
349pub fn parseFromStub(self: *Dylib, allocator: *Allocator, target: std.Target, lib_stub: LibStub) !void {355pub fn parseFromStub(self: *Dylib, allocator: *Allocator, target: std.Target, lib_stub: LibStub) !void {