zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit a454ba79083128e3172d2ca14fced9ec4a3763b1 (tree)
parent 8105390fff82f372645b01dbfe89f7972ba4e49d
Author: Jakub Konka <kubkon@jakubkonka.com>
Date:   Mon, 15 Jan 2024 08:58:44 +0100

test/link/macho: upgrade dylib test

Diffstat:
Mtest/link.zig | 4----
Mtest/link/macho.zig | 38++++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/test/link.zig b/test/link.zig @@ -108,10 +108,6 @@ pub const cases = [_]Case{ .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 @@ -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<stdio.h> + \\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<stdio.h> + \\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);