| author | |
| committer | |
| log | e96f8b817a889abecc86a71961ba9a95c13c315e |
| tree | b0357bd6f7fe9661dcd6c5c5f741f9aab035f0d6 |
| parent | 1e0eb3c8097a3bd45cd5e6c7b67f6f7d4f974c6f |
5 files changed, 44 insertions(+), 77 deletions(-)
test/link.zig-4| ... | ... | @@ -171,10 +171,6 @@ pub const cases = [_]Case{ |
| 171 | 171 | .build_root = "test/link/macho/unwind_info", |
| 172 | 172 | .import = @import("link/macho/unwind_info/build.zig"), |
| 173 | 173 | }, |
| 174 | .{ | |
| 175 | .build_root = "test/link/macho/weak_library", | |
| 176 | .import = @import("link/macho/weak_library/build.zig"), | |
| 177 | }, | |
| 178 | 174 | .{ |
| 179 | 175 | .build_root = "test/link/macho/weak_framework", |
| 180 | 176 | .import = @import("link/macho/weak_framework/build.zig"), |
test/link/macho.zig+44| ... | ... | @@ -26,6 +26,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { |
| 26 | 26 | // Tests requiring symlinks when tested on Windows |
| 27 | 27 | if (build_opts.has_symlinks_windows) { |
| 28 | 28 | macho_step.dependOn(testNeededLibrary(b, .{ .target = default_target })); |
| 29 | macho_step.dependOn(testWeakLibrary(b, .{ .target = default_target })); | |
| 29 | 30 | |
| 30 | 31 | // Tests requiring presence of macOS SDK in system path |
| 31 | 32 | if (build_opts.has_macos_sdk) { |
| ... | ... | @@ -766,6 +767,49 @@ fn testWeakBind(b: *Build, opts: Options) *Step { |
| 766 | 767 | return test_step; |
| 767 | 768 | } |
| 768 | 769 | |
| 770 | fn testWeakLibrary(b: *Build, opts: Options) *Step { | |
| 771 | const test_step = addTestStep(b, "macho-weak-library", opts); | |
| 772 | ||
| 773 | const dylib = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes = | |
| 774 | \\#include<stdio.h> | |
| 775 | \\int a = 42; | |
| 776 | \\const char* asStr() { | |
| 777 | \\ static char str[3]; | |
| 778 | \\ sprintf(str, "%d", 42); | |
| 779 | \\ return str; | |
| 780 | \\} | |
| 781 | }); | |
| 782 | ||
| 783 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = | |
| 784 | \\#include<stdio.h> | |
| 785 | \\extern int a; | |
| 786 | \\extern const char* asStr(); | |
| 787 | \\int main() { | |
| 788 | \\ printf("%d %s", a, asStr()); | |
| 789 | \\ return 0; | |
| 790 | \\} | |
| 791 | }); | |
| 792 | exe.root_module.linkSystemLibrary("a", .{ .weak = true }); | |
| 793 | exe.addLibraryPath(dylib.getEmittedBinDirectory()); | |
| 794 | exe.addRPath(dylib.getEmittedBinDirectory()); | |
| 795 | ||
| 796 | const check = exe.checkObject(); | |
| 797 | check.checkInHeaders(); | |
| 798 | check.checkExact("cmd LOAD_WEAK_DYLIB"); | |
| 799 | check.checkContains("liba.dylib"); | |
| 800 | check.checkInSymtab(); | |
| 801 | check.checkExact("(undefined) weakref external _a (from liba)"); | |
| 802 | check.checkInSymtab(); | |
| 803 | check.checkExact("(undefined) weakref external _asStr (from liba)"); | |
| 804 | test_step.dependOn(&check.step); | |
| 805 | ||
| 806 | const run = addRunArtifact(exe); | |
| 807 | run.expectStdOutEqual("42 42"); | |
| 808 | test_step.dependOn(&run.step); | |
| 809 | ||
| 810 | return test_step; | |
| 811 | } | |
| 812 | ||
| 769 | 813 | fn addTestStep(b: *Build, comptime prefix: []const u8, opts: Options) *Step { |
| 770 | 814 | return link.addTestStep(b, "macho-" ++ prefix, opts); |
| 771 | 815 | } |
test/link/macho/weak_library/a.c deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | #include <stdio.h> | |
| 2 | ||
| 3 | int a = 42; | |
| 4 | ||
| 5 | const char* asStr() { | |
| 6 | static char str[3]; | |
| 7 | sprintf(str, "%d", 42); | |
| 8 | return str; | |
| 9 | } |
test/link/macho/weak_library/build.zig deleted-55| ... | ... | @@ -1,55 +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 | const dylib = b.addSharedLibrary(.{ | |
| 19 | .name = "a", | |
| 20 | .version = .{ .major = 1, .minor = 0, .patch = 0 }, | |
| 21 | .target = target, | |
| 22 | .optimize = optimize, | |
| 23 | }); | |
| 24 | dylib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} }); | |
| 25 | dylib.linkLibC(); | |
| 26 | b.installArtifact(dylib); | |
| 27 | ||
| 28 | const exe = b.addExecutable(.{ | |
| 29 | .name = "test", | |
| 30 | .target = target, | |
| 31 | .optimize = optimize, | |
| 32 | }); | |
| 33 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); | |
| 34 | exe.linkLibC(); | |
| 35 | exe.root_module.linkSystemLibrary("a", .{ .weak = true }); | |
| 36 | exe.addLibraryPath(dylib.getEmittedBinDirectory()); | |
| 37 | exe.addRPath(dylib.getEmittedBinDirectory()); | |
| 38 | ||
| 39 | const check = exe.checkObject(); | |
| 40 | check.checkInHeaders(); | |
| 41 | check.checkExact("cmd LOAD_WEAK_DYLIB"); | |
| 42 | check.checkExact("name @rpath/liba.dylib"); | |
| 43 | ||
| 44 | check.checkInSymtab(); | |
| 45 | check.checkExact("(undefined) weakref external _a (from liba)"); | |
| 46 | ||
| 47 | check.checkInSymtab(); | |
| 48 | check.checkExact("(undefined) weakref external _asStr (from liba)"); | |
| 49 | test_step.dependOn(&check.step); | |
| 50 | ||
| 51 | const run = b.addRunArtifact(exe); | |
| 52 | run.skip_foreign_checks = true; | |
| 53 | run.expectStdOutEqual("42 42"); | |
| 54 | test_step.dependOn(&run.step); | |
| 55 | } |
test/link/macho/weak_library/main.c deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | #include <stdio.h> | |
| 2 | ||
| 3 | extern int a; | |
| 4 | extern const char* asStr(); | |
| 5 | ||
| 6 | int main(int argc, char* argv[]) { | |
| 7 | printf("%d %s", a, asStr()); | |
| 8 | return 0; | |
| 9 | } |