diff --git a/config.example.toml b/config.example.toml index c1939933850c4..4fbdccba91104 100644 --- a/config.example.toml +++ b/config.example.toml @@ -842,6 +842,17 @@ # See that option for more info. #codegen-backends = rust.codegen-backends (array) +# This is a "runner" to pass to `compiletest` when executing tests. Tests will +# execute this tool where the binary-to-test is passed as an argument. Can +# be useful for situations such as when WebAssembly is being tested and a +# runtime needs to be configured. This value is similar to +# Cargo's `CARGO_$target_RUNNER` configuration. +# +# This configuration is a space-separated list of arguments so `foo bar` would +# execute the program `foo` with the first argument as `bar` and the second +# argument as the test binary. +#runner = (string) + # ============================================================================= # Distribution options # diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index 58bc379136978..248d831b6e30e 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -1971,6 +1971,8 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the if builder.remote_tested(target) { cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient)); + } else if let Some(tool) = builder.runner(target) { + cmd.arg("--runner").arg(tool); } if suite != "mir-opt" { @@ -2523,6 +2525,8 @@ fn prepare_cargo_test( format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)), format!("{} run 0", builder.tool_exe(Tool::RemoteTestClient).display()), ); + } else if let Some(tool) = builder.runner(target) { + cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)), tool); } cargo diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 4766f9d426c30..683e0a4302f94 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -581,6 +581,7 @@ pub struct Target { pub musl_libdir: Option, pub wasi_root: Option, pub qemu_rootfs: Option, + pub runner: Option, pub no_std: bool, pub codegen_backends: Option>, } @@ -1144,6 +1145,7 @@ define_config! { qemu_rootfs: Option = "qemu-rootfs", no_std: Option = "no-std", codegen_backends: Option> = "codegen-backends", + runner: Option = "runner", } } @@ -1864,6 +1866,7 @@ impl Config { target.musl_libdir = cfg.musl_libdir.map(PathBuf::from); target.wasi_root = cfg.wasi_root.map(PathBuf::from); target.qemu_rootfs = cfg.qemu_rootfs.map(PathBuf::from); + target.runner = cfg.runner; target.sanitizers = cfg.sanitizers; target.profiler = cfg.profiler; target.rpath = cfg.rpath; diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 10c13fecbf367..938b95cc60e4b 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -1354,6 +1354,17 @@ impl Build { || env::var_os("TEST_DEVICE_ADDR").is_some() } + /// Returns an optional "runner" to pass to `compiletest` when executing + /// test binaries. + /// + /// An example of this would be a WebAssembly runtime when testing the wasm + /// targets. + fn runner(&self, target: TargetSelection) -> Option { + let target = self.config.target_config.get(&target)?; + let runner = target.runner.as_ref()?; + Some(runner.to_owned()) + } + /// Returns the root of the "rootfs" image that this target will be using, /// if one was configured. /// diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs index d166b84e51fc5..a348fa3584147 100644 --- a/src/bootstrap/src/utils/change_tracker.rs +++ b/src/bootstrap/src/utils/change_tracker.rs @@ -141,4 +141,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[ severity: ChangeSeverity::Info, summary: "A new `boostrap-cache-path` option has been introduced which can be utilized to modify the cache path for bootstrap.", }, + ChangeInfo { + change_id: 122108, + severity: ChangeSeverity::Info, + summary: "a new `target.*.runner` option is available to specify a wrapper executable required to run tests for a target", + }, ]; diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 06d8f099c33fa..78246136f2a1b 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -266,8 +266,10 @@ pub struct Config { pub logfile: Option, /// A command line to prefix program execution with, - /// for running under valgrind - pub runtool: Option, + /// for running under valgrind for example. + /// + /// Similar to `CARGO_*_RUNNER` configuration. + pub runner: Option, /// Flags to pass to the compiler when building for the host pub host_rustcflags: Vec, diff --git a/src/tools/compiletest/src/lib.rs b/src/tools/compiletest/src/lib.rs index b32a5a4bf1a4a..ef02e7fcb4abb 100644 --- a/src/tools/compiletest/src/lib.rs +++ b/src/tools/compiletest/src/lib.rs @@ -86,7 +86,7 @@ pub fn parse_config(args: Vec) -> Config { .optflag("", "exact", "filters match exactly") .optopt( "", - "runtool", + "runner", "supervisor program to run tests under \ (eg. emulator, valgrind)", "PROGRAM", @@ -256,7 +256,7 @@ pub fn parse_config(args: Vec) -> Config { _ => panic!("unknown `--run` option `{}` given", mode), }), logfile: matches.opt_str("logfile").map(|s| PathBuf::from(&s)), - runtool: matches.opt_str("runtool"), + runner: matches.opt_str("runner"), host_rustcflags: matches.opt_strs("host-rustcflags"), target_rustcflags: matches.opt_strs("target-rustcflags"), optimize_tests: matches.opt_present("optimize-tests"), @@ -341,7 +341,7 @@ pub fn log_config(config: &Config) { c, format!("force_pass_mode: {}", opt_str(&config.force_pass_mode.map(|m| format!("{}", m))),), ); - logv(c, format!("runtool: {}", opt_str(&config.runtool))); + logv(c, format!("runner: {}", opt_str(&config.runner))); logv(c, format!("host-rustcflags: {:?}", config.host_rustcflags)); logv(c, format!("target-rustcflags: {:?}", config.target_rustcflags)); logv(c, format!("target: {}", config.target)); diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index ae0db88d873be..9fd83c507edde 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -461,7 +461,7 @@ impl<'test> TestCx<'test> { } let mut new_config = self.config.clone(); - new_config.runtool = new_config.valgrind_path.clone(); + new_config.runner = new_config.valgrind_path.clone(); let new_cx = TestCx { config: &new_config, ..*self }; proc_res = new_cx.exec_compiled_test(); @@ -2647,7 +2647,7 @@ impl<'test> TestCx<'test> { fn make_run_args(&self) -> ProcArgs { // If we've got another tool to run under (valgrind), // then split apart its command - let mut args = self.split_maybe_args(&self.config.runtool); + let mut args = self.split_maybe_args(&self.config.runner); // If this is emscripten, then run tests under nodejs if self.config.target.contains("emscripten") {