diff --git a/lib/std/build/CheckObjectStep.zig b/lib/std/build/CheckObjectStep.zig index 375e183231aaa3d36e6c79fabed1f358e016c705..c7e91bb7cbbf548423b19a9cfc30869768547bfc 100644 --- a/lib/std/build/CheckObjectStep.zig +++ b/lib/std/build/CheckObjectStep.zig @@ -408,6 +408,8 @@ const MachODumper = struct { .ID_DYLIB, .LOAD_DYLIB, + .LOAD_WEAK_DYLIB, + .REEXPORT_DYLIB, => { const dylib = lc.dylib.inner.dylib; try writer.writeByte('\n'); diff --git a/test/link.zig b/test/link.zig index 6878881a6686c89d52bf47377723864c03265bcc..c578638ec3dd11f184dc1525a236695083aeef23 100644 --- a/test/link.zig +++ b/test/link.zig @@ -45,7 +45,11 @@ pub fn addCases(cases: *tests.StandaloneContext) void { .requires_macos_sdk = true, }); - cases.addBuildFile("test/link/macho/needed_l/build.zig", .{ + cases.addBuildFile("test/link/macho/needed_library/build.zig", .{ + .build_modes = true, + }); + + cases.addBuildFile("test/link/macho/weak_library/build.zig", .{ .build_modes = true, }); @@ -54,6 +58,11 @@ pub fn addCases(cases: *tests.StandaloneContext) void { .requires_macos_sdk = true, }); + cases.addBuildFile("test/link/macho/weak_framework/build.zig", .{ + .build_modes = true, + .requires_macos_sdk = true, + }); + // Try to build and run an Objective-C executable. cases.addBuildFile("test/link/macho/objc/build.zig", .{ .build_modes = true, diff --git a/test/link/macho/needed_l/a.c b/test/link/macho/needed_l/a.c deleted file mode 100644 index 4bcf8c97861b2f21f77c7901c7514def56533185..0000000000000000000000000000000000000000 --- a/test/link/macho/needed_l/a.c +++ /dev/null @@ -1 +0,0 @@ -int a = 42; diff --git a/test/link/macho/needed_l/build.zig b/test/link/macho/needed_l/build.zig deleted file mode 100644 index 708a09dc32e20415cd76dde8311f37785142568c..0000000000000000000000000000000000000000 --- a/test/link/macho/needed_l/build.zig +++ /dev/null @@ -1,35 +0,0 @@ -const std = @import("std"); -const Builder = std.build.Builder; -const LibExeObjectStep = std.build.LibExeObjStep; - -pub fn build(b: *Builder) void { - const mode = b.standardReleaseOptions(); - - const test_step = b.step("test", "Test the program"); - test_step.dependOn(b.getInstallStep()); - - const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); - dylib.setBuildMode(mode); - dylib.addCSourceFile("a.c", &.{}); - dylib.linkLibC(); - dylib.install(); - - // -dead_strip_dylibs - // -needed-la - const exe = b.addExecutable("test", null); - exe.addCSourceFile("main.c", &[0][]const u8{}); - exe.setBuildMode(mode); - exe.linkLibC(); - exe.linkSystemLibraryNeeded("a"); - exe.addLibraryPath(b.pathFromRoot("zig-out/lib")); - exe.addRPath(b.pathFromRoot("zig-out/lib")); - exe.dead_strip_dylibs = true; - - const check = exe.checkObject(.macho); - check.checkStart("cmd LOAD_DYLIB"); - check.checkNext("name @rpath/liba.dylib"); - test_step.dependOn(&check.step); - - const run_cmd = exe.run(); - test_step.dependOn(&run_cmd.step); -} diff --git a/test/link/macho/needed_l/main.c b/test/link/macho/needed_l/main.c deleted file mode 100644 index ca68d24cc70460626b8cb3168417e66ddc4404ea..0000000000000000000000000000000000000000 --- a/test/link/macho/needed_l/main.c +++ /dev/null @@ -1,3 +0,0 @@ -int main(int argc, char* argv[]) { - return 0; -} diff --git a/test/link/macho/needed_library/a.c b/test/link/macho/needed_library/a.c new file mode 100644 index 0000000000000000000000000000000000000000..4bcf8c97861b2f21f77c7901c7514def56533185 --- /dev/null +++ b/test/link/macho/needed_library/a.c @@ -0,0 +1 @@ +int a = 42; diff --git a/test/link/macho/needed_library/build.zig b/test/link/macho/needed_library/build.zig new file mode 100644 index 0000000000000000000000000000000000000000..708a09dc32e20415cd76dde8311f37785142568c --- /dev/null +++ b/test/link/macho/needed_library/build.zig @@ -0,0 +1,35 @@ +const std = @import("std"); +const Builder = std.build.Builder; +const LibExeObjectStep = std.build.LibExeObjStep; + +pub fn build(b: *Builder) void { + const mode = b.standardReleaseOptions(); + + const test_step = b.step("test", "Test the program"); + test_step.dependOn(b.getInstallStep()); + + const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); + dylib.setBuildMode(mode); + dylib.addCSourceFile("a.c", &.{}); + dylib.linkLibC(); + dylib.install(); + + // -dead_strip_dylibs + // -needed-la + const exe = b.addExecutable("test", null); + exe.addCSourceFile("main.c", &[0][]const u8{}); + exe.setBuildMode(mode); + exe.linkLibC(); + exe.linkSystemLibraryNeeded("a"); + exe.addLibraryPath(b.pathFromRoot("zig-out/lib")); + exe.addRPath(b.pathFromRoot("zig-out/lib")); + exe.dead_strip_dylibs = true; + + const check = exe.checkObject(.macho); + check.checkStart("cmd LOAD_DYLIB"); + check.checkNext("name @rpath/liba.dylib"); + test_step.dependOn(&check.step); + + const run_cmd = exe.run(); + test_step.dependOn(&run_cmd.step); +} diff --git a/test/link/macho/needed_library/main.c b/test/link/macho/needed_library/main.c new file mode 100644 index 0000000000000000000000000000000000000000..ca68d24cc70460626b8cb3168417e66ddc4404ea --- /dev/null +++ b/test/link/macho/needed_library/main.c @@ -0,0 +1,3 @@ +int main(int argc, char* argv[]) { + return 0; +} diff --git a/test/link/macho/weak_framework/build.zig b/test/link/macho/weak_framework/build.zig new file mode 100644 index 0000000000000000000000000000000000000000..44675a15f8e7597fb43f2790abfaea5dc92fa2da --- /dev/null +++ b/test/link/macho/weak_framework/build.zig @@ -0,0 +1,24 @@ +const std = @import("std"); +const Builder = std.build.Builder; +const LibExeObjectStep = std.build.LibExeObjStep; + +pub fn build(b: *Builder) void { + const mode = b.standardReleaseOptions(); + + const test_step = b.step("test", "Test the program"); + test_step.dependOn(b.getInstallStep()); + + const exe = b.addExecutable("test", null); + exe.addCSourceFile("main.c", &[0][]const u8{}); + exe.setBuildMode(mode); + exe.linkLibC(); + exe.linkFrameworkWeak("Cocoa"); + + const check = exe.checkObject(.macho); + check.checkStart("cmd LOAD_WEAK_DYLIB"); + check.checkNext("name {*}Cocoa"); + test_step.dependOn(&check.step); + + const run_cmd = exe.run(); + test_step.dependOn(&run_cmd.step); +} diff --git a/test/link/macho/weak_framework/main.c b/test/link/macho/weak_framework/main.c new file mode 100644 index 0000000000000000000000000000000000000000..ca68d24cc70460626b8cb3168417e66ddc4404ea --- /dev/null +++ b/test/link/macho/weak_framework/main.c @@ -0,0 +1,3 @@ +int main(int argc, char* argv[]) { + return 0; +} diff --git a/test/link/macho/weak_library/a.c b/test/link/macho/weak_library/a.c new file mode 100644 index 0000000000000000000000000000000000000000..9f49802ce6177e3cb5714de2b4ae8da459e1ceb2 --- /dev/null +++ b/test/link/macho/weak_library/a.c @@ -0,0 +1,9 @@ +#include + +int a = 42; + +const char* asStr() { + static char str[3]; + sprintf(str, "%d", 42); + return str; +} diff --git a/test/link/macho/weak_library/build.zig b/test/link/macho/weak_library/build.zig new file mode 100644 index 0000000000000000000000000000000000000000..5a1f7b4ce5d8afe2ffaace4432ab6e913eacf951 --- /dev/null +++ b/test/link/macho/weak_library/build.zig @@ -0,0 +1,33 @@ +const std = @import("std"); +const Builder = std.build.Builder; +const LibExeObjectStep = std.build.LibExeObjStep; + +pub fn build(b: *Builder) void { + const mode = b.standardReleaseOptions(); + + const test_step = b.step("test", "Test the program"); + test_step.dependOn(b.getInstallStep()); + + const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); + dylib.setBuildMode(mode); + dylib.addCSourceFile("a.c", &.{}); + dylib.linkLibC(); + dylib.install(); + + const exe = b.addExecutable("test", null); + exe.addCSourceFile("main.c", &[0][]const u8{}); + exe.setBuildMode(mode); + exe.linkLibC(); + exe.linkSystemLibraryWeak("a"); + exe.addLibraryPath(b.pathFromRoot("zig-out/lib")); + exe.addRPath(b.pathFromRoot("zig-out/lib")); + + const check = exe.checkObject(.macho); + check.checkStart("cmd LOAD_WEAK_DYLIB"); + check.checkNext("name @rpath/liba.dylib"); + test_step.dependOn(&check.step); + + const run_cmd = exe.run(); + run_cmd.expectStdOutEqual("42 42"); + test_step.dependOn(&run_cmd.step); +} diff --git a/test/link/macho/weak_library/main.c b/test/link/macho/weak_library/main.c new file mode 100644 index 0000000000000000000000000000000000000000..ee5367fef740e70d8161a41bc0ff69a1c17a2f78 --- /dev/null +++ b/test/link/macho/weak_library/main.c @@ -0,0 +1,9 @@ +#include + +extern int a; +extern const char* asStr(); + +int main(int argc, char* argv[]) { + printf("%d %s", a, asStr()); + return 0; +}