| author | |
| committer | |
| log | 075f5bc5ffdbe0a458a733d596a1fc4a74b8e1ab |
| tree | 03202c54ac0b5c5d3e12ebfc4a5a433ab4a57ca9 |
| parent | 20bd722464699bd11a05fe8e250f9f8086853cf2 |
13 files changed, 129 insertions(+), 40 deletions(-)
lib/std/build/CheckObjectStep.zig+2| ... | ... | @@ -408,6 +408,8 @@ const MachODumper = struct { |
| 408 | 408 | |
| 409 | 409 | .ID_DYLIB, |
| 410 | 410 | .LOAD_DYLIB, |
| 411 | .LOAD_WEAK_DYLIB, | |
| 412 | .REEXPORT_DYLIB, | |
| 411 | 413 | => { |
| 412 | 414 | const dylib = lc.dylib.inner.dylib; |
| 413 | 415 | try writer.writeByte('\n'); |
test/link.zig+10-1| ... | ... | @@ -45,7 +45,11 @@ pub fn addCases(cases: *tests.StandaloneContext) void { |
| 45 | 45 | .requires_macos_sdk = true, |
| 46 | 46 | }); |
| 47 | 47 | |
| 48 | cases.addBuildFile("test/link/macho/needed_l/build.zig", .{ | |
| 48 | cases.addBuildFile("test/link/macho/needed_library/build.zig", .{ | |
| 49 | .build_modes = true, | |
| 50 | }); | |
| 51 | ||
| 52 | cases.addBuildFile("test/link/macho/weak_library/build.zig", .{ | |
| 49 | 53 | .build_modes = true, |
| 50 | 54 | }); |
| 51 | 55 | |
| ... | ... | @@ -54,6 +58,11 @@ pub fn addCases(cases: *tests.StandaloneContext) void { |
| 54 | 58 | .requires_macos_sdk = true, |
| 55 | 59 | }); |
| 56 | 60 | |
| 61 | cases.addBuildFile("test/link/macho/weak_framework/build.zig", .{ | |
| 62 | .build_modes = true, | |
| 63 | .requires_macos_sdk = true, | |
| 64 | }); | |
| 65 | ||
| 57 | 66 | // Try to build and run an Objective-C executable. |
| 58 | 67 | cases.addBuildFile("test/link/macho/objc/build.zig", .{ |
| 59 | 68 | .build_modes = true, |
test/link/macho/needed_l/a.c deleted-1| ... | ... | @@ -1 +0,0 @@ |
| 1 | int a = 42; |
test/link/macho/needed_l/build.zig deleted-35| ... | ... | @@ -1,35 +0,0 @@ |
| 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 the program"); | |
| 9 | test_step.dependOn(b.getInstallStep()); | |
| 10 | ||
| 11 | const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); | |
| 12 | dylib.setBuildMode(mode); | |
| 13 | dylib.addCSourceFile("a.c", &.{}); | |
| 14 | dylib.linkLibC(); | |
| 15 | dylib.install(); | |
| 16 | ||
| 17 | // -dead_strip_dylibs | |
| 18 | // -needed-la | |
| 19 | const exe = b.addExecutable("test", null); | |
| 20 | exe.addCSourceFile("main.c", &[0][]const u8{}); | |
| 21 | exe.setBuildMode(mode); | |
| 22 | exe.linkLibC(); | |
| 23 | exe.linkSystemLibraryNeeded("a"); | |
| 24 | exe.addLibraryPath(b.pathFromRoot("zig-out/lib")); | |
| 25 | exe.addRPath(b.pathFromRoot("zig-out/lib")); | |
| 26 | exe.dead_strip_dylibs = true; | |
| 27 | ||
| 28 | const check = exe.checkObject(.macho); | |
| 29 | check.checkStart("cmd LOAD_DYLIB"); | |
| 30 | check.checkNext("name @rpath/liba.dylib"); | |
| 31 | test_step.dependOn(&check.step); | |
| 32 | ||
| 33 | const run_cmd = exe.run(); | |
| 34 | test_step.dependOn(&run_cmd.step); | |
| 35 | } |
test/link/macho/needed_l/main.c deleted-3| ... | ... | @@ -1,3 +0,0 @@ |
| 1 | int main(int argc, char* argv[]) { | |
| 2 | return 0; | |
| 3 | } |
test/link/macho/needed_library/a.c created+1| ... | ... | @@ -0,0 +1 @@ |
| 1 | int a = 42; |
test/link/macho/needed_library/build.zig created+35| ... | ... | @@ -0,0 +1,35 @@ |
| 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 the program"); | |
| 9 | test_step.dependOn(b.getInstallStep()); | |
| 10 | ||
| 11 | const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); | |
| 12 | dylib.setBuildMode(mode); | |
| 13 | dylib.addCSourceFile("a.c", &.{}); | |
| 14 | dylib.linkLibC(); | |
| 15 | dylib.install(); | |
| 16 | ||
| 17 | // -dead_strip_dylibs | |
| 18 | // -needed-la | |
| 19 | const exe = b.addExecutable("test", null); | |
| 20 | exe.addCSourceFile("main.c", &[0][]const u8{}); | |
| 21 | exe.setBuildMode(mode); | |
| 22 | exe.linkLibC(); | |
| 23 | exe.linkSystemLibraryNeeded("a"); | |
| 24 | exe.addLibraryPath(b.pathFromRoot("zig-out/lib")); | |
| 25 | exe.addRPath(b.pathFromRoot("zig-out/lib")); | |
| 26 | exe.dead_strip_dylibs = true; | |
| 27 | ||
| 28 | const check = exe.checkObject(.macho); | |
| 29 | check.checkStart("cmd LOAD_DYLIB"); | |
| 30 | check.checkNext("name @rpath/liba.dylib"); | |
| 31 | test_step.dependOn(&check.step); | |
| 32 | ||
| 33 | const run_cmd = exe.run(); | |
| 34 | test_step.dependOn(&run_cmd.step); | |
| 35 | } |
test/link/macho/needed_library/main.c created+3| ... | ... | @@ -0,0 +1,3 @@ |
| 1 | int main(int argc, char* argv[]) { | |
| 2 | return 0; | |
| 3 | } |
test/link/macho/weak_framework/build.zig created+24| ... | ... | @@ -0,0 +1,24 @@ |
| 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 the program"); | |
| 9 | test_step.dependOn(b.getInstallStep()); | |
| 10 | ||
| 11 | const exe = b.addExecutable("test", null); | |
| 12 | exe.addCSourceFile("main.c", &[0][]const u8{}); | |
| 13 | exe.setBuildMode(mode); | |
| 14 | exe.linkLibC(); | |
| 15 | exe.linkFrameworkWeak("Cocoa"); | |
| 16 | ||
| 17 | const check = exe.checkObject(.macho); | |
| 18 | check.checkStart("cmd LOAD_WEAK_DYLIB"); | |
| 19 | check.checkNext("name {*}Cocoa"); | |
| 20 | test_step.dependOn(&check.step); | |
| 21 | ||
| 22 | const run_cmd = exe.run(); | |
| 23 | test_step.dependOn(&run_cmd.step); | |
| 24 | } |
test/link/macho/weak_framework/main.c created+3| ... | ... | @@ -0,0 +1,3 @@ |
| 1 | int main(int argc, char* argv[]) { | |
| 2 | return 0; | |
| 3 | } |
test/link/macho/weak_library/a.c created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 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 created+33| ... | ... | @@ -0,0 +1,33 @@ |
| 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 the program"); | |
| 9 | test_step.dependOn(b.getInstallStep()); | |
| 10 | ||
| 11 | const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); | |
| 12 | dylib.setBuildMode(mode); | |
| 13 | dylib.addCSourceFile("a.c", &.{}); | |
| 14 | dylib.linkLibC(); | |
| 15 | dylib.install(); | |
| 16 | ||
| 17 | const exe = b.addExecutable("test", null); | |
| 18 | exe.addCSourceFile("main.c", &[0][]const u8{}); | |
| 19 | exe.setBuildMode(mode); | |
| 20 | exe.linkLibC(); | |
| 21 | exe.linkSystemLibraryWeak("a"); | |
| 22 | exe.addLibraryPath(b.pathFromRoot("zig-out/lib")); | |
| 23 | exe.addRPath(b.pathFromRoot("zig-out/lib")); | |
| 24 | ||
| 25 | const check = exe.checkObject(.macho); | |
| 26 | check.checkStart("cmd LOAD_WEAK_DYLIB"); | |
| 27 | check.checkNext("name @rpath/liba.dylib"); | |
| 28 | test_step.dependOn(&check.step); | |
| 29 | ||
| 30 | const run_cmd = exe.run(); | |
| 31 | run_cmd.expectStdOutEqual("42 42"); | |
| 32 | test_step.dependOn(&run_cmd.step); | |
| 33 | } |
test/link/macho/weak_library/main.c created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 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 | } |