diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2021-08-10 18:43:32 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2021-08-11 19:38:00 +0200 |
| commit | d95e8bc5f8c48752aed73d077e2f9c87293a6617 (patch) | |
| tree | c6d9b2ff57a4fedefc2f82b0d588cedff2e0f817 | |
| parent | 8afe6210e95dd4608584535e8aed882285dc2078 (diff) | |
| download | zig-d95e8bc5f8c48752aed73d077e2f9c87293a6617.tar.gz zig-d95e8bc5f8c48752aed73d077e2f9c87293a6617.zip | |
macho: simplify versioning logic for TAPI
| -rw-r--r-- | src/link/MachO/Dylib.zig | 47 | ||||
| -rw-r--r-- | src/link/tapi.zig | 22 | ||||
| -rw-r--r-- | src/link/tapi/yaml.zig | 2 |
3 files changed, 28 insertions, 43 deletions
diff --git a/src/link/MachO/Dylib.zig b/src/link/MachO/Dylib.zig index d3de8827d7..141e39f651 100644 --- a/src/link/MachO/Dylib.zig +++ b/src/link/MachO/Dylib.zig @@ -348,6 +348,8 @@ fn parseFromStubV3(self: *Dylib, allocator: *Allocator, target: std.Target, lib_ const arch_string = @tagName(target.cpu.arch); + log.debug("{s}", .{lib_stub.inner[0].installName()}); + for (lib_stub.inner) |elem, stub_index| { const stub = elem.v3; if (!hasArch(stub.archs, arch_string)) continue; @@ -370,41 +372,28 @@ fn parseFromStubV3(self: *Dylib, allocator: *Allocator, target: std.Target, lib_ } } + if (exp.objc_classes) |objc_classes| { + for (objc_classes) |class_name| { + try self.addObjCClassSymbols(allocator, class_name); + } + } + if (exp.re_exports) |re_exports| { - for (re_exports) |reexp| { - if (self.symbols.contains(reexp)) continue; - try self.symbols.putNoClobber(allocator, try allocator.dupe(u8, reexp), {}); + for (re_exports) |lib| { + if (umbrella_libs.contains(lib)) { + log.debug(" | {s} <= {s}", .{ lib, lib_stub.inner[0].installName() }); + continue; + } + + log.debug(" | {s}", .{lib}); + + const dep_id = try Id.default(allocator, lib); + try self.dependent_libs.append(allocator, dep_id); } } } } } - - log.debug("{s}", .{lib_stub.inner[0].installName()}); - - // // TODO track which libs were already parsed in different steps - // for (lib_stub.inner) |elem| { - // const stub = elem.v3; - // if (!archMatches(stub.archs, arch_string)) continue; - - // if (stub.reexported_libraries) |reexports| { - // for (reexports) |reexp| { - // if (!matcher.matches(reexp.targets)) continue; - - // for (reexp.libraries) |lib| { - // if (umbrella_libs.contains(lib)) { - // log.debug(" | {s} <= {s}", .{ lib, umbrella_lib.install_name }); - // continue; - // } - - // log.debug(" | {s}", .{lib}); - - // const dep_id = try Id.default(allocator, lib); - // try self.dependent_libs.append(allocator, dep_id); - // } - // } - // } - // } } fn targetToAppleString(allocator: *Allocator, target: std.Target) ![]const u8 { diff --git a/src/link/tapi.zig b/src/link/tapi.zig index aa953cc76a..e412651c08 100644 --- a/src/link/tapi.zig +++ b/src/link/tapi.zig @@ -19,11 +19,12 @@ pub const TbdV3 = struct { install_name: []const u8, current_version: ?VersionField, compatibility_version: ?VersionField, - objc_constraint: []const u8, + objc_constraint: ?[]const u8, exports: ?[]const struct { archs: []const []const u8, re_exports: ?[]const []const u8, symbols: ?[]const []const u8, + objc_classes: ?[]const []const u8, }, }; @@ -107,10 +108,8 @@ pub const LibStub = struct { // TODO clean this up. lib_stub.inner = blk: { err: { - const inner = lib_stub.yaml.parse([]TbdV4) catch |err| switch (err) { - error.TypeMismatch => break :err, - else => |e| return e, - }; + log.debug("trying to parse as []TbdV4", .{}); + const inner = lib_stub.yaml.parse([]TbdV4) catch break :err; var out = try lib_stub.yaml.arena.allocator.alloc(Tbd, inner.len); for (inner) |doc, i| { out[i] = .{ .v4 = doc }; @@ -119,25 +118,22 @@ pub const LibStub = struct { } err: { - const inner = lib_stub.yaml.parse(TbdV4) catch |err| switch (err) { - error.TypeMismatch => break :err, - else => |e| return e, - }; + log.debug("trying to parse as TbdV4", .{}); + const inner = lib_stub.yaml.parse(TbdV4) catch break :err; var out = try lib_stub.yaml.arena.allocator.alloc(Tbd, 1); out[0] = .{ .v4 = inner }; break :blk out; } err: { - const inner = lib_stub.yaml.parse(TbdV3) catch |err| switch (err) { - error.TypeMismatch => break :err, - else => |e| return e, - }; + log.debug("trying to parse as TbdV3", .{}); + const inner = lib_stub.yaml.parse(TbdV3) catch break :err; var out = try lib_stub.yaml.arena.allocator.alloc(Tbd, 1); out[0] = .{ .v3 = inner }; break :blk out; } + // TODO this is clunky. Perhaps an optional would be better here? return error.TypeMismatch; }; diff --git a/src/link/tapi/yaml.zig b/src/link/tapi/yaml.zig index b58df7609f..25d2c73e82 100644 --- a/src/link/tapi/yaml.zig +++ b/src/link/tapi/yaml.zig @@ -371,7 +371,7 @@ pub const Yaml = struct { } const unwrapped = value orelse { - log.err("missing struct field: {s}: {s}", .{ field.name, @typeName(field.field_type) }); + log.debug("missing struct field: {s}: {s}", .{ field.name, @typeName(field.field_type) }); return error.StructFieldMissing; }; @field(parsed, field.name) = try self.parseValue(field.field_type, unwrapped); |
