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 {
27362736 ));
27372737 const ver = self.base.options.target.os.version_range.semver.min;
27382738 const version = ver.major << 16 | ver.minor << 8 | ver.patch;
2739 const is_simulator_abi = self.base.options.target.abi == .simulator;
27392740 var cmd = commands.emptyGenericCommandWithData(macho.build_version_command{
27402741 .cmd = macho.LC_BUILD_VERSION,
27412742 .cmdsize = cmdsize,
27422743 .platform = switch (self.base.options.target.os.tag) {
27432744 .macos => macho.PLATFORM_MACOS,
2744 .ios => macho.PLATFORM_IOSSIMULATOR,
2745 .watchos => macho.PLATFORM_WATCHOS,
2746 .tvos => macho.PLATFORM_TVOS,
2745 .ios => if (is_simulator_abi) macho.PLATFORM_IOSSIMULATOR else macho.PLATFORM_IOS,
2746 .watchos => if (is_simulator_abi) macho.PLATFORM_WATCHOSSIMULATOR else macho.PLATFORM_WATCHOS,
2747 .tvos => if (is_simulator_abi) macho.PLATFORM_TVOSSIMULATOR else macho.PLATFORM_TVOS,
27472748 else => unreachable,
27482749 },
27492750 .minos = version,
......@@ -4355,14 +4356,15 @@ pub fn populateMissingMetadata(self: *MachO) !void {
43554356 ));
43564357 const ver = self.base.options.target.os.version_range.semver.min;
43574358 const version = ver.major << 16 | ver.minor << 8 | ver.patch;
4359 const is_simulator_abi = self.base.options.target.abi == .simulator;
43584360 var cmd = commands.emptyGenericCommandWithData(macho.build_version_command{
43594361 .cmd = macho.LC_BUILD_VERSION,
43604362 .cmdsize = cmdsize,
43614363 .platform = switch (self.base.options.target.os.tag) {
43624364 .macos => macho.PLATFORM_MACOS,
4363 .ios => macho.PLATFORM_IOSSIMULATOR,
4364 .watchos => macho.PLATFORM_WATCHOS,
4365 .tvos => macho.PLATFORM_TVOS,
4365 .ios => if (is_simulator_abi) macho.PLATFORM_IOSSIMULATOR else macho.PLATFORM_IOS,
4366 .watchos => if (is_simulator_abi) macho.PLATFORM_WATCHOSSIMULATOR else macho.PLATFORM_WATCHOS,
4367 .tvos => if (is_simulator_abi) macho.PLATFORM_TVOSSIMULATOR else macho.PLATFORM_TVOS,
43664368 else => unreachable,
43674369 },
43684370 .minos = version,
src/link/MachO/Dylib.zig+9-3
......@@ -340,10 +340,16 @@ fn targetToAppleString(allocator: *Allocator, target: std.Target) ![]const u8 {
340340 .x86_64 => "x86_64",
341341 else => unreachable,
342342 };
343 if (target.os.tag == .ios) {
344 return std.fmt.allocPrint(allocator, "{s}-{s}-simulator", .{ arch, @tagName(target.os.tag) });
343 const os = @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 });
345351 }
346 return std.fmt.allocPrint(allocator, "{s}-{s}", .{ arch, @tagName(target.os.tag) });
352 return std.fmt.allocPrint(allocator, "{s}-{s}", .{ arch, os });
347353}
348354
349355pub fn parseFromStub(self: *Dylib, allocator: *Allocator, target: std.Target, lib_stub: LibStub) !void {