mirror of
https://github.com/ziglang/zig.git
synced 2025-12-16 11:13:08 +00:00
Merge pull request #19260 from mikdusan/macos-zippered
macos: add zippered support
This commit is contained in:
commit
23f729aec9
@ -113,7 +113,7 @@ pub fn main() !void {
|
|||||||
};
|
};
|
||||||
defer libc.deinit(gpa);
|
defer libc.deinit(gpa);
|
||||||
} else {
|
} else {
|
||||||
if (!target_query.isNative()) {
|
if (!target_query.canDetectLibC()) {
|
||||||
fatal("unable to detect libc for non-native target", .{});
|
fatal("unable to detect libc for non-native target", .{});
|
||||||
}
|
}
|
||||||
var libc = LibCInstallation.findNative(.{
|
var libc = LibCInstallation.findNative(.{
|
||||||
|
|||||||
@ -415,6 +415,15 @@ pub fn isNative(self: Query) bool {
|
|||||||
return self.isNativeCpu() and self.isNativeOs() and self.isNativeAbi();
|
return self.isNativeCpu() and self.isNativeOs() and self.isNativeAbi();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn canDetectLibC(self: Query) bool {
|
||||||
|
if (self.isNative()) return true;
|
||||||
|
if (self.os_tag) |os| {
|
||||||
|
if (builtin.os.tag == .macos and os.isDarwin()) return true;
|
||||||
|
if (os == .linux and self.abi == .android) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// Formats a version with the patch component omitted if it is zero,
|
/// Formats a version with the patch component omitted if it is zero,
|
||||||
/// unlike SemanticVersion.format which formats all its version components regardless.
|
/// unlike SemanticVersion.format which formats all its version components regardless.
|
||||||
fn formatVersion(version: SemanticVersion, writer: anytype) !void {
|
fn formatVersion(version: SemanticVersion, writer: anytype) !void {
|
||||||
|
|||||||
@ -167,7 +167,7 @@ pub const FindNativeOptions = struct {
|
|||||||
pub fn findNative(args: FindNativeOptions) FindError!LibCInstallation {
|
pub fn findNative(args: FindNativeOptions) FindError!LibCInstallation {
|
||||||
var self: LibCInstallation = .{};
|
var self: LibCInstallation = .{};
|
||||||
|
|
||||||
if (is_darwin) {
|
if (is_darwin and args.target.isDarwin()) {
|
||||||
if (!std.zig.system.darwin.isSdkInstalled(args.allocator))
|
if (!std.zig.system.darwin.isSdkInstalled(args.allocator))
|
||||||
return error.DarwinSdkNotFound;
|
return error.DarwinSdkNotFound;
|
||||||
const sdk = std.zig.system.darwin.getSdk(args.allocator, args.target) orelse
|
const sdk = std.zig.system.darwin.getSdk(args.allocator, args.target) orelse
|
||||||
@ -196,7 +196,7 @@ pub fn findNative(args: FindNativeOptions) FindError!LibCInstallation {
|
|||||||
try self.findNativeCrtDirWindows(args, &sdk);
|
try self.findNativeCrtDirWindows(args, &sdk);
|
||||||
} else if (is_haiku) {
|
} else if (is_haiku) {
|
||||||
try self.findNativeIncludeDirPosix(args);
|
try self.findNativeIncludeDirPosix(args);
|
||||||
try self.findNativeCrtBeginDirHaiku(args);
|
try self.findNativeGccDirHaiku(args);
|
||||||
self.crt_dir = try args.allocator.dupeZ(u8, "/system/develop/lib");
|
self.crt_dir = try args.allocator.dupeZ(u8, "/system/develop/lib");
|
||||||
} else if (builtin.target.os.tag.isSolarish()) {
|
} else if (builtin.target.os.tag.isSolarish()) {
|
||||||
// There is only one libc, and its headers/libraries are always in the same spot.
|
// There is only one libc, and its headers/libraries are always in the same spot.
|
||||||
@ -443,13 +443,16 @@ fn findNativeCrtDirWindows(
|
|||||||
fn findNativeCrtDirPosix(self: *LibCInstallation, args: FindNativeOptions) FindError!void {
|
fn findNativeCrtDirPosix(self: *LibCInstallation, args: FindNativeOptions) FindError!void {
|
||||||
self.crt_dir = try ccPrintFileName(.{
|
self.crt_dir = try ccPrintFileName(.{
|
||||||
.allocator = args.allocator,
|
.allocator = args.allocator,
|
||||||
.search_basename = "crt1.o",
|
.search_basename = switch (args.target.os.tag) {
|
||||||
|
.linux => if (args.target.isAndroid()) "crtbegin_dynamic.o" else "crt1.o",
|
||||||
|
else => "crt1.o",
|
||||||
|
},
|
||||||
.want_dirname = .only_dir,
|
.want_dirname = .only_dir,
|
||||||
.verbose = args.verbose,
|
.verbose = args.verbose,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn findNativeCrtBeginDirHaiku(self: *LibCInstallation, args: FindNativeOptions) FindError!void {
|
fn findNativeGccDirHaiku(self: *LibCInstallation, args: FindNativeOptions) FindError!void {
|
||||||
self.gcc_dir = try ccPrintFileName(.{
|
self.gcc_dir = try ccPrintFileName(.{
|
||||||
.allocator = args.allocator,
|
.allocator = args.allocator,
|
||||||
.search_basename = "crtbeginS.o",
|
.search_basename = "crtbeginS.o",
|
||||||
|
|||||||
@ -38,7 +38,11 @@ pub fn getSdk(allocator: Allocator, target: Target) ?[]const u8 {
|
|||||||
const is_simulator_abi = target.abi == .simulator;
|
const is_simulator_abi = target.abi == .simulator;
|
||||||
const sdk = switch (target.os.tag) {
|
const sdk = switch (target.os.tag) {
|
||||||
.macos => "macosx",
|
.macos => "macosx",
|
||||||
.ios => if (is_simulator_abi) "iphonesimulator" else "iphoneos",
|
.ios => switch (target.abi) {
|
||||||
|
.simulator => "iphonesimulator",
|
||||||
|
.macabi => "macosx",
|
||||||
|
else => "iphoneos",
|
||||||
|
},
|
||||||
.watchos => if (is_simulator_abi) "watchsimulator" else "watchos",
|
.watchos => if (is_simulator_abi) "watchsimulator" else "watchos",
|
||||||
.tvos => if (is_simulator_abi) "appletvsimulator" else "appletvos",
|
.tvos => if (is_simulator_abi) "appletvsimulator" else "appletvos",
|
||||||
else => return null,
|
else => return null,
|
||||||
|
|||||||
@ -4376,9 +4376,11 @@ pub const Platform = struct {
|
|||||||
.IOS, .IOSSIMULATOR => .ios,
|
.IOS, .IOSSIMULATOR => .ios,
|
||||||
.TVOS, .TVOSSIMULATOR => .tvos,
|
.TVOS, .TVOSSIMULATOR => .tvos,
|
||||||
.WATCHOS, .WATCHOSSIMULATOR => .watchos,
|
.WATCHOS, .WATCHOSSIMULATOR => .watchos,
|
||||||
|
.MACCATALYST => .ios,
|
||||||
else => @panic("TODO"),
|
else => @panic("TODO"),
|
||||||
},
|
},
|
||||||
.abi = switch (cmd.platform) {
|
.abi = switch (cmd.platform) {
|
||||||
|
.MACCATALYST => .macabi,
|
||||||
.IOSSIMULATOR,
|
.IOSSIMULATOR,
|
||||||
.TVOSSIMULATOR,
|
.TVOSSIMULATOR,
|
||||||
.WATCHOSSIMULATOR,
|
.WATCHOSSIMULATOR,
|
||||||
@ -4425,7 +4427,11 @@ pub const Platform = struct {
|
|||||||
pub fn toApplePlatform(plat: Platform) macho.PLATFORM {
|
pub fn toApplePlatform(plat: Platform) macho.PLATFORM {
|
||||||
return switch (plat.os_tag) {
|
return switch (plat.os_tag) {
|
||||||
.macos => .MACOS,
|
.macos => .MACOS,
|
||||||
.ios => if (plat.abi == .simulator) .IOSSIMULATOR else .IOS,
|
.ios => switch (plat.abi) {
|
||||||
|
.simulator => .IOSSIMULATOR,
|
||||||
|
.macabi => .MACCATALYST,
|
||||||
|
else => .IOS,
|
||||||
|
},
|
||||||
.tvos => if (plat.abi == .simulator) .TVOSSIMULATOR else .TVOS,
|
.tvos => if (plat.abi == .simulator) .TVOSSIMULATOR else .TVOS,
|
||||||
.watchos => if (plat.abi == .simulator) .WATCHOSSIMULATOR else .WATCHOS,
|
.watchos => if (plat.abi == .simulator) .WATCHOSSIMULATOR else .WATCHOS,
|
||||||
else => unreachable,
|
else => unreachable,
|
||||||
|
|||||||
@ -54,7 +54,7 @@ pub fn parse(self: *Dylib, macho_file: *MachO, file: std.fs.File, fat_arch: ?fat
|
|||||||
const gpa = macho_file.base.comp.gpa;
|
const gpa = macho_file.base.comp.gpa;
|
||||||
const offset = if (fat_arch) |ar| ar.offset else 0;
|
const offset = if (fat_arch) |ar| ar.offset else 0;
|
||||||
|
|
||||||
log.debug("parsing dylib from binary", .{});
|
log.debug("parsing dylib from binary: {s}", .{self.path});
|
||||||
|
|
||||||
var header_buffer: [@sizeOf(macho.mach_header_64)]u8 = undefined;
|
var header_buffer: [@sizeOf(macho.mach_header_64)]u8 = undefined;
|
||||||
{
|
{
|
||||||
@ -266,7 +266,7 @@ pub fn parseTbd(
|
|||||||
|
|
||||||
const gpa = macho_file.base.comp.gpa;
|
const gpa = macho_file.base.comp.gpa;
|
||||||
|
|
||||||
log.debug("parsing dylib from stub", .{});
|
log.debug("parsing dylib from stub: {s}", .{self.path});
|
||||||
|
|
||||||
const umbrella_lib = lib_stub.inner[0];
|
const umbrella_lib = lib_stub.inner[0];
|
||||||
|
|
||||||
@ -751,8 +751,14 @@ pub const TargetMatcher = struct {
|
|||||||
.v3 => |v3| blk: {
|
.v3 => |v3| blk: {
|
||||||
var targets = std.ArrayList([]const u8).init(arena.allocator());
|
var targets = std.ArrayList([]const u8).init(arena.allocator());
|
||||||
for (v3.archs) |arch| {
|
for (v3.archs) |arch| {
|
||||||
const target = try std.fmt.allocPrint(arena.allocator(), "{s}-{s}", .{ arch, v3.platform });
|
if (mem.eql(u8, v3.platform, "zippered")) {
|
||||||
try targets.append(target);
|
// From Xcode 10.3 → 11.3.1, macos SDK .tbd files specify platform as 'zippered'
|
||||||
|
// which should map to [ '<arch>-macos', '<arch>-maccatalyst' ]
|
||||||
|
try targets.append(try std.fmt.allocPrint(arena.allocator(), "{s}-macos", .{arch}));
|
||||||
|
try targets.append(try std.fmt.allocPrint(arena.allocator(), "{s}-maccatalyst", .{arch}));
|
||||||
|
} else {
|
||||||
|
try targets.append(try std.fmt.allocPrint(arena.allocator(), "{s}-{s}", .{ arch, v3.platform }));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break :blk targets.items;
|
break :blk targets.items;
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user