Skip to content

Commit ed82e19

Browse files
committed
Add target.*.runner configuration for targets
This commit adds a `runner` field configuration to `config.toml` for specifying a wrapper executable when executing binaries for a target. This is pulled out of rust-lang#122036 where a WebAssembly runtime is used, for example, to execute tests for `wasm32-wasip1`. The name "runner" here is chosen to match Cargo's `CARGO_*_RUNNER` configuration, and to make things a bit more consistent this additionally renames compiletest's `--runtool` argument to `--runner`.
1 parent bfe762e commit ed82e19

File tree

7 files changed

+38
-7
lines changed

7 files changed

+38
-7
lines changed

config.example.toml

+11
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,17 @@
838838
# See that option for more info.
839839
#codegen-backends = rust.codegen-backends (array)
840840

841+
# This is a "runner" to pass to `compiletest` when executing tests. Tests will
842+
# execute this tool where the binary-to-test is passed as an argument. Can
843+
# be useful for situations such as when WebAssembly is being tested and a
844+
# runtime needs to be configured. This value is similar to
845+
# Cargo's `CARGO_$target_RUNNER` configuration.
846+
#
847+
# This configuration is a space-separated list of arguments so `foo bar` would
848+
# execute the program `foo` with the first argument as `bar` and the second
849+
# argument as the test binary.
850+
#runner = <none> (string)
851+
841852
# =============================================================================
842853
# Distribution options
843854
#

src/bootstrap/src/core/build_steps/test.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,8 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
19701970

19711971
if builder.remote_tested(target) {
19721972
cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
1973+
} else if let Some(tool) = builder.runner(target) {
1974+
cmd.arg("--runner").arg(tool);
19731975
}
19741976

19751977
if suite != "mir-opt" {
@@ -2519,6 +2521,8 @@ fn prepare_cargo_test(
25192521
format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
25202522
format!("{} run 0", builder.tool_exe(Tool::RemoteTestClient).display()),
25212523
);
2524+
} else if let Some(tool) = builder.runner(target) {
2525+
cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)), tool);
25222526
}
25232527

25242528
cargo

src/bootstrap/src/core/config/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ pub struct Target {
578578
pub musl_libdir: Option<PathBuf>,
579579
pub wasi_root: Option<PathBuf>,
580580
pub qemu_rootfs: Option<PathBuf>,
581+
pub runner: Option<String>,
581582
pub no_std: bool,
582583
pub codegen_backends: Option<Vec<Interned<String>>>,
583584
}
@@ -1140,6 +1141,7 @@ define_config! {
11401141
qemu_rootfs: Option<String> = "qemu-rootfs",
11411142
no_std: Option<bool> = "no-std",
11421143
codegen_backends: Option<Vec<String>> = "codegen-backends",
1144+
runner: Option<String> = "runner",
11431145
}
11441146
}
11451147

@@ -1858,6 +1860,7 @@ impl Config {
18581860
target.musl_libdir = cfg.musl_libdir.map(PathBuf::from);
18591861
target.wasi_root = cfg.wasi_root.map(PathBuf::from);
18601862
target.qemu_rootfs = cfg.qemu_rootfs.map(PathBuf::from);
1863+
target.runner = cfg.runner;
18611864
target.sanitizers = cfg.sanitizers;
18621865
target.profiler = cfg.profiler;
18631866
target.rpath = cfg.rpath;

src/bootstrap/src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,17 @@ impl Build {
13531353
|| env::var_os("TEST_DEVICE_ADDR").is_some()
13541354
}
13551355

1356+
/// Returns an optional "runner" to pass to `compiletest` when executing
1357+
/// test binaries.
1358+
///
1359+
/// An example of this would be a WebAssembly runtime when testing the wasm
1360+
/// targets.
1361+
fn runner(&self, target: TargetSelection) -> Option<String> {
1362+
let target = self.config.target_config.get(&target)?;
1363+
let runner = target.runner.as_ref()?;
1364+
Some(runner.to_owned())
1365+
}
1366+
13561367
/// Returns the root of the "rootfs" image that this target will be using,
13571368
/// if one was configured.
13581369
///

src/tools/compiletest/src/common.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,10 @@ pub struct Config {
266266
pub logfile: Option<PathBuf>,
267267

268268
/// A command line to prefix program execution with,
269-
/// for running under valgrind
270-
pub runtool: Option<String>,
269+
/// for running under valgrind for example.
270+
///
271+
/// Similar to `CARGO_*_RUNNER` configuration.
272+
pub runner: Option<String>,
271273

272274
/// Flags to pass to the compiler when building for the host
273275
pub host_rustcflags: Vec<String>,

src/tools/compiletest/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
8686
.optflag("", "exact", "filters match exactly")
8787
.optopt(
8888
"",
89-
"runtool",
89+
"runner",
9090
"supervisor program to run tests under \
9191
(eg. emulator, valgrind)",
9292
"PROGRAM",
@@ -256,7 +256,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
256256
_ => panic!("unknown `--run` option `{}` given", mode),
257257
}),
258258
logfile: matches.opt_str("logfile").map(|s| PathBuf::from(&s)),
259-
runtool: matches.opt_str("runtool"),
259+
runner: matches.opt_str("runner"),
260260
host_rustcflags: matches.opt_strs("host-rustcflags"),
261261
target_rustcflags: matches.opt_strs("target-rustcflags"),
262262
optimize_tests: matches.opt_present("optimize-tests"),
@@ -341,7 +341,7 @@ pub fn log_config(config: &Config) {
341341
c,
342342
format!("force_pass_mode: {}", opt_str(&config.force_pass_mode.map(|m| format!("{}", m))),),
343343
);
344-
logv(c, format!("runtool: {}", opt_str(&config.runtool)));
344+
logv(c, format!("runner: {}", opt_str(&config.runner)));
345345
logv(c, format!("host-rustcflags: {:?}", config.host_rustcflags));
346346
logv(c, format!("target-rustcflags: {:?}", config.target_rustcflags));
347347
logv(c, format!("target: {}", config.target));

src/tools/compiletest/src/runtest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ impl<'test> TestCx<'test> {
461461
}
462462

463463
let mut new_config = self.config.clone();
464-
new_config.runtool = new_config.valgrind_path.clone();
464+
new_config.runner = new_config.valgrind_path.clone();
465465
let new_cx = TestCx { config: &new_config, ..*self };
466466
proc_res = new_cx.exec_compiled_test();
467467

@@ -2647,7 +2647,7 @@ impl<'test> TestCx<'test> {
26472647
fn make_run_args(&self) -> ProcArgs {
26482648
// If we've got another tool to run under (valgrind),
26492649
// then split apart its command
2650-
let mut args = self.split_maybe_args(&self.config.runtool);
2650+
let mut args = self.split_maybe_args(&self.config.runner);
26512651

26522652
// If this is emscripten, then run tests under nodejs
26532653
if self.config.target.contains("emscripten") {

0 commit comments

Comments
 (0)