authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-07-10 16:25:16+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-07-23 10:03:51+02:00
log4776065036f9878c86e54fa83341fe8cdbb175f0
treeb45ef95236a0bdc2eaf80c98b2773c638dc39679
parent735b6eefe92b222a0405671517b67e3b6c5cdded
signature Commit is signed but in an unrecognized format.

Use `EmulatableRunStep` for MachO linker tests


9 files changed, 31 insertions(+), 21 deletions(-)

lib/std/build/EmulatableRunStep.zig+6-1
......@@ -56,7 +56,12 @@ pub const StdIoAction = union(enum) {
5656pub fn create(builder: *Builder, name: []const u8, artifact: *LibExeObjStep) *EmulatableRunStep {
5757 std.debug.assert(artifact.kind == .exe or artifact.kind == .test_exe);
5858 const self = builder.allocator.create(EmulatableRunStep) catch unreachable;
59 const hide_warnings = builder.option(bool, "hide-foreign-warnings", "Hide the warning when a foreign binary which is incompatible is skipped") orelse false;
59
60 const option_name = "hide-foreign-warnings";
61 const hide_warnings = if (builder.available_options_map.get(option_name) == null) warn: {
62 break :warn builder.option(bool, option_name, "Hide the warning when a foreign binary which is incompatible is skipped") orelse false;
63 } else false;
64
6065 self.* = .{
6166 .builder = builder,
6267 .step = Step.init(.emulatable_run, name, builder.allocator, make),
test/link/macho/dylib/build.zig+4-3
......@@ -3,12 +3,14 @@ const Builder = std.build.Builder;
33
44pub fn build(b: *Builder) void {
55 const mode = b.standardReleaseOptions();
6 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
67
78 const test_step = b.step("test", "Test");
89 test_step.dependOn(b.getInstallStep());
910
1011 const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
1112 dylib.setBuildMode(mode);
13 dylib.setTarget(target);
1214 dylib.addCSourceFile("a.c", &.{});
1315 dylib.linkLibC();
1416 dylib.install();
......@@ -23,6 +25,7 @@ pub fn build(b: *Builder) void {
2325 test_step.dependOn(&check_dylib.step);
2426
2527 const exe = b.addExecutable("main", null);
28 exe.setTarget(target);
2629 exe.setBuildMode(mode);
2730 exe.addCSourceFile("main.c", &.{});
2831 exe.linkSystemLibrary("a");
......@@ -40,9 +43,7 @@ pub fn build(b: *Builder) void {
4043 check_exe.checkStart("cmd RPATH");
4144 check_exe.checkNext(std.fmt.allocPrint(b.allocator, "path {s}", .{b.pathFromRoot("zig-out/lib")}) catch unreachable);
4245
43 test_step.dependOn(&check_exe.step);
44
45 const run = exe.run();
46 const run = check_exe.runAndCompare();
4647 run.cwd = b.pathFromRoot(".");
4748 run.expectStdOutEqual("Hello world");
4849 test_step.dependOn(&run.step);
test/link/macho/entry/build.zig+2-3
......@@ -8,6 +8,7 @@ pub fn build(b: *Builder) void {
88 test_step.dependOn(b.getInstallStep());
99
1010 const exe = b.addExecutable("main", null);
11 exe.setTarget(.{ .os_tag = .macos });
1112 exe.setBuildMode(mode);
1213 exe.addCSourceFile("main.c", &.{});
1314 exe.linkLibC();
......@@ -26,9 +27,7 @@ pub fn build(b: *Builder) void {
2627
2728 check_exe.checkComputeCompare("vmaddr entryoff +", .{ .op = .eq, .value = .{ .variable = "n_value" } });
2829
29 test_step.dependOn(&check_exe.step);
30
31 const run = exe.run();
30 const run = check_exe.runAndCompare();
3231 run.expectStdOutEqual("42");
3332 test_step.dependOn(&run.step);
3433}
test/link/macho/needed_library/build.zig+4-2
......@@ -4,11 +4,13 @@ const LibExeObjectStep = std.build.LibExeObjStep;
44
55pub fn build(b: *Builder) void {
66 const mode = b.standardReleaseOptions();
7 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
78
89 const test_step = b.step("test", "Test the program");
910 test_step.dependOn(b.getInstallStep());
1011
1112 const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
13 dylib.setTarget(target);
1214 dylib.setBuildMode(mode);
1315 dylib.addCSourceFile("a.c", &.{});
1416 dylib.linkLibC();
......@@ -19,6 +21,7 @@ pub fn build(b: *Builder) void {
1921 const exe = b.addExecutable("test", null);
2022 exe.addCSourceFile("main.c", &[0][]const u8{});
2123 exe.setBuildMode(mode);
24 exe.setTarget(target);
2225 exe.linkLibC();
2326 exe.linkSystemLibraryNeeded("a");
2427 exe.addLibraryPath(b.pathFromRoot("zig-out/lib"));
......@@ -28,8 +31,7 @@ pub fn build(b: *Builder) void {
2831 const check = exe.checkObject(.macho);
2932 check.checkStart("cmd LOAD_DYLIB");
3033 check.checkNext("name @rpath/liba.dylib");
31 test_step.dependOn(&check.step);
3234
33 const run_cmd = exe.run();
35 const run_cmd = check.runAndCompare();
3436 test_step.dependOn(&run_cmd.step);
3537}
test/link/macho/objc/build.zig+1-2
......@@ -7,7 +7,6 @@ pub fn build(b: *Builder) void {
77 const test_step = b.step("test", "Test the program");
88
99 const exe = b.addExecutable("test", null);
10 b.default_step.dependOn(&exe.step);
1110 exe.addIncludePath(".");
1211 exe.addCSourceFile("Foo.m", &[0][]const u8{});
1312 exe.addCSourceFile("test.m", &[0][]const u8{});
......@@ -17,6 +16,6 @@ pub fn build(b: *Builder) void {
1716 // populate paths to the sysroot here.
1817 exe.linkFramework("Foundation");
1918
20 const run_cmd = exe.run();
19 const run_cmd = std.build.EmulatableRunStep.create(b, "run", exe);
2120 test_step.dependOn(&run_cmd.step);
2221}
test/link/macho/pagezero/build.zig+2
......@@ -9,6 +9,7 @@ pub fn build(b: *Builder) void {
99
1010 {
1111 const exe = b.addExecutable("pagezero", null);
12 exe.setTarget(.{ .os_tag = .macos });
1213 exe.setBuildMode(mode);
1314 exe.addCSourceFile("main.c", &.{});
1415 exe.linkLibC();
......@@ -28,6 +29,7 @@ pub fn build(b: *Builder) void {
2829
2930 {
3031 const exe = b.addExecutable("no_pagezero", null);
32 exe.setTarget(.{ .os_tag = .macos });
3133 exe.setBuildMode(mode);
3234 exe.addCSourceFile("main.c", &.{});
3335 exe.linkLibC();
test/link/macho/search_strategy/build.zig+6-4
......@@ -1,6 +1,7 @@
11const std = @import("std");
22const Builder = std.build.Builder;
33const LibExeObjectStep = std.build.LibExeObjStep;
4const target: std.zig.CrossTarget = .{ .os_tag = .macos };
45
56pub fn build(b: *Builder) void {
67 const mode = b.standardReleaseOptions();
......@@ -17,9 +18,7 @@ pub fn build(b: *Builder) void {
1718 check.checkStart("cmd LOAD_DYLIB");
1819 check.checkNext("name @rpath/liba.dylib");
1920
20 test_step.dependOn(&check.step);
21
22 const run = exe.run();
21 const run = check.runAndCompare();
2322 run.cwd = b.pathFromRoot(".");
2423 run.expectStdOutEqual("Hello world");
2524 test_step.dependOn(&run.step);
......@@ -30,7 +29,7 @@ pub fn build(b: *Builder) void {
3029 const exe = createScenario(b, mode);
3130 exe.search_strategy = .paths_first;
3231
33 const run = exe.run();
32 const run = std.build.EmulatableRunStep.create(b, "run", exe);
3433 run.cwd = b.pathFromRoot(".");
3534 run.expectStdOutEqual("Hello world");
3635 test_step.dependOn(&run.step);
......@@ -39,6 +38,7 @@ pub fn build(b: *Builder) void {
3938
4039fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep {
4140 const static = b.addStaticLibrary("a", null);
41 static.setTarget(target);
4242 static.setBuildMode(mode);
4343 static.addCSourceFile("a.c", &.{});
4444 static.linkLibC();
......@@ -48,6 +48,7 @@ fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep {
4848 static.install();
4949
5050 const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
51 dylib.setTarget(target);
5152 dylib.setBuildMode(mode);
5253 dylib.addCSourceFile("a.c", &.{});
5354 dylib.linkLibC();
......@@ -57,6 +58,7 @@ fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep {
5758 dylib.install();
5859
5960 const exe = b.addExecutable("main", null);
61 exe.setTarget(target);
6062 exe.setBuildMode(mode);
6163 exe.addCSourceFile("main.c", &.{});
6264 exe.linkSystemLibraryName("a");
test/link/macho/stack_size/build.zig+2-3
......@@ -8,6 +8,7 @@ pub fn build(b: *Builder) void {
88 test_step.dependOn(b.getInstallStep());
99
1010 const exe = b.addExecutable("main", null);
11 exe.setTarget(.{ .os_tag = .macos });
1112 exe.setBuildMode(mode);
1213 exe.addCSourceFile("main.c", &.{});
1314 exe.linkLibC();
......@@ -17,8 +18,6 @@ pub fn build(b: *Builder) void {
1718 check_exe.checkStart("cmd MAIN");
1819 check_exe.checkNext("stacksize 100000000");
1920
20 test_step.dependOn(&check_exe.step);
21
22 const run = exe.run();
21 const run = check_exe.runAndCompare();
2322 test_step.dependOn(&run.step);
2423}
test/link/macho/weak_library/build.zig+4-3
......@@ -4,11 +4,13 @@ const LibExeObjectStep = std.build.LibExeObjStep;
44
55pub fn build(b: *Builder) void {
66 const mode = b.standardReleaseOptions();
7 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
78
89 const test_step = b.step("test", "Test the program");
910 test_step.dependOn(b.getInstallStep());
1011
1112 const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
13 dylib.setTarget(target);
1214 dylib.setBuildMode(mode);
1315 dylib.addCSourceFile("a.c", &.{});
1416 dylib.linkLibC();
......@@ -16,6 +18,7 @@ pub fn build(b: *Builder) void {
1618
1719 const exe = b.addExecutable("test", null);
1820 exe.addCSourceFile("main.c", &[0][]const u8{});
21 exe.setTarget(target);
1922 exe.setBuildMode(mode);
2023 exe.linkLibC();
2124 exe.linkSystemLibraryWeak("a");
......@@ -30,9 +33,7 @@ pub fn build(b: *Builder) void {
3033 check.checkNext("(undefined) weak external _a (from liba)");
3134 check.checkNext("(undefined) weak external _asStr (from liba)");
3235
33 test_step.dependOn(&check.step);
34
35 const run_cmd = exe.run();
36 const run_cmd = check.runAndCompare();
3637 run_cmd.expectStdOutEqual("42 42");
3738 test_step.dependOn(&run_cmd.step);
3839}