aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2023-07-26 18:22:59 +0200
committerGitHub <noreply@github.com>2023-07-26 18:22:59 +0200
commitf821543e4b5e44b2ca3217c189272105fc3effb9 (patch)
tree791536aa3ff2205cdaaa7052ea3dd596db3782ea /test
parentcb475aa161238ef0d77fc49b13c23f2c4b48bfc5 (diff)
parent960e5c329a5436d1e5748948c5744c1a11ddecbb (diff)
downloadzig-f821543e4b5e44b2ca3217c189272105fc3effb9.tar.gz
zig-f821543e4b5e44b2ca3217c189272105fc3effb9.zip
Merge pull request #16553 from ziglang/issue-11896
macho: fix parsing of TBDv3 dylib stubs
Diffstat (limited to 'test')
-rw-r--r--test/link.zig4
-rw-r--r--test/link/macho/tbdv3/a.c3
-rw-r--r--test/link/macho/tbdv3/build.zig57
-rw-r--r--test/link/macho/tbdv3/main.c7
4 files changed, 71 insertions, 0 deletions
diff --git a/test/link.zig b/test/link.zig
index c877e6c357..f79b4a478c 100644
--- a/test/link.zig
+++ b/test/link.zig
@@ -165,6 +165,10 @@ pub const cases = [_]Case{
.import = @import("link/macho/strict_validation/build.zig"),
},
.{
+ .build_root = "test/link/macho/tbdv3",
+ .import = @import("link/macho/tbdv3/build.zig"),
+ },
+ .{
.build_root = "test/link/macho/tls",
.import = @import("link/macho/tls/build.zig"),
},
diff --git a/test/link/macho/tbdv3/a.c b/test/link/macho/tbdv3/a.c
new file mode 100644
index 0000000000..ddd18ee4b6
--- /dev/null
+++ b/test/link/macho/tbdv3/a.c
@@ -0,0 +1,3 @@
+int getFoo() {
+ return 42;
+}
diff --git a/test/link/macho/tbdv3/build.zig b/test/link/macho/tbdv3/build.zig
new file mode 100644
index 0000000000..c2eb6df626
--- /dev/null
+++ b/test/link/macho/tbdv3/build.zig
@@ -0,0 +1,57 @@
+const std = @import("std");
+const builtin = @import("builtin");
+
+pub const requires_symlinks = true;
+pub const requires_macos_sdk = false;
+
+pub fn build(b: *std.Build) void {
+ const test_step = b.step("test", "Test it");
+ b.default_step = test_step;
+
+ add(b, test_step, .Debug);
+ add(b, test_step, .ReleaseFast);
+ add(b, test_step, .ReleaseSmall);
+ add(b, test_step, .ReleaseSafe);
+}
+
+fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
+ const target: std.zig.CrossTarget = .{ .os_tag = .macos };
+
+ const lib = b.addSharedLibrary(.{
+ .name = "a",
+ .version = .{ .major = 1, .minor = 0, .patch = 0 },
+ .optimize = optimize,
+ .target = target,
+ });
+ lib.addCSourceFile("a.c", &.{});
+ lib.linkLibC();
+
+ const tbd_file = b.addWriteFile("liba.tbd",
+ \\--- !tapi-tbd-v3
+ \\archs: [ arm64, x86_64 ]
+ \\uuids: [ 'arm64: DEADBEEF', 'x86_64: BEEFDEAD' ]
+ \\platform: macos
+ \\install-name: @rpath/liba.dylib
+ \\current-version: 0
+ \\exports:
+ \\ - archs: [ arm64, x86_64 ]
+ \\ symbols: [ _getFoo ]
+ );
+
+ const exe = b.addExecutable(.{
+ .name = "test",
+ .optimize = optimize,
+ .target = target,
+ });
+ exe.addCSourceFile("main.c", &[0][]const u8{});
+ exe.linkSystemLibrary("a");
+ exe.addLibraryPathDirectorySource(tbd_file.getDirectorySource());
+ exe.addRPathDirectorySource(lib.getOutputDirectorySource());
+ exe.linkLibC();
+
+ const run = b.addRunArtifact(exe);
+ run.skip_foreign_checks = true;
+ run.expectExitCode(0);
+
+ test_step.dependOn(&run.step);
+}
diff --git a/test/link/macho/tbdv3/main.c b/test/link/macho/tbdv3/main.c
new file mode 100644
index 0000000000..3cf37ae590
--- /dev/null
+++ b/test/link/macho/tbdv3/main.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int getFoo();
+
+int main() {
+ return getFoo() - 42;
+}