authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-06-24 22:03:56+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-06-24 22:07:51+02:00
log24821dd17f3a23d9fb496ff8fa5dcbefb5b1d18d
treeb1d487026eebdaf2fe65056808167e603c1c273f
parenteadac4763135717ace3a7809ec5d6413b1699fcd

link-tests: test -search_paths_first and -search_dylibs_first macho flags


7 files changed, 129 insertions(+), 0 deletions(-)

test/link.zig+8
...@@ -60,5 +60,13 @@ pub fn addCases(cases: *tests.StandaloneContext) void {...@@ -60,5 +60,13 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
60 cases.addBuildFile("test/link/macho/stack_size/build.zig", .{60 cases.addBuildFile("test/link/macho/stack_size/build.zig", .{
61 .build_modes = true,61 .build_modes = true,
62 });62 });
63
64 cases.addBuildFile("test/link/macho/search_paths_first/build.zig", .{
65 .build_modes = true,
66 });
67
68 cases.addBuildFile("test/link/macho/search_dylibs_first/build.zig", .{
69 .build_modes = true,
70 });
63 }71 }
64}72}
test/link/macho/search_dylibs_first/a.c created+7
...@@ -0,0 +1,7 @@
1#include <stdio.h>
2
3char world[] = "world";
4
5char* hello() {
6 return "Hello";
7}
test/link/macho/search_dylibs_first/build.zig created+48
...@@ -0,0 +1,48 @@
1const std = @import("std");
2const Builder = std.build.Builder;
3
4pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
6
7 const test_step = b.step("test", "Test");
8 test_step.dependOn(b.getInstallStep());
9
10 const static = b.addStaticLibrary("a", null);
11 static.setBuildMode(mode);
12 static.addCSourceFile("a.c", &.{});
13 static.linkLibC();
14 static.override_dest_dir = std.build.InstallDir{
15 .custom = "static",
16 };
17 static.install();
18
19 const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
20 dylib.setBuildMode(mode);
21 dylib.addCSourceFile("a.c", &.{});
22 dylib.linkLibC();
23 dylib.override_dest_dir = std.build.InstallDir{
24 .custom = "dynamic",
25 };
26 dylib.install();
27
28 const exe = b.addExecutable("main", null);
29 exe.setBuildMode(mode);
30 exe.addCSourceFile("main.c", &.{});
31 exe.linkSystemLibraryName("a");
32 exe.linkLibC();
33 exe.addLibraryPath(b.pathFromRoot("zig-out/static"));
34 exe.addLibraryPath(b.pathFromRoot("zig-out/dynamic"));
35 exe.addRPath(b.pathFromRoot("zig-out/dynamic"));
36 exe.search_strategy = .dylibs_first;
37
38 const check = exe.checkObject(.macho);
39 check.checkStart("cmd LOAD_DYLIB");
40 check.checkNext("name @rpath/liba.dylib");
41
42 test_step.dependOn(&check.step);
43
44 const run = exe.run();
45 run.cwd = b.pathFromRoot(".");
46 run.expectStdOutEqual("Hello world");
47 test_step.dependOn(&run.step);
48}
test/link/macho/search_dylibs_first/main.c created+9
...@@ -0,0 +1,9 @@
1#include <stdio.h>
2
3char* hello();
4extern char world[];
5
6int main() {
7 printf("%s %s", hello(), world);
8 return 0;
9}
test/link/macho/search_paths_first/a.c created+7
...@@ -0,0 +1,7 @@
1#include <stdio.h>
2
3char world[] = "world";
4
5char* hello() {
6 return "Hello";
7}
test/link/macho/search_paths_first/build.zig created+41
...@@ -0,0 +1,41 @@
1const std = @import("std");
2const Builder = std.build.Builder;
3
4pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
6
7 const test_step = b.step("test", "Test");
8 test_step.dependOn(b.getInstallStep());
9
10 const static = b.addStaticLibrary("a", null);
11 static.setBuildMode(mode);
12 static.addCSourceFile("a.c", &.{});
13 static.linkLibC();
14 static.override_dest_dir = std.build.InstallDir{
15 .custom = "static",
16 };
17 static.install();
18
19 const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
20 dylib.setBuildMode(mode);
21 dylib.addCSourceFile("a.c", &.{});
22 dylib.linkLibC();
23 dylib.override_dest_dir = std.build.InstallDir{
24 .custom = "dynamic",
25 };
26 dylib.install();
27
28 const exe = b.addExecutable("main", null);
29 exe.setBuildMode(mode);
30 exe.addCSourceFile("main.c", &.{});
31 exe.linkSystemLibraryName("a");
32 exe.linkLibC();
33 exe.addLibraryPath(b.pathFromRoot("zig-out/static"));
34 exe.addLibraryPath(b.pathFromRoot("zig-out/dynamic"));
35 exe.search_strategy = .paths_first;
36
37 const run = exe.run();
38 run.cwd = b.pathFromRoot(".");
39 run.expectStdOutEqual("Hello world");
40 test_step.dependOn(&run.step);
41}
test/link/macho/search_paths_first/main.c created+9
...@@ -0,0 +1,9 @@
1#include <stdio.h>
2
3char* hello();
4extern char world[];
5
6int main() {
7 printf("%s %s", hello(), world);
8 return 0;
9}