From a454ba79083128e3172d2ca14fced9ec4a3763b1 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Mon, 15 Jan 2024 08:58:44 +0100 Subject: [PATCH] test/link/macho: upgrade dylib test --- test/link.zig | 4 ---- test/link/macho.zig | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/test/link.zig b/test/link.zig index b778b349a0..1085a35181 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/dylib", - .import = @import("link/macho/dylib/build.zig"), - }, .{ .build_root = "test/link/macho/empty", .import = @import("link/macho/empty/build.zig"), diff --git a/test/link/macho.zig b/test/link/macho.zig index ef50abe5cd..e3c481aed9 100644 --- a/test/link/macho.zig +++ b/test/link/macho.zig @@ -35,6 +35,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { // Tests requiring symlinks when tested on Windows if (build_opts.has_symlinks_windows) { + macho_step.dependOn(testDylib(b, .{ .target = default_target })); macho_step.dependOn(testNeededLibrary(b, .{ .target = default_target })); macho_step.dependOn(testWeakLibrary(b, .{ .target = default_target })); macho_step.dependOn(testTls(b, .{ .target = default_target })); @@ -182,6 +183,43 @@ fn testDeadStripDylibs(b: *Build, opts: Options) *Step { return test_step; } +fn testDylib(b: *Build, opts: Options) *Step { + const test_step = addTestStep(b, "macho-dylib", opts); + + const dylib = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes = + \\#include + \\char world[] = "world"; + \\char* hello() { + \\ return "Hello"; + \\} + }); + + const check = dylib.checkObject(); + check.checkInHeaders(); + check.checkExact("header"); + check.checkNotPresent("PIE"); + test_step.dependOn(&check.step); + + const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = + \\#include + \\char* hello(); + \\extern char world[]; + \\int main() { + \\ printf("%s %s", hello(), world); + \\ return 0; + \\} + }); + exe.root_module.linkSystemLibrary("a", .{}); + exe.addLibraryPath(dylib.getEmittedBinDirectory()); + exe.addRPath(dylib.getEmittedBinDirectory()); + + const run = addRunArtifact(exe); + run.expectStdOutEqual("Hello world"); + 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);