motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit 2371a63bd46cb1af7e3b9857136ea7677f6abdcc (tree)
parent 700768498488dbae1c737b484f330b86f116cb62
Author: Jakub Konka <kubkon@jakubkonka.com>
Date:   Fri,  6 Aug 2021 09:12:43 +0200

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.

Diffstat:
Msrc/link/MachO.zig | 14++++++++------
Msrc/link/MachO/Dylib.zig | 12+++++++++---
2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/src/link/MachO.zig b/src/link/MachO.zig @@ -2736,14 +2736,15 @@ fn populateMetadata(self: *MachO) !void { )); const ver = self.base.options.target.os.version_range.semver.min; const version = ver.major << 16 | ver.minor << 8 | ver.patch; + const is_simulator_abi = self.base.options.target.abi == .simulator; var cmd = commands.emptyGenericCommandWithData(macho.build_version_command{ .cmd = macho.LC_BUILD_VERSION, .cmdsize = cmdsize, .platform = switch (self.base.options.target.os.tag) { .macos => macho.PLATFORM_MACOS, - .ios => macho.PLATFORM_IOSSIMULATOR, - .watchos => macho.PLATFORM_WATCHOS, - .tvos => macho.PLATFORM_TVOS, + .ios => if (is_simulator_abi) macho.PLATFORM_IOSSIMULATOR else macho.PLATFORM_IOS, + .watchos => if (is_simulator_abi) macho.PLATFORM_WATCHOSSIMULATOR else macho.PLATFORM_WATCHOS, + .tvos => if (is_simulator_abi) macho.PLATFORM_TVOSSIMULATOR else macho.PLATFORM_TVOS, else => unreachable, }, .minos = version, @@ -4355,14 +4356,15 @@ pub fn populateMissingMetadata(self: *MachO) !void { )); const ver = self.base.options.target.os.version_range.semver.min; const version = ver.major << 16 | ver.minor << 8 | ver.patch; + const is_simulator_abi = self.base.options.target.abi == .simulator; var cmd = commands.emptyGenericCommandWithData(macho.build_version_command{ .cmd = macho.LC_BUILD_VERSION, .cmdsize = cmdsize, .platform = switch (self.base.options.target.os.tag) { .macos => macho.PLATFORM_MACOS, - .ios => macho.PLATFORM_IOSSIMULATOR, - .watchos => macho.PLATFORM_WATCHOS, - .tvos => macho.PLATFORM_TVOS, + .ios => if (is_simulator_abi) macho.PLATFORM_IOSSIMULATOR else macho.PLATFORM_IOS, + .watchos => if (is_simulator_abi) macho.PLATFORM_WATCHOSSIMULATOR else macho.PLATFORM_WATCHOS, + .tvos => if (is_simulator_abi) macho.PLATFORM_TVOSSIMULATOR else macho.PLATFORM_TVOS, else => unreachable, }, .minos = version, diff --git a/src/link/MachO/Dylib.zig b/src/link/MachO/Dylib.zig @@ -340,10 +340,16 @@ fn targetToAppleString(allocator: *Allocator, target: std.Target) ![]const u8 { .x86_64 => "x86_64", else => unreachable, }; - if (target.os.tag == .ios) { - return std.fmt.allocPrint(allocator, "{s}-{s}-simulator", .{ arch, @tagName(target.os.tag) }); + const os = @tagName(target.os.tag); + const abi: ?[]const u8 = switch (target.abi) { + .gnu => null, + .simulator => "simulator", + else => unreachable, + }; + if (abi) |x| { + return std.fmt.allocPrint(allocator, "{s}-{s}-{s}", .{ arch, os, x }); } - return std.fmt.allocPrint(allocator, "{s}-{s}", .{ arch, @tagName(target.os.tag) }); + return std.fmt.allocPrint(allocator, "{s}-{s}", .{ arch, os }); } pub fn parseFromStub(self: *Dylib, allocator: *Allocator, target: std.Target, lib_stub: LibStub) !void {