| author | |
| committer | |
| log | b70fedee7e61d0243211ef36635681fcb998ca54 |
| tree | b9bfd890f95530d50ec75d69394012d08bc481f5 |
| parent | 933231868ab37c67af53ab67aaf1355b5f50413a |
5 files changed, 70 insertions(+), 105 deletions(-)
test/link.zig-4| ... | ... | @@ -119,10 +119,6 @@ pub const cases = [_]Case{ |
| 119 | 119 | .build_root = "test/link/macho/reexports", |
| 120 | 120 | .import = @import("link/macho/reexports/build.zig"), |
| 121 | 121 | }, |
| 122 | .{ | |
| 123 | .build_root = "test/link/macho/search_strategy", | |
| 124 | .import = @import("link/macho/search_strategy/build.zig"), | |
| 125 | }, | |
| 126 | 122 | .{ |
| 127 | 123 | .build_root = "test/link/macho/stack_size", |
| 128 | 124 | .import = @import("link/macho/stack_size/build.zig"), |
test/link/macho.zig+70-1| ... | ... | @@ -45,9 +45,10 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { |
| 45 | 45 | macho_step.dependOn(testEntryPointDylib(b, .{ .target = default_target })); |
| 46 | 46 | macho_step.dependOn(testDylib(b, .{ .target = default_target })); |
| 47 | 47 | macho_step.dependOn(testNeededLibrary(b, .{ .target = default_target })); |
| 48 | macho_step.dependOn(testWeakLibrary(b, .{ .target = default_target })); | |
| 48 | macho_step.dependOn(testSearchStrategy(b, .{ .target = b.host })); | |
| 49 | 49 | macho_step.dependOn(testTls(b, .{ .target = default_target })); |
| 50 | 50 | macho_step.dependOn(testTwoLevelNamespace(b, .{ .target = default_target })); |
| 51 | macho_step.dependOn(testWeakLibrary(b, .{ .target = default_target })); | |
| 51 | 52 | |
| 52 | 53 | // Tests requiring presence of macOS SDK in system path |
| 53 | 54 | if (build_opts.has_macos_sdk) { |
| ... | ... | @@ -1046,6 +1047,74 @@ fn testRelocatableZig(b: *Build, opts: Options) *Step { |
| 1046 | 1047 | return test_step; |
| 1047 | 1048 | } |
| 1048 | 1049 | |
| 1050 | fn testSearchStrategy(b: *Build, opts: Options) *Step { | |
| 1051 | const test_step = addTestStep(b, "macho-search-strategy", opts); | |
| 1052 | ||
| 1053 | const obj = addObject(b, opts, .{ .name = "a", .c_source_bytes = | |
| 1054 | \\#include<stdio.h> | |
| 1055 | \\char world[] = "world"; | |
| 1056 | \\char* hello() { | |
| 1057 | \\ return "Hello"; | |
| 1058 | \\} | |
| 1059 | }); | |
| 1060 | ||
| 1061 | const liba = addStaticLibrary(b, opts, .{ .name = "a" }); | |
| 1062 | liba.addObject(obj); | |
| 1063 | ||
| 1064 | const dylib = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 1065 | dylib.addObject(obj); | |
| 1066 | ||
| 1067 | const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = | |
| 1068 | \\#include<stdio.h> | |
| 1069 | \\char* hello(); | |
| 1070 | \\extern char world[]; | |
| 1071 | \\int main() { | |
| 1072 | \\ printf("%s %s", hello(), world); | |
| 1073 | \\ return 0; | |
| 1074 | \\} | |
| 1075 | }); | |
| 1076 | ||
| 1077 | { | |
| 1078 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 1079 | exe.addObject(main_o); | |
| 1080 | exe.root_module.linkSystemLibrary("a", .{ .use_pkg_config = .no, .search_strategy = .mode_first }); | |
| 1081 | exe.root_module.addLibraryPath(liba.getEmittedBinDirectory()); | |
| 1082 | exe.root_module.addLibraryPath(dylib.getEmittedBinDirectory()); | |
| 1083 | exe.root_module.addRPath(dylib.getEmittedBinDirectory()); | |
| 1084 | ||
| 1085 | const run = addRunArtifact(exe); | |
| 1086 | run.expectStdOutEqual("Hello world"); | |
| 1087 | test_step.dependOn(&run.step); | |
| 1088 | ||
| 1089 | const check = exe.checkObject(); | |
| 1090 | check.checkInHeaders(); | |
| 1091 | check.checkExact("cmd LOAD_DYLIB"); | |
| 1092 | check.checkContains("liba.dylib"); | |
| 1093 | test_step.dependOn(&check.step); | |
| 1094 | } | |
| 1095 | ||
| 1096 | { | |
| 1097 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 1098 | exe.addObject(main_o); | |
| 1099 | exe.root_module.linkSystemLibrary("a", .{ .use_pkg_config = .no, .search_strategy = .paths_first }); | |
| 1100 | exe.root_module.addLibraryPath(liba.getEmittedBinDirectory()); | |
| 1101 | exe.root_module.addLibraryPath(dylib.getEmittedBinDirectory()); | |
| 1102 | exe.root_module.addRPath(dylib.getEmittedBinDirectory()); | |
| 1103 | ||
| 1104 | const run = addRunArtifact(exe); | |
| 1105 | run.expectStdOutEqual("Hello world"); | |
| 1106 | test_step.dependOn(&run.step); | |
| 1107 | ||
| 1108 | const check = exe.checkObject(); | |
| 1109 | check.checkInHeaders(); | |
| 1110 | check.checkExact("cmd LOAD_DYLIB"); | |
| 1111 | check.checkNotPresent("liba.dylib"); | |
| 1112 | test_step.dependOn(&check.step); | |
| 1113 | } | |
| 1114 | ||
| 1115 | return test_step; | |
| 1116 | } | |
| 1117 | ||
| 1049 | 1118 | fn testSectionBoundarySymbols(b: *Build, opts: Options) *Step { |
| 1050 | 1119 | const test_step = addTestStep(b, "macho-section-boundary-symbols", opts); |
| 1051 | 1120 |
test/link/macho/search_strategy/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_strategy/build.zig deleted-84| ... | ... | @@ -1,84 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | pub const requires_symlinks = true; | |
| 4 | ||
| 5 | pub fn build(b: *std.Build) void { | |
| 6 | const test_step = b.step("test", "Test it"); | |
| 7 | b.default_step = test_step; | |
| 8 | ||
| 9 | add(b, test_step, .Debug); | |
| 10 | add(b, test_step, .ReleaseFast); | |
| 11 | add(b, test_step, .ReleaseSmall); | |
| 12 | add(b, test_step, .ReleaseSafe); | |
| 13 | } | |
| 14 | ||
| 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | |
| 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); | |
| 17 | ||
| 18 | { | |
| 19 | // -search_dylibs_first | |
| 20 | const exe = createScenario(b, optimize, target, "search_dylibs_first", .mode_first); | |
| 21 | ||
| 22 | const check = exe.checkObject(); | |
| 23 | check.checkInHeaders(); | |
| 24 | check.checkExact("cmd LOAD_DYLIB"); | |
| 25 | check.checkExact("name @rpath/libsearch_dylibs_first.dylib"); | |
| 26 | test_step.dependOn(&check.step); | |
| 27 | ||
| 28 | const run = b.addRunArtifact(exe); | |
| 29 | run.skip_foreign_checks = true; | |
| 30 | run.expectStdOutEqual("Hello world"); | |
| 31 | test_step.dependOn(&run.step); | |
| 32 | } | |
| 33 | ||
| 34 | { | |
| 35 | // -search_paths_first | |
| 36 | const exe = createScenario(b, optimize, target, "search_paths_first", .paths_first); | |
| 37 | ||
| 38 | const run = b.addRunArtifact(exe); | |
| 39 | run.skip_foreign_checks = true; | |
| 40 | run.expectStdOutEqual("Hello world"); | |
| 41 | test_step.dependOn(&run.step); | |
| 42 | } | |
| 43 | } | |
| 44 | ||
| 45 | fn createScenario( | |
| 46 | b: *std.Build, | |
| 47 | optimize: std.builtin.OptimizeMode, | |
| 48 | target: std.Build.ResolvedTarget, | |
| 49 | name: []const u8, | |
| 50 | search_strategy: std.Build.Module.SystemLib.SearchStrategy, | |
| 51 | ) *std.Build.Step.Compile { | |
| 52 | const static = b.addStaticLibrary(.{ | |
| 53 | .name = name, | |
| 54 | .optimize = optimize, | |
| 55 | .target = target, | |
| 56 | }); | |
| 57 | static.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} }); | |
| 58 | static.linkLibC(); | |
| 59 | ||
| 60 | const dylib = b.addSharedLibrary(.{ | |
| 61 | .name = name, | |
| 62 | .version = .{ .major = 1, .minor = 0, .patch = 0 }, | |
| 63 | .optimize = optimize, | |
| 64 | .target = target, | |
| 65 | }); | |
| 66 | dylib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} }); | |
| 67 | dylib.linkLibC(); | |
| 68 | ||
| 69 | const exe = b.addExecutable(.{ | |
| 70 | .name = name, | |
| 71 | .optimize = optimize, | |
| 72 | .target = target, | |
| 73 | }); | |
| 74 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); | |
| 75 | exe.linkSystemLibrary2(name, .{ | |
| 76 | .use_pkg_config = .no, | |
| 77 | .search_strategy = search_strategy, | |
| 78 | }); | |
| 79 | exe.linkLibC(); | |
| 80 | exe.addLibraryPath(static.getEmittedBinDirectory()); | |
| 81 | exe.addLibraryPath(dylib.getEmittedBinDirectory()); | |
| 82 | exe.addRPath(dylib.getEmittedBinDirectory()); | |
| 83 | return exe; | |
| 84 | } |
test/link/macho/search_strategy/main.c deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | #include <stdio.h> | |
| 2 | ||
| 3 | char* hello(); | |
| 4 | extern char world[]; | |
| 5 | ||
| 6 | int main(int argc, char* argv[]) { | |
| 7 | printf("%s %s", hello(), world); | |
| 8 | return 0; | |
| 9 | } |