aboutsummaryrefslogtreecommitdiff
path: root/test/link/macho.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2024-01-14 10:20:22 +0100
committerJakub Konka <kubkon@jakubkonka.com>2024-01-24 12:34:40 +0100
commite96f8b817a889abecc86a71961ba9a95c13c315e (patch)
treeb0357bd6f7fe9661dcd6c5c5f741f9aab035f0d6 /test/link/macho.zig
parent1e0eb3c8097a3bd45cd5e6c7b67f6f7d4f974c6f (diff)
downloadzig-e96f8b817a889abecc86a71961ba9a95c13c315e.tar.gz
zig-e96f8b817a889abecc86a71961ba9a95c13c315e.zip
test/link/macho: upgrade weak library test
Diffstat (limited to 'test/link/macho.zig')
-rw-r--r--test/link/macho.zig44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/link/macho.zig b/test/link/macho.zig
index c03e87694d..5b4d0a3a28 100644
--- a/test/link/macho.zig
+++ b/test/link/macho.zig
@@ -26,6 +26,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(testNeededLibrary(b, .{ .target = default_target }));
+ macho_step.dependOn(testWeakLibrary(b, .{ .target = default_target }));
// Tests requiring presence of macOS SDK in system path
if (build_opts.has_macos_sdk) {
@@ -766,6 +767,49 @@ fn testWeakBind(b: *Build, opts: Options) *Step {
return test_step;
}
+fn testWeakLibrary(b: *Build, opts: Options) *Step {
+ const test_step = addTestStep(b, "macho-weak-library", opts);
+
+ const dylib = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes =
+ \\#include<stdio.h>
+ \\int a = 42;
+ \\const char* asStr() {
+ \\ static char str[3];
+ \\ sprintf(str, "%d", 42);
+ \\ return str;
+ \\}
+ });
+
+ const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
+ \\#include<stdio.h>
+ \\extern int a;
+ \\extern const char* asStr();
+ \\int main() {
+ \\ printf("%d %s", a, asStr());
+ \\ return 0;
+ \\}
+ });
+ exe.root_module.linkSystemLibrary("a", .{ .weak = true });
+ exe.addLibraryPath(dylib.getEmittedBinDirectory());
+ exe.addRPath(dylib.getEmittedBinDirectory());
+
+ const check = exe.checkObject();
+ check.checkInHeaders();
+ check.checkExact("cmd LOAD_WEAK_DYLIB");
+ check.checkContains("liba.dylib");
+ check.checkInSymtab();
+ check.checkExact("(undefined) weakref external _a (from liba)");
+ check.checkInSymtab();
+ check.checkExact("(undefined) weakref external _asStr (from liba)");
+ test_step.dependOn(&check.step);
+
+ const run = addRunArtifact(exe);
+ run.expectStdOutEqual("42 42");
+ test_step.dependOn(&run.step);
+
+ return test_step;
+}
+
fn addTestStep(b: *Build, comptime prefix: []const u8, opts: Options) *Step {
return link.addTestStep(b, "macho-" ++ prefix, opts);
}