| author | |
| committer | |
| log | 24821dd17f3a23d9fb496ff8fa5dcbefb5b1d18d |
| tree | b1d487026eebdaf2fe65056808167e603c1c273f |
| parent | eadac4763135717ace3a7809ec5d6413b1699fcd |
7 files changed, 129 insertions(+), 0 deletions(-)
test/link.zig+8| ... | ... | @@ -60,5 +60,13 @@ pub fn addCases(cases: *tests.StandaloneContext) void { |
| 60 | 60 | cases.addBuildFile("test/link/macho/stack_size/build.zig", .{ |
| 61 | 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 | ||
| 3 | char world[] = "world"; | |
| 4 | ||
| 5 | char* hello() { | |
| 6 | return "Hello"; | |
| 7 | } |
test/link/macho/search_dylibs_first/build.zig created+48| ... | ... | @@ -0,0 +1,48 @@ |
| 1 | const std = @import("std"); | |
| 2 | const Builder = std.build.Builder; | |
| 3 | ||
| 4 | pub 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 | ||
| 3 | char* hello(); | |
| 4 | extern char world[]; | |
| 5 | ||
| 6 | int 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 | ||
| 3 | char world[] = "world"; | |
| 4 | ||
| 5 | char* hello() { | |
| 6 | return "Hello"; | |
| 7 | } |
test/link/macho/search_paths_first/build.zig created+41| ... | ... | @@ -0,0 +1,41 @@ |
| 1 | const std = @import("std"); | |
| 2 | const Builder = std.build.Builder; | |
| 3 | ||
| 4 | pub 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 | ||
| 3 | char* hello(); | |
| 4 | extern char world[]; | |
| 5 | ||
| 6 | int main() { | |
| 7 | printf("%s %s", hello(), world); | |
| 8 | return 0; | |
| 9 | } |