From f63f4508d228e37965865221220f4f94103111cf Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Tue, 30 Jan 2024 12:11:27 +0100 Subject: [PATCH] macho: fix parsing versions from TBDs if parsed as floats --- src/link/MachO/Dylib.zig | 2 +- test/link/macho.zig | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/link/MachO/Dylib.zig b/src/link/MachO/Dylib.zig index 52f3c782e..41b877579 100644 --- a/src/link/MachO/Dylib.zig +++ b/src/link/MachO/Dylib.zig @@ -803,7 +803,7 @@ pub const Id = struct { }, .float => |float| { var buf: [256]u8 = undefined; - break :blk try fmt.bufPrint(&buf, "{d:.2}", .{float}); + break :blk try fmt.bufPrint(&buf, "{d}", .{float}); }, .string => |string| { break :blk string; diff --git a/test/link/macho.zig b/test/link/macho.zig index a99b93da8..e1ce182a6 100644 --- a/test/link/macho.zig +++ b/test/link/macho.zig @@ -54,6 +54,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { macho_step.dependOn(testEntryPointArchive(b, .{ .target = default_target })); macho_step.dependOn(testEntryPointDylib(b, .{ .target = default_target })); macho_step.dependOn(testDylib(b, .{ .target = default_target })); + macho_step.dependOn(testDylibVersionTbd(b, .{ .target = default_target })); macho_step.dependOn(testNeededLibrary(b, .{ .target = default_target })); macho_step.dependOn(testSearchStrategy(b, .{ .target = default_target })); macho_step.dependOn(testTbdv3(b, .{ .target = default_target })); @@ -243,6 +244,42 @@ fn testDylib(b: *Build, opts: Options) *Step { return test_step; } +fn testDylibVersionTbd(b: *Build, opts: Options) *Step { + const test_step = addTestStep(b, "macho-dylib-version-tbd", opts); + + const tbd = tbd: { + const wf = WriteFile.create(b); + break :tbd wf.add("liba.tbd", + \\--- !tapi-tbd + \\tbd-version: 4 + \\targets: [ x86_64-macos, arm64-macos ] + \\uuids: + \\ - target: x86_64-macos + \\ value: DEADBEEF + \\ - target: arm64-macos + \\ value: BEEFDEAD + \\install-name: '@rpath/liba.dylib' + \\current-version: 1.2 + \\exports: + \\ - targets: [ x86_64-macos, arm64-macos ] + \\ symbols: [ _foo ] + ); + }; + + const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = "int main() {}" }); + exe.root_module.linkSystemLibrary("a", .{}); + exe.root_module.addLibraryPath(tbd.dirname()); + + const check = exe.checkObject(); + check.checkInHeaders(); + check.checkExact("cmd LOAD_DYLIB"); + check.checkExact("name @rpath/liba.dylib"); + check.checkExact("current version 10200"); + test_step.dependOn(&check.step); + + return test_step; +} + fn testEmptyObject(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "macho-empty-object", opts);