aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2022-06-25 17:55:26 +0200
committerGitHub <noreply@github.com>2022-06-25 17:55:26 +0200
commit0078d36ff39f2ef35e32f2d58e5d447b62f3a37e (patch)
tree37793e2032189f83915a829dac0bd425264b488e /test
parent905a18849f7f2c3f269fbf425170e0c86b12524a (diff)
parent8f00bc9d231c0c686b2ffa3bd0b14181afa7a171 (diff)
downloadzig-0078d36ff39f2ef35e32f2d58e5d447b62f3a37e.tar.gz
zig-0078d36ff39f2ef35e32f2d58e5d447b62f3a37e.zip
Merge pull request #11917 from motiejus/wl-search-paths
macho: implement `-search_paths_first` and `-search_dylibs_first`
Diffstat (limited to 'test')
-rw-r--r--test/link.zig4
-rw-r--r--test/link/macho/search_strategy/a.c7
-rw-r--r--test/link/macho/search_strategy/build.zig68
-rw-r--r--test/link/macho/search_strategy/main.c9
4 files changed, 88 insertions, 0 deletions
diff --git a/test/link.zig b/test/link.zig
index 42ce12f73c..62bdcff4b0 100644
--- a/test/link.zig
+++ b/test/link.zig
@@ -60,5 +60,9 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
cases.addBuildFile("test/link/macho/stack_size/build.zig", .{
.build_modes = true,
});
+
+ cases.addBuildFile("test/link/macho/search_strategy/build.zig", .{
+ .build_modes = true,
+ });
}
}
diff --git a/test/link/macho/search_strategy/a.c b/test/link/macho/search_strategy/a.c
new file mode 100644
index 0000000000..199b31e1a0
--- /dev/null
+++ b/test/link/macho/search_strategy/a.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+char world[] = "world";
+
+char* hello() {
+ return "Hello";
+}
diff --git a/test/link/macho/search_strategy/build.zig b/test/link/macho/search_strategy/build.zig
new file mode 100644
index 0000000000..c5e867c8d0
--- /dev/null
+++ b/test/link/macho/search_strategy/build.zig
@@ -0,0 +1,68 @@
+const std = @import("std");
+const Builder = std.build.Builder;
+const LibExeObjectStep = std.build.LibExeObjStep;
+
+pub fn build(b: *Builder) void {
+ const mode = b.standardReleaseOptions();
+
+ const test_step = b.step("test", "Test");
+ test_step.dependOn(b.getInstallStep());
+
+ {
+ // -search_dylibs_first
+ const exe = createScenario(b, mode);
+ exe.search_strategy = .dylibs_first;
+
+ const check = exe.checkObject(.macho);
+ check.checkStart("cmd LOAD_DYLIB");
+ check.checkNext("name @rpath/liba.dylib");
+
+ test_step.dependOn(&check.step);
+
+ const run = exe.run();
+ run.cwd = b.pathFromRoot(".");
+ run.expectStdOutEqual("Hello world");
+ test_step.dependOn(&run.step);
+ }
+
+ {
+ // -search_paths_first
+ const exe = createScenario(b, mode);
+ exe.search_strategy = .paths_first;
+
+ const run = exe.run();
+ run.cwd = b.pathFromRoot(".");
+ run.expectStdOutEqual("Hello world");
+ test_step.dependOn(&run.step);
+ }
+}
+
+fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep {
+ const static = b.addStaticLibrary("a", null);
+ static.setBuildMode(mode);
+ static.addCSourceFile("a.c", &.{});
+ static.linkLibC();
+ static.override_dest_dir = std.build.InstallDir{
+ .custom = "static",
+ };
+ static.install();
+
+ const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
+ dylib.setBuildMode(mode);
+ dylib.addCSourceFile("a.c", &.{});
+ dylib.linkLibC();
+ dylib.override_dest_dir = std.build.InstallDir{
+ .custom = "dynamic",
+ };
+ dylib.install();
+
+ const exe = b.addExecutable("main", null);
+ exe.setBuildMode(mode);
+ exe.addCSourceFile("main.c", &.{});
+ exe.linkSystemLibraryName("a");
+ exe.linkLibC();
+ exe.addLibraryPath(b.pathFromRoot("zig-out/static"));
+ exe.addLibraryPath(b.pathFromRoot("zig-out/dynamic"));
+ exe.addRPath(b.pathFromRoot("zig-out/dynamic"));
+ return exe;
+}
diff --git a/test/link/macho/search_strategy/main.c b/test/link/macho/search_strategy/main.c
new file mode 100644
index 0000000000..be1647ddad
--- /dev/null
+++ b/test/link/macho/search_strategy/main.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+char* hello();
+extern char world[];
+
+int main() {
+ printf("%s %s", hello(), world);
+ return 0;
+}