authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-10 18:43:32+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-11 19:38:00+02:00
logd95e8bc5f8c48752aed73d077e2f9c87293a6617
treec6d9b2ff57a4fedefc2f82b0d588cedff2e0f817
parent8afe6210e95dd4608584535e8aed882285dc2078

macho: simplify versioning logic for TAPI


3 files changed, 28 insertions(+), 43 deletions(-)

src/link/MachO/Dylib.zig+18-29
...@@ -348,6 +348,8 @@ fn parseFromStubV3(self: *Dylib, allocator: *Allocator, target: std.Target, lib_...@@ -348,6 +348,8 @@ fn parseFromStubV3(self: *Dylib, allocator: *Allocator, target: std.Target, lib_
348348
349 const arch_string = @tagName(target.cpu.arch);349 const arch_string = @tagName(target.cpu.arch);
350350
351 log.debug("{s}", .{lib_stub.inner[0].installName()});
352
351 for (lib_stub.inner) |elem, stub_index| {353 for (lib_stub.inner) |elem, stub_index| {
352 const stub = elem.v3;354 const stub = elem.v3;
353 if (!hasArch(stub.archs, arch_string)) continue;355 if (!hasArch(stub.archs, arch_string)) continue;
...@@ -370,41 +372,28 @@ fn parseFromStubV3(self: *Dylib, allocator: *Allocator, target: std.Target, lib_...@@ -370,41 +372,28 @@ fn parseFromStubV3(self: *Dylib, allocator: *Allocator, target: std.Target, lib_
370 }372 }
371 }373 }
372374
375 if (exp.objc_classes) |objc_classes| {
376 for (objc_classes) |class_name| {
377 try self.addObjCClassSymbols(allocator, class_name);
378 }
379 }
380
373 if (exp.re_exports) |re_exports| {381 if (exp.re_exports) |re_exports| {
374 for (re_exports) |reexp| {382 for (re_exports) |lib| {
375 if (self.symbols.contains(reexp)) continue;383 if (umbrella_libs.contains(lib)) {
376 try self.symbols.putNoClobber(allocator, try allocator.dupe(u8, reexp), {});384 log.debug(" | {s} <= {s}", .{ lib, lib_stub.inner[0].installName() });
385 continue;
386 }
387
388 log.debug(" | {s}", .{lib});
389
390 const dep_id = try Id.default(allocator, lib);
391 try self.dependent_libs.append(allocator, dep_id);
377 }392 }
378 }393 }
379 }394 }
380 }395 }
381 }396 }
382
383 log.debug("{s}", .{lib_stub.inner[0].installName()});
384
385 // // TODO track which libs were already parsed in different steps
386 // for (lib_stub.inner) |elem| {
387 // const stub = elem.v3;
388 // if (!archMatches(stub.archs, arch_string)) continue;
389
390 // if (stub.reexported_libraries) |reexports| {
391 // for (reexports) |reexp| {
392 // if (!matcher.matches(reexp.targets)) continue;
393
394 // for (reexp.libraries) |lib| {
395 // if (umbrella_libs.contains(lib)) {
396 // log.debug(" | {s} <= {s}", .{ lib, umbrella_lib.install_name });
397 // continue;
398 // }
399
400 // log.debug(" | {s}", .{lib});
401
402 // const dep_id = try Id.default(allocator, lib);
403 // try self.dependent_libs.append(allocator, dep_id);
404 // }
405 // }
406 // }
407 // }
408}397}
409398
410fn targetToAppleString(allocator: *Allocator, target: std.Target) ![]const u8 {399fn targetToAppleString(allocator: *Allocator, target: std.Target) ![]const u8 {
src/link/tapi.zig+9-13
...@@ -19,11 +19,12 @@ pub const TbdV3 = struct {...@@ -19,11 +19,12 @@ pub const TbdV3 = struct {
19 install_name: []const u8,19 install_name: []const u8,
20 current_version: ?VersionField,20 current_version: ?VersionField,
21 compatibility_version: ?VersionField,21 compatibility_version: ?VersionField,
22 objc_constraint: []const u8,22 objc_constraint: ?[]const u8,
23 exports: ?[]const struct {23 exports: ?[]const struct {
24 archs: []const []const u8,24 archs: []const []const u8,
25 re_exports: ?[]const []const u8,25 re_exports: ?[]const []const u8,
26 symbols: ?[]const []const u8,26 symbols: ?[]const []const u8,
27 objc_classes: ?[]const []const u8,
27 },28 },
28};29};
2930
...@@ -107,10 +108,8 @@ pub const LibStub = struct {...@@ -107,10 +108,8 @@ pub const LibStub = struct {
107 // TODO clean this up.108 // TODO clean this up.
108 lib_stub.inner = blk: {109 lib_stub.inner = blk: {
109 err: {110 err: {
110 const inner = lib_stub.yaml.parse([]TbdV4) catch |err| switch (err) {111 log.debug("trying to parse as []TbdV4", .{});
111 error.TypeMismatch => break :err,112 const inner = lib_stub.yaml.parse([]TbdV4) catch break :err;
112 else => |e| return e,
113 };
114 var out = try lib_stub.yaml.arena.allocator.alloc(Tbd, inner.len);113 var out = try lib_stub.yaml.arena.allocator.alloc(Tbd, inner.len);
115 for (inner) |doc, i| {114 for (inner) |doc, i| {
116 out[i] = .{ .v4 = doc };115 out[i] = .{ .v4 = doc };
...@@ -119,25 +118,22 @@ pub const LibStub = struct {...@@ -119,25 +118,22 @@ pub const LibStub = struct {
119 }118 }
120119
121 err: {120 err: {
122 const inner = lib_stub.yaml.parse(TbdV4) catch |err| switch (err) {121 log.debug("trying to parse as TbdV4", .{});
123 error.TypeMismatch => break :err,122 const inner = lib_stub.yaml.parse(TbdV4) catch break :err;
124 else => |e| return e,
125 };
126 var out = try lib_stub.yaml.arena.allocator.alloc(Tbd, 1);123 var out = try lib_stub.yaml.arena.allocator.alloc(Tbd, 1);
127 out[0] = .{ .v4 = inner };124 out[0] = .{ .v4 = inner };
128 break :blk out;125 break :blk out;
129 }126 }
130127
131 err: {128 err: {
132 const inner = lib_stub.yaml.parse(TbdV3) catch |err| switch (err) {129 log.debug("trying to parse as TbdV3", .{});
133 error.TypeMismatch => break :err,130 const inner = lib_stub.yaml.parse(TbdV3) catch break :err;
134 else => |e| return e,
135 };
136 var out = try lib_stub.yaml.arena.allocator.alloc(Tbd, 1);131 var out = try lib_stub.yaml.arena.allocator.alloc(Tbd, 1);
137 out[0] = .{ .v3 = inner };132 out[0] = .{ .v3 = inner };
138 break :blk out;133 break :blk out;
139 }134 }
140135
136 // TODO this is clunky. Perhaps an optional would be better here?
141 return error.TypeMismatch;137 return error.TypeMismatch;
142 };138 };
143139
src/link/tapi/yaml.zig+1-1
...@@ -371,7 +371,7 @@ pub const Yaml = struct {...@@ -371,7 +371,7 @@ pub const Yaml = struct {
371 }371 }
372372
373 const unwrapped = value orelse {373 const unwrapped = value orelse {
374 log.err("missing struct field: {s}: {s}", .{ field.name, @typeName(field.field_type) });374 log.debug("missing struct field: {s}: {s}", .{ field.name, @typeName(field.field_type) });
375 return error.StructFieldMissing;375 return error.StructFieldMissing;
376 };376 };
377 @field(parsed, field.name) = try self.parseValue(field.field_type, unwrapped);377 @field(parsed, field.name) = try self.parseValue(field.field_type, unwrapped);