| author | |
| committer | |
| log | 8f00bc9d231c0c686b2ffa3bd0b14181afa7a171 |
| tree | 9aac8869b99ae2927dad90be5ec2a75b1cd20bad |
| parent | dfdb807543a03eec27341deec6a5f3b88f87fac3 |
10 files changed, 85 insertions(+), 126 deletions(-)
test/link.zig+1-5| ... | ... | @@ -61,11 +61,7 @@ pub fn addCases(cases: *tests.StandaloneContext) void { |
| 61 | 61 | .build_modes = true, |
| 62 | 62 | }); |
| 63 | 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", .{ | |
| 64 | cases.addBuildFile("test/link/macho/search_strategy/build.zig", .{ | |
| 69 | 65 | .build_modes = true, |
| 70 | 66 | }); |
| 71 | 67 | } |
test/link/macho/search_dylibs_first/a.c deleted-7| ... | ... | @@ -1,7 +0,0 @@ |
| 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 deleted-48| ... | ... | @@ -1,48 +0,0 @@ |
| 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 deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 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 deleted-7| ... | ... | @@ -1,7 +0,0 @@ |
| 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 deleted-41| ... | ... | @@ -1,41 +0,0 @@ |
| 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 deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 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_strategy/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_strategy/build.zig created+68| ... | ... | @@ -0,0 +1,68 @@ |
| 1 | const std = @import("std"); | |
| 2 | const Builder = std.build.Builder; | |
| 3 | const LibExeObjectStep = std.build.LibExeObjStep; | |
| 4 | ||
| 5 | pub fn build(b: *Builder) void { | |
| 6 | const mode = b.standardReleaseOptions(); | |
| 7 | ||
| 8 | const test_step = b.step("test", "Test"); | |
| 9 | test_step.dependOn(b.getInstallStep()); | |
| 10 | ||
| 11 | { | |
| 12 | // -search_dylibs_first | |
| 13 | const exe = createScenario(b, mode); | |
| 14 | exe.search_strategy = .dylibs_first; | |
| 15 | ||
| 16 | const check = exe.checkObject(.macho); | |
| 17 | check.checkStart("cmd LOAD_DYLIB"); | |
| 18 | check.checkNext("name @rpath/liba.dylib"); | |
| 19 | ||
| 20 | test_step.dependOn(&check.step); | |
| 21 | ||
| 22 | const run = exe.run(); | |
| 23 | run.cwd = b.pathFromRoot("."); | |
| 24 | run.expectStdOutEqual("Hello world"); | |
| 25 | test_step.dependOn(&run.step); | |
| 26 | } | |
| 27 | ||
| 28 | { | |
| 29 | // -search_paths_first | |
| 30 | const exe = createScenario(b, mode); | |
| 31 | exe.search_strategy = .paths_first; | |
| 32 | ||
| 33 | const run = exe.run(); | |
| 34 | run.cwd = b.pathFromRoot("."); | |
| 35 | run.expectStdOutEqual("Hello world"); | |
| 36 | test_step.dependOn(&run.step); | |
| 37 | } | |
| 38 | } | |
| 39 | ||
| 40 | fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep { | |
| 41 | const static = b.addStaticLibrary("a", null); | |
| 42 | static.setBuildMode(mode); | |
| 43 | static.addCSourceFile("a.c", &.{}); | |
| 44 | static.linkLibC(); | |
| 45 | static.override_dest_dir = std.build.InstallDir{ | |
| 46 | .custom = "static", | |
| 47 | }; | |
| 48 | static.install(); | |
| 49 | ||
| 50 | const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); | |
| 51 | dylib.setBuildMode(mode); | |
| 52 | dylib.addCSourceFile("a.c", &.{}); | |
| 53 | dylib.linkLibC(); | |
| 54 | dylib.override_dest_dir = std.build.InstallDir{ | |
| 55 | .custom = "dynamic", | |
| 56 | }; | |
| 57 | dylib.install(); | |
| 58 | ||
| 59 | const exe = b.addExecutable("main", null); | |
| 60 | exe.setBuildMode(mode); | |
| 61 | exe.addCSourceFile("main.c", &.{}); | |
| 62 | exe.linkSystemLibraryName("a"); | |
| 63 | exe.linkLibC(); | |
| 64 | exe.addLibraryPath(b.pathFromRoot("zig-out/static")); | |
| 65 | exe.addLibraryPath(b.pathFromRoot("zig-out/dynamic")); | |
| 66 | exe.addRPath(b.pathFromRoot("zig-out/dynamic")); | |
| 67 | return exe; | |
| 68 | } |
test/link/macho/search_strategy/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 | } |