Commit 6e56a8df20

Jakub Konka <kubkon@jakubkonka.com>
2022-06-20 17:29:00
link-tests: CheckFileStep to do grep test on the binary
1 parent 38edef3
Changed files (3)
test/link/dylib/build.zig
@@ -24,6 +24,13 @@ pub fn build(b: *Builder) void {
     run.cwd = b.pathFromRoot(".");
     run.expectStdOutEqual("Hello world");
 
+    const exp_dylib = std.macho.createLoadDylibCommand(b.allocator, "@rpath/liba.dylib", 2, 0x10000, 0x10000) catch unreachable;
+    var buf = std.ArrayList(u8).init(b.allocator);
+    defer buf.deinit();
+    exp_dylib.write(buf.writer()) catch unreachable;
+    const check_file = std.build.CheckFileStep.create(b, exe.getOutputSource(), &[_][]const u8{buf.items});
+
     test_step.dependOn(b.getInstallStep());
     test_step.dependOn(&run.step);
+    test_step.dependOn(&check_file.step);
 }
test/link.zig
@@ -7,10 +7,6 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
         .build_modes = false, // we only guarantee zerofill for undefined in Debug
     });
 
-    cases.addBuildFile("test/link/dylib/build.zig", .{
-        .build_modes = true,
-    });
-
     cases.addBuildFile("test/link/common_symbols/build.zig", .{
         .build_modes = true,
     });
@@ -32,6 +28,10 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
     });
 
     if (builtin.os.tag == .macos) {
+        cases.addBuildFile("test/link/dylib/build.zig", .{
+            .build_modes = true,
+        });
+
         cases.addBuildFile("test/link/frameworks/build.zig", .{
             .build_modes = true,
             .requires_macos_sdk = true,
test/tests.zig
@@ -995,7 +995,8 @@ pub const StandaloneContext = struct {
         }
 
         if (features.cross_targets and !self.target.isNative()) {
-            const target_arg = fmt.allocPrint(b.allocator, "-Dtarget={s}", .{self.target.zigTriple(b.allocator) catch unreachable}) catch unreachable;
+            const target_triple = self.target.zigTriple(b.allocator) catch unreachable;
+            const target_arg = fmt.allocPrint(b.allocator, "-Dtarget={s}", .{target_triple}) catch unreachable;
             zig_args.append(target_arg) catch unreachable;
         }