Skip to content
/ rust Public
forked from rust-lang/rust

Commit 9b30f01

Browse files
authored
Rollup merge of rust-lang#122108 - alexcrichton:target-config-runtool, r=WaffleLapkin
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`.
2 parents b3ac6fa + 9bdb8a6 commit 9b30f01

File tree

8 files changed

+43
-7
lines changed

8 files changed

+43
-7
lines changed

config.example.toml

+11
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,17 @@
842842
# See that option for more info.
843843
#codegen-backends = rust.codegen-backends (array)
844844

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

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

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

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

19761978
if suite != "mir-opt" {
@@ -2523,6 +2525,8 @@ fn prepare_cargo_test(
25232525
format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
25242526
format!("{} run 0", builder.tool_exe(Tool::RemoteTestClient).display()),
25252527
);
2528+
} else if let Some(tool) = builder.runner(target) {
2529+
cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)), tool);
25262530
}
25272531

25282532
cargo

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

+3
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ pub struct Target {
581581
pub musl_libdir: Option<PathBuf>,
582582
pub wasi_root: Option<PathBuf>,
583583
pub qemu_rootfs: Option<PathBuf>,
584+
pub runner: Option<String>,
584585
pub no_std: bool,
585586
pub codegen_backends: Option<Vec<String>>,
586587
}
@@ -1144,6 +1145,7 @@ define_config! {
11441145
qemu_rootfs: Option<String> = "qemu-rootfs",
11451146
no_std: Option<bool> = "no-std",
11461147
codegen_backends: Option<Vec<String>> = "codegen-backends",
1148+
runner: Option<String> = "runner",
11471149
}
11481150
}
11491151

@@ -1864,6 +1866,7 @@ impl Config {
18641866
target.musl_libdir = cfg.musl_libdir.map(PathBuf::from);
18651867
target.wasi_root = cfg.wasi_root.map(PathBuf::from);
18661868
target.qemu_rootfs = cfg.qemu_rootfs.map(PathBuf::from);
1869+
target.runner = cfg.runner;
18671870
target.sanitizers = cfg.sanitizers;
18681871
target.profiler = cfg.profiler;
18691872
target.rpath = cfg.rpath;

src/bootstrap/src/lib.rs

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

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

src/bootstrap/src/utils/change_tracker.rs

+5
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
141141
severity: ChangeSeverity::Info,
142142
summary: "A new `boostrap-cache-path` option has been introduced which can be utilized to modify the cache path for bootstrap.",
143143
},
144+
ChangeInfo {
145+
change_id: 122108,
146+
severity: ChangeSeverity::Info,
147+
summary: "a new `target.*.runner` option is available to specify a wrapper executable required to run tests for a target",
148+
},
144149
];

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)