From 181e476915133091c6a51862861079151a4f19f1 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Sun, 14 Jan 2024 17:02:57 +0100 Subject: [PATCH] test/link/macho: upgrade dead_strip_dylibs test --- test/link.zig | 4 ---- test/link/macho.zig | 50 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/test/link.zig b/test/link.zig index b6d4a4fa40..b778b349a0 100644 --- a/test/link.zig +++ b/test/link.zig @@ -107,10 +107,6 @@ pub const cases = [_]Case{ .build_root = "test/link/macho/bugs/16628", .import = @import("link/macho/bugs/16628/build.zig"), }, - .{ - .build_root = "test/link/macho/dead_strip_dylibs", - .import = @import("link/macho/dead_strip_dylibs/build.zig"), - }, .{ .build_root = "test/link/macho/dylib", .import = @import("link/macho/dylib/build.zig"), diff --git a/test/link/macho.zig b/test/link/macho.zig index 38327bbdcf..85ff0142f2 100644 --- a/test/link/macho.zig +++ b/test/link/macho.zig @@ -42,6 +42,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { // Tests requiring presence of macOS SDK in system path if (build_opts.has_macos_sdk) { + macho_step.dependOn(testDeadStripDylibs(b, .{ .target = b.host })); macho_step.dependOn(testHeaderpad(b, .{ .target = b.host })); macho_step.dependOn(testNeededFramework(b, .{ .target = b.host })); macho_step.dependOn(testWeakFramework(b, .{ .target = b.host })); @@ -132,6 +133,55 @@ fn testDeadStrip(b: *Build, opts: Options) *Step { return test_step; } +fn testDeadStripDylibs(b: *Build, opts: Options) *Step { + const test_step = addTestStep(b, "macho-dead-strip-dylibs", opts); + + const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = + \\#include + \\int main() { + \\ if (objc_getClass("NSObject") == 0) { + \\ return -1; + \\ } + \\ if (objc_getClass("NSApplication") == 0) { + \\ return -2; + \\ } + \\ return 0; + \\} + }); + + { + const exe = addExecutable(b, opts, .{ .name = "main1" }); + exe.addObject(main_o); + exe.root_module.linkFramework("Cocoa", .{}); + + const check = exe.checkObject(); + check.checkInHeaders(); + check.checkExact("cmd LOAD_DYLIB"); + check.checkContains("Cocoa"); + check.checkInHeaders(); + check.checkExact("cmd LOAD_DYLIB"); + check.checkContains("libobjc"); + test_step.dependOn(&check.step); + + const run = addRunArtifact(exe); + run.expectExitCode(0); + test_step.dependOn(&run.step); + } + + { + const exe = addExecutable(b, opts, .{ .name = "main2" }); + exe.addObject(main_o); + exe.root_module.linkFramework("Cocoa", .{}); + exe.dead_strip_dylibs = true; + + const run = addRunArtifact(exe); + run.expectExitCode(@as(u8, @bitCast(@as(i8, -2)))); + test_step.dependOn(&run.step); + } + + return test_step; +} + fn testEntryPointDylib(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "macho-entry-point-dylib", opts);