authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-14 17:02:57+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-24 12:34:40+01:00
log181e476915133091c6a51862861079151a4f19f1
tree3f16a8117fbbef91d8f8e93908910b7bb9337098
parentb038bcb93b7a3e254be3fb2f1979680ffa99aa48

test/link/macho: upgrade dead_strip_dylibs test


2 files changed, 50 insertions(+), 4 deletions(-)

test/link.zig-4
......@@ -107,10 +107,6 @@ pub const cases = [_]Case{
107107 .build_root = "test/link/macho/bugs/16628",
108108 .import = @import("link/macho/bugs/16628/build.zig"),
109109 },
110 .{
111 .build_root = "test/link/macho/dead_strip_dylibs",
112 .import = @import("link/macho/dead_strip_dylibs/build.zig"),
113 },
114110 .{
115111 .build_root = "test/link/macho/dylib",
116112 .import = @import("link/macho/dylib/build.zig"),
test/link/macho.zig+50
......@@ -42,6 +42,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
4242
4343 // Tests requiring presence of macOS SDK in system path
4444 if (build_opts.has_macos_sdk) {
45 macho_step.dependOn(testDeadStripDylibs(b, .{ .target = b.host }));
4546 macho_step.dependOn(testHeaderpad(b, .{ .target = b.host }));
4647 macho_step.dependOn(testNeededFramework(b, .{ .target = b.host }));
4748 macho_step.dependOn(testWeakFramework(b, .{ .target = b.host }));
......@@ -132,6 +133,55 @@ fn testDeadStrip(b: *Build, opts: Options) *Step {
132133 return test_step;
133134}
134135
136fn testDeadStripDylibs(b: *Build, opts: Options) *Step {
137 const test_step = addTestStep(b, "macho-dead-strip-dylibs", opts);
138
139 const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes =
140 \\#include <objc/runtime.h>
141 \\int main() {
142 \\ if (objc_getClass("NSObject") == 0) {
143 \\ return -1;
144 \\ }
145 \\ if (objc_getClass("NSApplication") == 0) {
146 \\ return -2;
147 \\ }
148 \\ return 0;
149 \\}
150 });
151
152 {
153 const exe = addExecutable(b, opts, .{ .name = "main1" });
154 exe.addObject(main_o);
155 exe.root_module.linkFramework("Cocoa", .{});
156
157 const check = exe.checkObject();
158 check.checkInHeaders();
159 check.checkExact("cmd LOAD_DYLIB");
160 check.checkContains("Cocoa");
161 check.checkInHeaders();
162 check.checkExact("cmd LOAD_DYLIB");
163 check.checkContains("libobjc");
164 test_step.dependOn(&check.step);
165
166 const run = addRunArtifact(exe);
167 run.expectExitCode(0);
168 test_step.dependOn(&run.step);
169 }
170
171 {
172 const exe = addExecutable(b, opts, .{ .name = "main2" });
173 exe.addObject(main_o);
174 exe.root_module.linkFramework("Cocoa", .{});
175 exe.dead_strip_dylibs = true;
176
177 const run = addRunArtifact(exe);
178 run.expectExitCode(@as(u8, @bitCast(@as(i8, -2))));
179 test_step.dependOn(&run.step);
180 }
181
182 return test_step;
183}
184
135185fn testEntryPointDylib(b: *Build, opts: Options) *Step {
136186 const test_step = addTestStep(b, "macho-entry-point-dylib", opts);
137187