Creates a Step.Run with an executable built with addExecutable.
Add command line arguments with methods of Step.Run.
It doesn't have to target the host. In some cases cross-compiled binaries can even be executed.
This is declarative; it constructs a build step that may or may not be run depending on the options provided by the user to the build command.
See also:
addSystemCommandaddRunFilepub fn addRunArtifact(b: *Build, exe: *Step.Compile) *Step.Run
pub fn addRunArtifact(b: *Build, exe: *Step.Compile) *Step.Run {
// Avoid the common case of the step name looking like "run test test".
const step_name = if (exe.kind.isTest() and mem.eql(u8, exe.name, "test"))
b.fmt("run {t}", .{exe.kind})
else
b.fmt("run {t} {s}", .{ exe.kind, exe.name });
const run_step = Step.Run.create(b, step_name);
run_step.producer = exe;
if (exe.kind == .@"test") {
run_step.addArtifactArg(exe);
const test_server_mode: bool = s: {
if (exe.test_runner) |r| break :s r.mode == .server;
if (exe.use_llvm == false) {
// The default test runner does not use the server protocol if the selected backend
// is too immature to support it. Keep this logic in sync with `need_simple` in the
// default test runner implementation.
switch (exe.rootModuleTarget().cpu.arch) {
// stage2_aarch64
.aarch64,
.aarch64_be,
// stage2_powerpc
.powerpc,
.powerpcle,
.powerpc64,
.powerpc64le,
// stage2_riscv64
.riscv64,
=> break :s false,
else => {},
}
}
break :s true;
};
if (test_server_mode) {
run_step.enableTestRunnerMode();
} else if (exe.test_runner == null) {
// If a test runner does not use the `std.zig.Server` protocol, it can instead
// communicate failure via its exit code.
run_step.expectExitCode(0);
}
} else {
run_step.addArtifactArg(exe);
}
return run_step;
}