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) {...@@ -56,7 +56,12 @@ pub const StdIoAction = union(enum) {
56pub fn create(builder: *Builder, name: []const u8, artifact: *LibExeObjStep) *EmulatableRunStep {56pub fn create(builder: *Builder, name: []const u8, artifact: *LibExeObjStep) *EmulatableRunStep {
57 std.debug.assert(artifact.kind == .exe or artifact.kind == .test_exe);57 std.debug.assert(artifact.kind == .exe or artifact.kind == .test_exe);
58 const self = builder.allocator.create(EmulatableRunStep) catch unreachable;58 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
60 self.* = .{65 self.* = .{
61 .builder = builder,66 .builder = builder,
62 .step = Step.init(.emulatable_run, name, builder.allocator, make),67 .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;...@@ -3,12 +3,14 @@ const Builder = std.build.Builder;
33
4pub fn build(b: *Builder) void {4pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();5 const mode = b.standardReleaseOptions();
6 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
67
7 const test_step = b.step("test", "Test");8 const test_step = b.step("test", "Test");
8 test_step.dependOn(b.getInstallStep());9 test_step.dependOn(b.getInstallStep());
910
10 const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));11 const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
11 dylib.setBuildMode(mode);12 dylib.setBuildMode(mode);
13 dylib.setTarget(target);
12 dylib.addCSourceFile("a.c", &.{});14 dylib.addCSourceFile("a.c", &.{});
13 dylib.linkLibC();15 dylib.linkLibC();
14 dylib.install();16 dylib.install();
...@@ -23,6 +25,7 @@ pub fn build(b: *Builder) void {...@@ -23,6 +25,7 @@ pub fn build(b: *Builder) void {
23 test_step.dependOn(&check_dylib.step);25 test_step.dependOn(&check_dylib.step);
2426
25 const exe = b.addExecutable("main", null);27 const exe = b.addExecutable("main", null);
28 exe.setTarget(target);
26 exe.setBuildMode(mode);29 exe.setBuildMode(mode);
27 exe.addCSourceFile("main.c", &.{});30 exe.addCSourceFile("main.c", &.{});
28 exe.linkSystemLibrary("a");31 exe.linkSystemLibrary("a");
...@@ -40,9 +43,7 @@ pub fn build(b: *Builder) void {...@@ -40,9 +43,7 @@ pub fn build(b: *Builder) void {
40 check_exe.checkStart("cmd RPATH");43 check_exe.checkStart("cmd RPATH");
41 check_exe.checkNext(std.fmt.allocPrint(b.allocator, "path {s}", .{b.pathFromRoot("zig-out/lib")}) catch unreachable);44 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);46 const run = check_exe.runAndCompare();
44
45 const run = exe.run();
46 run.cwd = b.pathFromRoot(".");47 run.cwd = b.pathFromRoot(".");
47 run.expectStdOutEqual("Hello world");48 run.expectStdOutEqual("Hello world");
48 test_step.dependOn(&run.step);49 test_step.dependOn(&run.step);
test/link/macho/entry/build.zig+2-3
...@@ -8,6 +8,7 @@ pub fn build(b: *Builder) void {...@@ -8,6 +8,7 @@ pub fn build(b: *Builder) void {
8 test_step.dependOn(b.getInstallStep());8 test_step.dependOn(b.getInstallStep());
99
10 const exe = b.addExecutable("main", null);10 const exe = b.addExecutable("main", null);
11 exe.setTarget(.{ .os_tag = .macos });
11 exe.setBuildMode(mode);12 exe.setBuildMode(mode);
12 exe.addCSourceFile("main.c", &.{});13 exe.addCSourceFile("main.c", &.{});
13 exe.linkLibC();14 exe.linkLibC();
...@@ -26,9 +27,7 @@ pub fn build(b: *Builder) void {...@@ -26,9 +27,7 @@ pub fn build(b: *Builder) void {
2627
27 check_exe.checkComputeCompare("vmaddr entryoff +", .{ .op = .eq, .value = .{ .variable = "n_value" } });28 check_exe.checkComputeCompare("vmaddr entryoff +", .{ .op = .eq, .value = .{ .variable = "n_value" } });
2829
29 test_step.dependOn(&check_exe.step);30 const run = check_exe.runAndCompare();
30
31 const run = exe.run();
32 run.expectStdOutEqual("42");31 run.expectStdOutEqual("42");
33 test_step.dependOn(&run.step);32 test_step.dependOn(&run.step);
34}33}
test/link/macho/needed_library/build.zig+4-2
...@@ -4,11 +4,13 @@ const LibExeObjectStep = std.build.LibExeObjStep;...@@ -4,11 +4,13 @@ const LibExeObjectStep = std.build.LibExeObjStep;
44
5pub fn build(b: *Builder) void {5pub fn build(b: *Builder) void {
6 const mode = b.standardReleaseOptions();6 const mode = b.standardReleaseOptions();
7 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
78
8 const test_step = b.step("test", "Test the program");9 const test_step = b.step("test", "Test the program");
9 test_step.dependOn(b.getInstallStep());10 test_step.dependOn(b.getInstallStep());
1011
11 const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));12 const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
13 dylib.setTarget(target);
12 dylib.setBuildMode(mode);14 dylib.setBuildMode(mode);
13 dylib.addCSourceFile("a.c", &.{});15 dylib.addCSourceFile("a.c", &.{});
14 dylib.linkLibC();16 dylib.linkLibC();
...@@ -19,6 +21,7 @@ pub fn build(b: *Builder) void {...@@ -19,6 +21,7 @@ pub fn build(b: *Builder) void {
19 const exe = b.addExecutable("test", null);21 const exe = b.addExecutable("test", null);
20 exe.addCSourceFile("main.c", &[0][]const u8{});22 exe.addCSourceFile("main.c", &[0][]const u8{});
21 exe.setBuildMode(mode);23 exe.setBuildMode(mode);
24 exe.setTarget(target);
22 exe.linkLibC();25 exe.linkLibC();
23 exe.linkSystemLibraryNeeded("a");26 exe.linkSystemLibraryNeeded("a");
24 exe.addLibraryPath(b.pathFromRoot("zig-out/lib"));27 exe.addLibraryPath(b.pathFromRoot("zig-out/lib"));
...@@ -28,8 +31,7 @@ pub fn build(b: *Builder) void {...@@ -28,8 +31,7 @@ pub fn build(b: *Builder) void {
28 const check = exe.checkObject(.macho);31 const check = exe.checkObject(.macho);
29 check.checkStart("cmd LOAD_DYLIB");32 check.checkStart("cmd LOAD_DYLIB");
30 check.checkNext("name @rpath/liba.dylib");33 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();
34 test_step.dependOn(&run_cmd.step);36 test_step.dependOn(&run_cmd.step);
35}37}
test/link/macho/objc/build.zig+1-2
...@@ -7,7 +7,6 @@ pub fn build(b: *Builder) void {...@@ -7,7 +7,6 @@ pub fn build(b: *Builder) void {
7 const test_step = b.step("test", "Test the program");7 const test_step = b.step("test", "Test the program");
88
9 const exe = b.addExecutable("test", null);9 const exe = b.addExecutable("test", null);
10 b.default_step.dependOn(&exe.step);
11 exe.addIncludePath(".");10 exe.addIncludePath(".");
12 exe.addCSourceFile("Foo.m", &[0][]const u8{});11 exe.addCSourceFile("Foo.m", &[0][]const u8{});
13 exe.addCSourceFile("test.m", &[0][]const u8{});12 exe.addCSourceFile("test.m", &[0][]const u8{});
...@@ -17,6 +16,6 @@ pub fn build(b: *Builder) void {...@@ -17,6 +16,6 @@ pub fn build(b: *Builder) void {
17 // populate paths to the sysroot here.16 // populate paths to the sysroot here.
18 exe.linkFramework("Foundation");17 exe.linkFramework("Foundation");
1918
20 const run_cmd = exe.run();19 const run_cmd = std.build.EmulatableRunStep.create(b, "run", exe);
21 test_step.dependOn(&run_cmd.step);20 test_step.dependOn(&run_cmd.step);
22}21}
test/link/macho/pagezero/build.zig+2
...@@ -9,6 +9,7 @@ pub fn build(b: *Builder) void {...@@ -9,6 +9,7 @@ pub fn build(b: *Builder) void {
99
10 {10 {
11 const exe = b.addExecutable("pagezero", null);11 const exe = b.addExecutable("pagezero", null);
12 exe.setTarget(.{ .os_tag = .macos });
12 exe.setBuildMode(mode);13 exe.setBuildMode(mode);
13 exe.addCSourceFile("main.c", &.{});14 exe.addCSourceFile("main.c", &.{});
14 exe.linkLibC();15 exe.linkLibC();
...@@ -28,6 +29,7 @@ pub fn build(b: *Builder) void {...@@ -28,6 +29,7 @@ pub fn build(b: *Builder) void {
2829
29 {30 {
30 const exe = b.addExecutable("no_pagezero", null);31 const exe = b.addExecutable("no_pagezero", null);
32 exe.setTarget(.{ .os_tag = .macos });
31 exe.setBuildMode(mode);33 exe.setBuildMode(mode);
32 exe.addCSourceFile("main.c", &.{});34 exe.addCSourceFile("main.c", &.{});
33 exe.linkLibC();35 exe.linkLibC();
test/link/macho/search_strategy/build.zig+6-4
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const Builder = std.build.Builder;2const Builder = std.build.Builder;
3const LibExeObjectStep = std.build.LibExeObjStep;3const LibExeObjectStep = std.build.LibExeObjStep;
4const target: std.zig.CrossTarget = .{ .os_tag = .macos };
45
5pub fn build(b: *Builder) void {6pub fn build(b: *Builder) void {
6 const mode = b.standardReleaseOptions();7 const mode = b.standardReleaseOptions();
...@@ -17,9 +18,7 @@ pub fn build(b: *Builder) void {...@@ -17,9 +18,7 @@ pub fn build(b: *Builder) void {
17 check.checkStart("cmd LOAD_DYLIB");18 check.checkStart("cmd LOAD_DYLIB");
18 check.checkNext("name @rpath/liba.dylib");19 check.checkNext("name @rpath/liba.dylib");
1920
20 test_step.dependOn(&check.step);21 const run = check.runAndCompare();
21
22 const run = exe.run();
23 run.cwd = b.pathFromRoot(".");22 run.cwd = b.pathFromRoot(".");
24 run.expectStdOutEqual("Hello world");23 run.expectStdOutEqual("Hello world");
25 test_step.dependOn(&run.step);24 test_step.dependOn(&run.step);
...@@ -30,7 +29,7 @@ pub fn build(b: *Builder) void {...@@ -30,7 +29,7 @@ pub fn build(b: *Builder) void {
30 const exe = createScenario(b, mode);29 const exe = createScenario(b, mode);
31 exe.search_strategy = .paths_first;30 exe.search_strategy = .paths_first;
3231
33 const run = exe.run();32 const run = std.build.EmulatableRunStep.create(b, "run", exe);
34 run.cwd = b.pathFromRoot(".");33 run.cwd = b.pathFromRoot(".");
35 run.expectStdOutEqual("Hello world");34 run.expectStdOutEqual("Hello world");
36 test_step.dependOn(&run.step);35 test_step.dependOn(&run.step);
...@@ -39,6 +38,7 @@ pub fn build(b: *Builder) void {...@@ -39,6 +38,7 @@ pub fn build(b: *Builder) void {
3938
40fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep {39fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep {
41 const static = b.addStaticLibrary("a", null);40 const static = b.addStaticLibrary("a", null);
41 static.setTarget(target);
42 static.setBuildMode(mode);42 static.setBuildMode(mode);
43 static.addCSourceFile("a.c", &.{});43 static.addCSourceFile("a.c", &.{});
44 static.linkLibC();44 static.linkLibC();
...@@ -48,6 +48,7 @@ fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep {...@@ -48,6 +48,7 @@ fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep {
48 static.install();48 static.install();
4949
50 const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));50 const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
51 dylib.setTarget(target);
51 dylib.setBuildMode(mode);52 dylib.setBuildMode(mode);
52 dylib.addCSourceFile("a.c", &.{});53 dylib.addCSourceFile("a.c", &.{});
53 dylib.linkLibC();54 dylib.linkLibC();
...@@ -57,6 +58,7 @@ fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep {...@@ -57,6 +58,7 @@ fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep {
57 dylib.install();58 dylib.install();
5859
59 const exe = b.addExecutable("main", null);60 const exe = b.addExecutable("main", null);
61 exe.setTarget(target);
60 exe.setBuildMode(mode);62 exe.setBuildMode(mode);
61 exe.addCSourceFile("main.c", &.{});63 exe.addCSourceFile("main.c", &.{});
62 exe.linkSystemLibraryName("a");64 exe.linkSystemLibraryName("a");
test/link/macho/stack_size/build.zig+2-3
...@@ -8,6 +8,7 @@ pub fn build(b: *Builder) void {...@@ -8,6 +8,7 @@ pub fn build(b: *Builder) void {
8 test_step.dependOn(b.getInstallStep());8 test_step.dependOn(b.getInstallStep());
99
10 const exe = b.addExecutable("main", null);10 const exe = b.addExecutable("main", null);
11 exe.setTarget(.{ .os_tag = .macos });
11 exe.setBuildMode(mode);12 exe.setBuildMode(mode);
12 exe.addCSourceFile("main.c", &.{});13 exe.addCSourceFile("main.c", &.{});
13 exe.linkLibC();14 exe.linkLibC();
...@@ -17,8 +18,6 @@ pub fn build(b: *Builder) void {...@@ -17,8 +18,6 @@ pub fn build(b: *Builder) void {
17 check_exe.checkStart("cmd MAIN");18 check_exe.checkStart("cmd MAIN");
18 check_exe.checkNext("stacksize 100000000");19 check_exe.checkNext("stacksize 100000000");
1920
20 test_step.dependOn(&check_exe.step);21 const run = check_exe.runAndCompare();
21
22 const run = exe.run();
23 test_step.dependOn(&run.step);22 test_step.dependOn(&run.step);
24}23}
test/link/macho/weak_library/build.zig+4-3
...@@ -4,11 +4,13 @@ const LibExeObjectStep = std.build.LibExeObjStep;...@@ -4,11 +4,13 @@ const LibExeObjectStep = std.build.LibExeObjStep;
44
5pub fn build(b: *Builder) void {5pub fn build(b: *Builder) void {
6 const mode = b.standardReleaseOptions();6 const mode = b.standardReleaseOptions();
7 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
78
8 const test_step = b.step("test", "Test the program");9 const test_step = b.step("test", "Test the program");
9 test_step.dependOn(b.getInstallStep());10 test_step.dependOn(b.getInstallStep());
1011
11 const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));12 const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
13 dylib.setTarget(target);
12 dylib.setBuildMode(mode);14 dylib.setBuildMode(mode);
13 dylib.addCSourceFile("a.c", &.{});15 dylib.addCSourceFile("a.c", &.{});
14 dylib.linkLibC();16 dylib.linkLibC();
...@@ -16,6 +18,7 @@ pub fn build(b: *Builder) void {...@@ -16,6 +18,7 @@ pub fn build(b: *Builder) void {
1618
17 const exe = b.addExecutable("test", null);19 const exe = b.addExecutable("test", null);
18 exe.addCSourceFile("main.c", &[0][]const u8{});20 exe.addCSourceFile("main.c", &[0][]const u8{});
21 exe.setTarget(target);
19 exe.setBuildMode(mode);22 exe.setBuildMode(mode);
20 exe.linkLibC();23 exe.linkLibC();
21 exe.linkSystemLibraryWeak("a");24 exe.linkSystemLibraryWeak("a");
...@@ -30,9 +33,7 @@ pub fn build(b: *Builder) void {...@@ -30,9 +33,7 @@ pub fn build(b: *Builder) void {
30 check.checkNext("(undefined) weak external _a (from liba)");33 check.checkNext("(undefined) weak external _a (from liba)");
31 check.checkNext("(undefined) weak external _asStr (from liba)");34 check.checkNext("(undefined) weak external _asStr (from liba)");
3235
33 test_step.dependOn(&check.step);36 const run_cmd = check.runAndCompare();
34
35 const run_cmd = exe.run();
36 run_cmd.expectStdOutEqual("42 42");37 run_cmd.expectStdOutEqual("42 42");
37 test_step.dependOn(&run_cmd.step);38 test_step.dependOn(&run_cmd.step);
38}39}