diff options
| author | bors <bors@rust-lang.org> | 2024-03-27 17:43:20 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-03-27 17:43:20 +0000 |
| commit | 0157da41ee9a1f6fb1a20e00ea62ab4122e2feaa (patch) | |
| tree | 741b5837eef2affdf7001be59d47174ebe1ce1fd | |
| parent | d5db7fb537c0352eec3855aa0331c271c48ac4f6 (diff) | |
| parent | 1f2178b9e7b43f4efe549e19889eafeec9061e8c (diff) | |
| download | rust-0157da41ee9a1f6fb1a20e00ea62ab4122e2feaa.tar.gz rust-0157da41ee9a1f6fb1a20e00ea62ab4122e2feaa.zip | |
Auto merge of #122460 - jieyouxu:rmake-example-refactor, r=Nilstrieb
Rework rmake support library API
### Take 1: Strongly-typed API
Context: https://github.com/rust-lang/rust/pull/122448#discussion_r1523774427
> My 2 cents: from my experience with writing similar "test DSLs", I would suggest to create these helpers as soon as possible in the process (basically the first time someone needs them, not only after N similar usages), and basically treat any imperative code in these high-level tests as a maintenance burden, basically making them as declarative as possible. Otherwise it might be a bit annoying to keep refactoring the tests later once such helpers are available.
>
> I would even discourage the arg method and create explicit methods for setting things like unpretty, the output file etc., but this might be more controversial, as it will make the invoked command-line arguments more opaque.
cc `@Kobzol` for the testing DSL suggestion.
Example:
```rs
let output = Rustc::new()
.input_file("main.rs")
.emit(&[EmitKind::Metadata])
.extern_("stable", &stable_path)
.output();
```
### Take 2: xshell-based macro API
Example:
```rs
let sh = Shell::new()?;
let stable_path = stable_path.to_string_lossy();
let output = cmd!(sh, "rustc main.rs --emit=metadata --extern stable={stable_path}").output()?;
```
### Take 3: Weakly-typed API with a few helper methods
```rs
let output = Rustc::new()
.input("main.rs")
.emit("metadata")
.extern_("stable", &stable_path)
.output();
```
19 files changed, 404 insertions, 282 deletions
diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 419b04231b5..7975677286d 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -1,19 +1,21 @@ +pub mod run; +pub mod rustc; +pub mod rustdoc; + use std::env; -use std::path::{Path, PathBuf}; -use std::process::{Command, Output}; +use std::path::PathBuf; +use std::process::Output; pub use object; pub use wasmparser; -pub fn out_dir() -> PathBuf { - env::var_os("TMPDIR").unwrap().into() -} +pub use run::{run, run_fail}; +pub use rustc::{aux_build, rustc, Rustc}; +pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc}; -fn setup_common_build_cmd(command: &str) -> Command { - let rustc = env::var(command).unwrap(); - let mut cmd = Command::new(rustc); - cmd.arg("--out-dir").arg(out_dir()).arg("-L").arg(out_dir()); - cmd +/// Path of `TMPDIR` (a temporary build directory, not under `/tmp`). +pub fn tmp_dir() -> PathBuf { + env::var_os("TMPDIR").unwrap().into() } fn handle_failed_output(cmd: &str, output: Output, caller_line_number: u32) -> ! { @@ -24,170 +26,3 @@ fn handle_failed_output(cmd: &str, output: Output, caller_line_number: u32) -> ! eprintln!("=== STDERR ===\n{}\n\n", String::from_utf8(output.stderr).unwrap()); std::process::exit(1) } - -pub fn rustc() -> RustcInvocationBuilder { - RustcInvocationBuilder::new() -} - -pub fn aux_build() -> AuxBuildInvocationBuilder { - AuxBuildInvocationBuilder::new() -} - -pub fn rustdoc() -> Rustdoc { - Rustdoc::new() -} - -#[derive(Debug)] -pub struct RustcInvocationBuilder { - cmd: Command, -} - -impl RustcInvocationBuilder { - fn new() -> Self { - let cmd = setup_common_build_cmd("RUSTC"); - Self { cmd } - } - - pub fn arg(&mut self, arg: &str) -> &mut RustcInvocationBuilder { - self.cmd.arg(arg); - self - } - - pub fn args(&mut self, args: &[&str]) -> &mut RustcInvocationBuilder { - self.cmd.args(args); - self - } - - #[track_caller] - pub fn run(&mut self) -> Output { - let caller_location = std::panic::Location::caller(); - let caller_line_number = caller_location.line(); - - let output = self.cmd.output().unwrap(); - if !output.status.success() { - handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number); - } - output - } -} - -#[derive(Debug)] -pub struct AuxBuildInvocationBuilder { - cmd: Command, -} - -impl AuxBuildInvocationBuilder { - fn new() -> Self { - let mut cmd = setup_common_build_cmd("RUSTC"); - cmd.arg("--crate-type=lib"); - Self { cmd } - } - - pub fn arg(&mut self, arg: &str) -> &mut AuxBuildInvocationBuilder { - self.cmd.arg(arg); - self - } - - #[track_caller] - pub fn run(&mut self) -> Output { - let caller_location = std::panic::Location::caller(); - let caller_line_number = caller_location.line(); - - let output = self.cmd.output().unwrap(); - if !output.status.success() { - handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number); - } - output - } -} - -#[derive(Debug)] -pub struct Rustdoc { - cmd: Command, -} - -impl Rustdoc { - fn new() -> Self { - let cmd = setup_common_build_cmd("RUSTDOC"); - Self { cmd } - } - - pub fn arg(&mut self, arg: &str) -> &mut Self { - self.cmd.arg(arg); - self - } - - #[track_caller] - pub fn run(&mut self) -> Output { - let caller_location = std::panic::Location::caller(); - let caller_line_number = caller_location.line(); - - let output = self.cmd.output().unwrap(); - if !output.status.success() { - handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number); - } - output - } -} - -fn run_common(bin_name: &str) -> (Command, Output) { - let target = env::var("TARGET").unwrap(); - - let bin_name = - if target.contains("windows") { format!("{}.exe", bin_name) } else { bin_name.to_owned() }; - - let mut bin_path = PathBuf::new(); - bin_path.push(env::var("TMPDIR").unwrap()); - bin_path.push(&bin_name); - let ld_lib_path_envvar = env::var("LD_LIB_PATH_ENVVAR").unwrap(); - let mut cmd = Command::new(bin_path); - cmd.env(&ld_lib_path_envvar, { - let mut paths = vec![]; - paths.push(PathBuf::from(env::var("TMPDIR").unwrap())); - for p in env::split_paths(&env::var("TARGET_RPATH_ENV").unwrap()) { - paths.push(p.to_path_buf()); - } - for p in env::split_paths(&env::var(&ld_lib_path_envvar).unwrap()) { - paths.push(p.to_path_buf()); - } - env::join_paths(paths.iter()).unwrap() - }); - - if target.contains("windows") { - let mut paths = vec![]; - for p in env::split_paths(&std::env::var("PATH").unwrap_or(String::new())) { - paths.push(p.to_path_buf()); - } - paths.push(Path::new(&std::env::var("TARGET_RPATH_DIR").unwrap()).to_path_buf()); - cmd.env("PATH", env::join_paths(paths.iter()).unwrap()); - } - - let output = cmd.output().unwrap(); - (cmd, output) -} - -/// Run a built binary and make sure it succeeds. -#[track_caller] -pub fn run(bin_name: &str) -> Output { - let caller_location = std::panic::Location::caller(); - let caller_line_number = caller_location.line(); - - let (cmd, output) = run_common(bin_name); - if !output.status.success() { - handle_failed_output(&format!("{:#?}", cmd), output, caller_line_number); - } - output -} - -/// Run a built binary and make sure it fails. -#[track_caller] -pub fn run_fail(bin_name: &str) -> Output { - let caller_location = std::panic::Location::caller(); - let caller_line_number = caller_location.line(); - - let (cmd, output) = run_common(bin_name); - if output.status.success() { - handle_failed_output(&format!("{:#?}", cmd), output, caller_line_number); - } - output -} diff --git a/src/tools/run-make-support/src/run.rs b/src/tools/run-make-support/src/run.rs new file mode 100644 index 00000000000..42dcf54da22 --- /dev/null +++ b/src/tools/run-make-support/src/run.rs @@ -0,0 +1,67 @@ +use std::env; +use std::path::{Path, PathBuf}; +use std::process::{Command, Output}; + +use super::handle_failed_output; + +fn run_common(bin_name: &str) -> (Command, Output) { + let target = env::var("TARGET").unwrap(); + + let bin_name = + if target.contains("windows") { format!("{}.exe", bin_name) } else { bin_name.to_owned() }; + + let mut bin_path = PathBuf::new(); + bin_path.push(env::var("TMPDIR").unwrap()); + bin_path.push(&bin_name); + let ld_lib_path_envvar = env::var("LD_LIB_PATH_ENVVAR").unwrap(); + let mut cmd = Command::new(bin_path); + cmd.env(&ld_lib_path_envvar, { + let mut paths = vec![]; + paths.push(PathBuf::from(env::var("TMPDIR").unwrap())); + for p in env::split_paths(&env::var("TARGET_RPATH_ENV").unwrap()) { + paths.push(p.to_path_buf()); + } + for p in env::split_paths(&env::var(&ld_lib_path_envvar).unwrap()) { + paths.push(p.to_path_buf()); + } + env::join_paths(paths.iter()).unwrap() + }); + + if target.contains("windows") { + let mut paths = vec![]; + for p in env::split_paths(&std::env::var("PATH").unwrap_or(String::new())) { + paths.push(p.to_path_buf()); + } + paths.push(Path::new(&std::env::var("TARGET_RPATH_DIR").unwrap()).to_path_buf()); + cmd.env("PATH", env::join_paths(paths.iter()).unwrap()); + } + + let output = cmd.output().unwrap(); + (cmd, output) +} + +/// Run a built binary and make sure it succeeds. +#[track_caller] +pub fn run(bin_name: &str) -> Output { + let caller_location = std::panic::Location::caller(); + let caller_line_number = caller_location.line(); + + let (cmd, output) = run_common(bin_name); + if !output.status.success() { + handle_failed_output(&format!("{:#?}", cmd), output, caller_line_number); + } + output +} + +/// Run a built binary and make sure it fails. +#[track_caller] +pub fn run_fail(bin_name: &str) -> Output { + let caller_location = std::panic::Location::caller(); + let caller_line_number = caller_location.line(); + + let (cmd, output) = run_common(bin_name); + if output.status.success() { + handle_failed_output(&format!("{:#?}", cmd), output, caller_line_number); + } + output +} diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs new file mode 100644 index 00000000000..d0ab8df42d2 --- /dev/null +++ b/src/tools/run-make-support/src/rustc.rs @@ -0,0 +1,147 @@ +use std::env; +use std::path::Path; +use std::process::{Command, Output}; + +use crate::{handle_failed_output, tmp_dir}; + +/// Construct a new `rustc` invocation. +pub fn rustc() -> Rustc { + Rustc::new() +} + +/// Construct a new `rustc` aux-build invocation. +pub fn aux_build() -> Rustc { + Rustc::new_aux_build() +} + +/// A `rustc` invocation builder. +#[derive(Debug)] +pub struct Rustc { + cmd: Command, +} + +fn setup_common() -> Command { + let rustc = env::var("RUSTC").unwrap(); + let mut cmd = Command::new(rustc); + cmd.arg("--out-dir").arg(tmp_dir()).arg("-L").arg(tmp_dir()); + cmd +} + +impl Rustc { + // `rustc` invocation constructor methods + + /// Construct a new `rustc` invocation. + pub fn new() -> Self { + let cmd = setup_common(); + Self { cmd } + } + + /// Construct a new `rustc` invocation with `aux_build` preset (setting `--crate-type=lib`). + pub fn new_aux_build() -> Self { + let mut cmd = setup_common(); + cmd.arg("--crate-type=lib"); + Self { cmd } + } + + // Argument provider methods + + /// Configure the compilation environment. + pub fn cfg(&mut self, s: &str) -> &mut Self { + self.cmd.arg("--cfg"); + self.cmd.arg(s); + self + } + + /// Specify default optimization level `-O` (alias for `-C opt-level=2`). + pub fn opt(&mut self) -> &mut Self { + self.cmd.arg("-O"); + self + } + + /// Specify type(s) of output files to generate. + pub fn emit(&mut self, kinds: &str) -> &mut Self { + self.cmd.arg(format!("--emit={kinds}")); + self + } + + /// Specify where an external library is located. + pub fn extern_<P: AsRef<Path>>(&mut self, crate_name: &str, path: P) -> &mut Self { + assert!( + !crate_name.contains(|c: char| c.is_whitespace() || c == '\\' || c == '/'), + "crate name cannot contain whitespace or path separators" + ); + + let path = path.as_ref().to_string_lossy(); + + self.cmd.arg("--extern"); + self.cmd.arg(format!("{crate_name}={path}")); + + self + } + + /// Specify path to the input file. + pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self { + self.cmd.arg(path.as_ref()); + self + } + + /// Specify target triple. + pub fn target(&mut self, target: &str) -> &mut Self { + assert!(!target.contains(char::is_whitespace), "target triple cannot contain spaces"); + self.cmd.arg(format!("--target={target}")); + self + } + + /// Generic command argument provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`. + /// This method will panic if a plain `-Z` or `-C` is passed, or if `-Z <name>` or `-C <name>` + /// is passed (note the space). + pub fn arg(&mut self, arg: &str) -> &mut Self { + assert!( + !(["-Z", "-C"].contains(&arg) || arg.starts_with("-Z ") || arg.starts_with("-C ")), + "use `-Zarg` or `-Carg` over split `-Z` `arg` or `-C` `arg`" + ); + self.cmd.arg(arg); + self + } + + /// Generic command arguments provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`. + /// This method will panic if a plain `-Z` or `-C` is passed, or if `-Z <name>` or `-C <name>` + /// is passed (note the space). + pub fn args(&mut self, args: &[&str]) -> &mut Self { + for arg in args { + assert!( + !(["-Z", "-C"].contains(&arg) || arg.starts_with("-Z ") || arg.starts_with("-C ")), + "use `-Zarg` or `-Carg` over split `-Z` `arg` or `-C` `arg`" + ); + } + + self.cmd.args(args); + self + } + + // Command inspection, output and running helper methods + + /// Get the [`Output`][std::process::Output] of the finished `rustc` process. + pub fn output(&mut self) -> Output { + self.cmd.output().unwrap() + } + + /// Run the constructed `rustc` command and assert that it is successfully run. + #[track_caller] + pub fn run(&mut self) -> Output { + let caller_location = std::panic::Location::caller(); + let caller_line_number = caller_location.line(); + + let output = self.cmd.output().unwrap(); + if !output.status.success() { + handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number); + } + output + } + + /// Inspect what the underlying [`Command`] is up to the current construction. + pub fn inspect(&mut self, f: impl FnOnce(&Command)) -> &mut Self { + f(&self.cmd); + self + } +} diff --git a/src/tools/run-make-support/src/rustdoc.rs b/src/tools/run-make-support/src/rustdoc.rs new file mode 100644 index 00000000000..9607ff02f96 --- /dev/null +++ b/src/tools/run-make-support/src/rustdoc.rs @@ -0,0 +1,80 @@ +use std::env; +use std::path::Path; +use std::process::{Command, Output}; + +use crate::handle_failed_output; + +/// Construct a plain `rustdoc` invocation with no flags set. +pub fn bare_rustdoc() -> Rustdoc { + Rustdoc::bare() +} + +/// Construct a new `rustdoc` invocation with `-L $(TARGET_RPATH_DIR)` set. +pub fn rustdoc() -> Rustdoc { + Rustdoc::new() +} + +#[derive(Debug)] +pub struct Rustdoc { + cmd: Command, +} + +fn setup_common() -> Command { + let rustdoc = env::var("RUSTDOC").unwrap(); + Command::new(rustdoc) +} + +impl Rustdoc { + /// Construct a bare `rustdoc` invocation. + pub fn bare() -> Self { + let cmd = setup_common(); + Self { cmd } + } + + /// Construct a `rustdoc` invocation with `-L $(TARGET_RPATH_DIR)` set. + pub fn new() -> Self { + let mut cmd = setup_common(); + let target_rpath_dir = env::var_os("TARGET_RPATH_DIR").unwrap(); + cmd.arg(format!("-L{}", target_rpath_dir.to_string_lossy())); + Self { cmd } + } + + /// Specify path to the input file. + pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self { + self.cmd.arg(path.as_ref()); + self + } + + /// Specify output directory. + pub fn out_dir<P: AsRef<Path>>(&mut self, path: P) -> &mut Self { + self.cmd.arg("--out-dir").arg(path.as_ref()); + self + } + + /// Given a `path`, pass `@{path}` to `rustdoc` as an + /// [arg file](https://doc.rust-lang.org/rustdoc/command-line-arguments.html#path-load-command-line-flags-from-a-path). + pub fn arg_file<P: AsRef<Path>>(&mut self, path: P) -> &mut Self { + self.cmd.arg(format!("@{}", path.as_ref().display())); + self + } + + /// Fallback argument provider. Consider adding meaningfully named methods instead of using + /// this method. + pub fn arg(&mut self, arg: &str) -> &mut Self { + self.cmd.arg(arg); + self + } + + /// Run the build `rustdoc` command and assert that the run is successful. + #[track_caller] + pub fn run(&mut self) -> Output { + let caller_location = std::panic::Location::caller(); + let caller_line_number = caller_location.line(); + + let output = self.cmd.output().unwrap(); + if !output.status.success() { + handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number); + } + output + } +} diff --git a/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs b/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs index 586f4e4095f..1204260a2f4 100644 --- a/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs +++ b/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs @@ -1,24 +1,25 @@ // ignore-tidy-linelength +// Check that the `CURRENT_RUSTC_VERSION` placeholder is correctly replaced by the current +// `rustc` version and the `since` property in feature stability gating is properly respected. + extern crate run_make_support; use std::path::PathBuf; -use run_make_support::{aux_build, rustc}; +use run_make_support::{rustc, aux_build}; fn main() { - aux_build() - .arg("--emit=metadata") - .arg("stable.rs") - .run(); + aux_build().input("stable.rs").emit("metadata").run(); + let mut stable_path = PathBuf::from(env!("TMPDIR")); stable_path.push("libstable.rmeta"); + let output = rustc() - .arg("--emit=metadata") - .arg("--extern") - .arg(&format!("stable={}", &stable_path.to_string_lossy())) - .arg("main.rs") - .run(); + .input("main.rs") + .emit("metadata") + .extern_("stable", &stable_path) + .output(); let stderr = String::from_utf8_lossy(&output.stderr); let version = include_str!(concat!(env!("S"), "/src/version")); diff --git a/tests/run-make/a-b-a-linker-guard/rmake.rs b/tests/run-make/a-b-a-linker-guard/rmake.rs index ef4813e1214..ffc1b2000b9 100644 --- a/tests/run-make/a-b-a-linker-guard/rmake.rs +++ b/tests/run-make/a-b-a-linker-guard/rmake.rs @@ -1,44 +1,36 @@ // ignore-tidy-linelength +// Test that if we build `b` against a version of `a` that has one set of types, it will not run +// with a dylib that has a different set of types. + extern crate run_make_support; use run_make_support::{run, run_fail, rustc}; fn main() { rustc() - .arg("a.rs") - .arg("--cfg") - .arg("x") - .arg("-C") - .arg("prefer-dynamic") - .arg("-Z") - .arg("unstable-options") - .arg("-C") - .arg("symbol-mangling-version=legacy") + .input("a.rs") + .cfg("x") + .arg("-Zunstable-options") + .arg("-Cprefer-dynamic") + .arg("-Csymbol-mangling-version=legacy") .run(); rustc() - .arg("b.rs") - .arg("-C") - .arg("prefer-dynamic") - .arg("-Z") - .arg("unstable-options") - .arg("-C") - .arg("symbol-mangling-version=legacy") - .run(); + .input("b.rs") + .arg("-Zunstable-options") + .arg("-Cprefer-dynamic") + .arg("-Csymbol-mangling-version=legacy") + .run(); run("b"); rustc() - .arg("a.rs") - .arg("--cfg") - .arg("y") - .arg("-C") - .arg("prefer-dynamic") - .arg("-Z") - .arg("unstable-options") - .arg("-C") - .arg("symbol-mangling-version=legacy") + .input("a.rs") + .cfg("y") + .arg("-Zunstable-options") + .arg("-Cprefer-dynamic") + .arg("-Csymbol-mangling-version=legacy") .run(); run_fail("b"); diff --git a/tests/run-make/compiler-builtins/rmake.rs b/tests/run-make/compiler-builtins/rmake.rs index e7a5e8addbe..b546a095c51 100644 --- a/tests/run-make/compiler-builtins/rmake.rs +++ b/tests/run-make/compiler-builtins/rmake.rs @@ -18,7 +18,7 @@ use run_make_support::object::read::Object; use run_make_support::object::ObjectSection; use run_make_support::object::ObjectSymbol; use run_make_support::object::RelocationTarget; -use run_make_support::out_dir; +use run_make_support::tmp_dir; use std::collections::HashSet; const MANIFEST: &str = r#" @@ -31,7 +31,7 @@ edition = "2021" path = "lib.rs""#; fn main() { - let target_dir = out_dir().join("target"); + let target_dir = tmp_dir().join("target"); let target = std::env::var("TARGET").unwrap(); if target.starts_with("wasm") || target.starts_with("nvptx") { // wasm and nvptx targets don't produce rlib files that object can parse. @@ -41,9 +41,9 @@ fn main() { println!("Testing compiler_builtins for {}", target); // Set up the tiniest Cargo project: An empty no_std library. Just enough to run -Zbuild-std. - let manifest_path = out_dir().join("Cargo.toml"); + let manifest_path = tmp_dir().join("Cargo.toml"); std::fs::write(&manifest_path, MANIFEST.as_bytes()).unwrap(); - std::fs::write(out_dir().join("lib.rs"), b"#![no_std]").unwrap(); + std::fs::write(tmp_dir().join("lib.rs"), b"#![no_std]").unwrap(); let path = std::env::var("PATH").unwrap(); let rustc = std::env::var("RUSTC").unwrap(); diff --git a/tests/run-make/rustdoc-test-args/rmake.rs b/tests/run-make/rustdoc-test-args/rmake.rs index 808d13928eb..c8edfb6370e 100644 --- a/tests/run-make/rustdoc-test-args/rmake.rs +++ b/tests/run-make/rustdoc-test-args/rmake.rs @@ -1,8 +1,8 @@ extern crate run_make_support; -use run_make_support::{out_dir, rustdoc}; -use std::{fs, iter}; +use run_make_support::{rustdoc, tmp_dir}; use std::path::Path; +use std::{fs, iter}; fn generate_a_lot_of_cfgs(path: &Path) { let content = iter::repeat("--cfg=a\n").take(100_000).collect::<String>(); @@ -10,9 +10,8 @@ fn generate_a_lot_of_cfgs(path: &Path) { } fn main() { - let arg_file = out_dir().join("args"); + let arg_file = tmp_dir().join("args"); generate_a_lot_of_cfgs(&arg_file); - let arg_file = format!("@{}", arg_file.display()); - rustdoc().arg("--test").arg(&arg_file).arg("foo.rs").run(); + rustdoc().out_dir(tmp_dir()).input("foo.rs").arg_file(&arg_file).arg("--test").run(); } diff --git a/tests/run-make/wasm-abi/rmake.rs b/tests/run-make/wasm-abi/rmake.rs index 07b826ae6fe..f4d0027798a 100644 --- a/tests/run-make/wasm-abi/rmake.rs +++ b/tests/run-make/wasm-abi/rmake.rs @@ -1,6 +1,6 @@ extern crate run_make_support; -use run_make_support::{out_dir, rustc}; +use run_make_support::{rustc, tmp_dir}; use std::path::Path; use std::process::Command; @@ -9,8 +9,9 @@ fn main() { return; } - rustc().arg("foo.rs").arg("--target=wasm32-wasip1").run(); - let file = out_dir().join("foo.wasm"); + rustc().input("foo.rs").target("wasm32-wasip1").run(); + + let file = tmp_dir().join("foo.wasm"); let has_wasmtime = match Command::new("wasmtime").arg("--version").output() { Ok(s) => s.status.success(), diff --git a/tests/run-make/wasm-custom-section/rmake.rs b/tests/run-make/wasm-custom-section/rmake.rs index 9ad152695ec..31fb5fb3230 100644 --- a/tests/run-make/wasm-custom-section/rmake.rs +++ b/tests/run-make/wasm-custom-section/rmake.rs @@ -1,6 +1,6 @@ extern crate run_make_support; -use run_make_support::{out_dir, rustc, wasmparser}; +use run_make_support::{rustc, tmp_dir, wasmparser}; use std::collections::HashMap; fn main() { @@ -8,10 +8,10 @@ fn main() { return; } - rustc().arg("foo.rs").arg("--target=wasm32-wasip1").run(); - rustc().arg("bar.rs").arg("--target=wasm32-wasip1").arg("-Clto").arg("-O").run(); + rustc().input("foo.rs").target("wasm32-wasip1").run(); + rustc().input("bar.rs").target("wasm32-wasip1").arg("-Clto").opt().run(); - let file = std::fs::read(&out_dir().join("bar.wasm")).unwrap(); + let file = std::fs::read(&tmp_dir().join("bar.wasm")).unwrap(); let mut custom = HashMap::new(); for payload in wasmparser::Parser::new(0).parse_all(&file) { diff --git a/tests/run-make/wasm-custom-sections-opt/rmake.rs b/tests/run-make/wasm-custom-sections-opt/rmake.rs index db31d6b7163..3164de1b4c9 100644 --- a/tests/run-make/wasm-custom-sections-opt/rmake.rs +++ b/tests/run-make/wasm-custom-sections-opt/rmake.rs @@ -1,6 +1,6 @@ extern crate run_make_support; -use run_make_support::{out_dir, rustc, wasmparser}; +use run_make_support::{tmp_dir, wasmparser, rustc}; use std::collections::HashMap; use std::path::Path; @@ -9,8 +9,9 @@ fn main() { return; } - rustc().arg("foo.rs").arg("--target=wasm32-wasip1").arg("-O").run(); - verify(&out_dir().join("foo.wasm")); + rustc().input("foo.rs").target("wasm32-wasip1").opt().run(); + + verify(&tmp_dir().join("foo.wasm")); } fn verify(path: &Path) { diff --git a/tests/run-make/wasm-export-all-symbols/rmake.rs b/tests/run-make/wasm-export-all-symbols/rmake.rs index e3b118279b7..13101a97444 100644 --- a/tests/run-make/wasm-export-all-symbols/rmake.rs +++ b/tests/run-make/wasm-export-all-symbols/rmake.rs @@ -1,6 +1,6 @@ extern crate run_make_support; -use run_make_support::{out_dir, rustc, wasmparser}; +use run_make_support::{tmp_dir, wasmparser, rustc}; use std::collections::HashMap; use std::path::Path; use wasmparser::ExternalKind::*; @@ -17,16 +17,17 @@ fn main() { fn test(args: &[&str]) { eprintln!("running with {args:?}"); - rustc().arg("bar.rs").arg("--target=wasm32-wasip1").args(args).run(); - rustc().arg("foo.rs").arg("--target=wasm32-wasip1").args(args).run(); - rustc().arg("main.rs").arg("--target=wasm32-wasip1").args(args).run(); + + rustc().input("bar.rs").target("wasm32-wasip1").args(args).run(); + rustc().input("foo.rs").target("wasm32-wasip1").args(args).run(); + rustc().input("main.rs").target("wasm32-wasip1").args(args).run(); verify_exports( - &out_dir().join("foo.wasm"), + &tmp_dir().join("foo.wasm"), &[("foo", Func), ("FOO", Global), ("memory", Memory)], ); verify_exports( - &out_dir().join("main.wasm"), + &tmp_dir().join("main.wasm"), &[ ("foo", Func), ("FOO", Global), diff --git a/tests/run-make/wasm-import-module/rmake.rs b/tests/run-make/wasm-import-module/rmake.rs index e521b5b0983..3962bd80a89 100644 --- a/tests/run-make/wasm-import-module/rmake.rs +++ b/tests/run-make/wasm-import-module/rmake.rs @@ -1,6 +1,6 @@ extern crate run_make_support; -use run_make_support::{out_dir, rustc, wasmparser}; +use run_make_support::{tmp_dir, wasmparser, rustc}; use std::collections::HashMap; use wasmparser::TypeRef::Func; @@ -9,10 +9,15 @@ fn main() { return; } - rustc().arg("foo.rs").arg("--target=wasm32-wasip1").run(); - rustc().arg("bar.rs").arg("--target=wasm32-wasip1").arg("-Clto").arg("-O").run(); + rustc().input("foo.rs").target("wasm32-wasip1").run(); + rustc() + .input("bar.rs") + .target("wasm32-wasip1") + .arg("-Clto") + .opt() + .run(); - let file = std::fs::read(&out_dir().join("bar.wasm")).unwrap(); + let file = std::fs::read(&tmp_dir().join("bar.wasm")).unwrap(); let mut imports = HashMap::new(); for payload in wasmparser::Parser::new(0).parse_all(&file) { diff --git a/tests/run-make/wasm-panic-small/rmake.rs b/tests/run-make/wasm-panic-small/rmake.rs index 0260485f744..7941b503994 100644 --- a/tests/run-make/wasm-panic-small/rmake.rs +++ b/tests/run-make/wasm-panic-small/rmake.rs @@ -2,7 +2,7 @@ extern crate run_make_support; -use run_make_support::{out_dir, rustc}; +use run_make_support::{rustc, tmp_dir}; fn main() { if std::env::var("TARGET").unwrap() != "wasm32-wasip1" { @@ -17,16 +17,10 @@ fn main() { fn test(cfg: &str) { eprintln!("running cfg {cfg:?}"); - rustc() - .arg("foo.rs") - .arg("--target=wasm32-wasip1") - .arg("-Clto") - .arg("-O") - .arg("--cfg") - .arg(cfg) - .run(); - let bytes = std::fs::read(&out_dir().join("foo.wasm")).unwrap(); + rustc().input("foo.rs").target("wasm32-wasip1").arg("-Clto").opt().cfg(cfg).run(); + + let bytes = std::fs::read(&tmp_dir().join("foo.wasm")).unwrap(); println!("{}", bytes.len()); assert!(bytes.len() < 40_000); } diff --git a/tests/run-make/wasm-spurious-import/rmake.rs b/tests/run-make/wasm-spurious-import/rmake.rs index 0ac9104bfb4..9dafa6f594a 100644 --- a/tests/run-make/wasm-spurious-import/rmake.rs +++ b/tests/run-make/wasm-spurious-import/rmake.rs @@ -1,8 +1,7 @@ extern crate run_make_support; -use run_make_support::{out_dir, rustc, wasmparser}; +use run_make_support::{rustc, tmp_dir, wasmparser}; use std::collections::HashMap; -use wasmparser::TypeRef::Func; fn main() { if std::env::var("TARGET").unwrap() != "wasm32-wasip1" { @@ -10,15 +9,15 @@ fn main() { } rustc() - .arg("main.rs") - .arg("--target=wasm32-wasip1") - .arg("-Coverflow-checks=yes") + .input("main.rs") + .target("wasm32-wasip1") + .arg("-Coverflow-checks") .arg("-Cpanic=abort") .arg("-Clto") .arg("-Copt-level=z") .run(); - let file = std::fs::read(&out_dir().join("main.wasm")).unwrap(); + let file = std::fs::read(&tmp_dir().join("main.wasm")).unwrap(); let mut imports = HashMap::new(); for payload in wasmparser::Parser::new(0).parse_all(&file) { diff --git a/tests/run-make/wasm-stringify-ints-small/rmake.rs b/tests/run-make/wasm-stringify-ints-small/rmake.rs index 80cff7acdf4..6b3ad871a70 100644 --- a/tests/run-make/wasm-stringify-ints-small/rmake.rs +++ b/tests/run-make/wasm-stringify-ints-small/rmake.rs @@ -2,16 +2,16 @@ extern crate run_make_support; -use run_make_support::{out_dir, rustc}; +use run_make_support::{rustc, tmp_dir}; fn main() { if std::env::var("TARGET").unwrap() != "wasm32-wasip1" { return; } - rustc().arg("foo.rs").arg("--target=wasm32-wasip1").arg("-Clto").arg("-O").run(); + rustc().input("foo.rs").target("wasm32-wasip1").arg("-Clto").opt().run(); - let bytes = std::fs::read(&out_dir().join("foo.wasm")).unwrap(); + let bytes = std::fs::read(&tmp_dir().join("foo.wasm")).unwrap(); println!("{}", bytes.len()); assert!(bytes.len() < 50_000); } diff --git a/tests/run-make/wasm-symbols-different-module/rmake.rs b/tests/run-make/wasm-symbols-different-module/rmake.rs index c3cc1e0c32b..a27da446baa 100644 --- a/tests/run-make/wasm-symbols-different-module/rmake.rs +++ b/tests/run-make/wasm-symbols-different-module/rmake.rs @@ -1,6 +1,6 @@ extern crate run_make_support; -use run_make_support::{out_dir, rustc, wasmparser}; +use run_make_support::{rustc, tmp_dir, wasmparser}; use std::collections::{HashMap, HashSet}; fn main() { @@ -24,9 +24,9 @@ fn test_file(file: &str, expected_imports: &[(&str, &[&str])]) { fn test(file: &str, args: &[&str], expected_imports: &[(&str, &[&str])]) { println!("test {file:?} {args:?} for {expected_imports:?}"); - rustc().arg(file).arg("--target=wasm32-wasip1").args(args).run(); + rustc().input(file).target("wasm32-wasip1").args(args).run(); - let file = std::fs::read(&out_dir().join(file).with_extension("wasm")).unwrap(); + let file = std::fs::read(&tmp_dir().join(file).with_extension("wasm")).unwrap(); let mut imports = HashMap::new(); for payload in wasmparser::Parser::new(0).parse_all(&file) { diff --git a/tests/run-make/wasm-symbols-not-exported/rmake.rs b/tests/run-make/wasm-symbols-not-exported/rmake.rs index 5ff0dc578b3..da536f2af71 100644 --- a/tests/run-make/wasm-symbols-not-exported/rmake.rs +++ b/tests/run-make/wasm-symbols-not-exported/rmake.rs @@ -1,6 +1,6 @@ extern crate run_make_support; -use run_make_support::{out_dir, rustc, wasmparser}; +use run_make_support::{rustc, tmp_dir, wasmparser}; use std::path::Path; fn main() { @@ -8,15 +8,15 @@ fn main() { return; } - rustc().arg("foo.rs").arg("--target=wasm32-wasip1").run(); - verify_symbols(&out_dir().join("foo.wasm")); - rustc().arg("foo.rs").arg("--target=wasm32-wasip1").arg("-O").run(); - verify_symbols(&out_dir().join("foo.wasm")); + rustc().input("foo.rs").target("wasm32-wasip1").run(); + verify_symbols(&tmp_dir().join("foo.wasm")); + rustc().input("foo.rs").target("wasm32-wasip1").opt().run(); + verify_symbols(&tmp_dir().join("foo.wasm")); - rustc().arg("bar.rs").arg("--target=wasm32-wasip1").run(); - verify_symbols(&out_dir().join("bar.wasm")); - rustc().arg("bar.rs").arg("--target=wasm32-wasip1").arg("-O").run(); - verify_symbols(&out_dir().join("bar.wasm")); + rustc().input("bar.rs").target("wasm32-wasip1").run(); + verify_symbols(&tmp_dir().join("bar.wasm")); + rustc().input("bar.rs").target("wasm32-wasip1").opt().run(); + verify_symbols(&tmp_dir().join("bar.wasm")); } fn verify_symbols(path: &Path) { diff --git a/tests/run-make/wasm-symbols-not-imported/rmake.rs b/tests/run-make/wasm-symbols-not-imported/rmake.rs index 974f415166b..b784b6aff6a 100644 --- a/tests/run-make/wasm-symbols-not-imported/rmake.rs +++ b/tests/run-make/wasm-symbols-not-imported/rmake.rs @@ -1,6 +1,6 @@ extern crate run_make_support; -use run_make_support::{out_dir, rustc, wasmparser}; +use run_make_support::{rustc, tmp_dir, wasmparser}; use std::path::Path; fn main() { @@ -8,14 +8,14 @@ fn main() { return; } - rustc().arg("foo.rs").arg("--target=wasm32-wasip1").run(); - verify_symbols(&out_dir().join("foo.wasm")); - rustc().arg("foo.rs").arg("--target=wasm32-wasip1").arg("-Clto").run(); - verify_symbols(&out_dir().join("foo.wasm")); - rustc().arg("foo.rs").arg("--target=wasm32-wasip1").arg("-O").run(); - verify_symbols(&out_dir().join("foo.wasm")); - rustc().arg("foo.rs").arg("--target=wasm32-wasip1").arg("-Clto").arg("-O").run(); - verify_symbols(&out_dir().join("foo.wasm")); + rustc().input("foo.rs").target("wasm32-wasip1").run(); + verify_symbols(&tmp_dir().join("foo.wasm")); + rustc().input("foo.rs").target("wasm32-wasip1").arg("-Clto").run(); + verify_symbols(&tmp_dir().join("foo.wasm")); + rustc().input("foo.rs").target("wasm32-wasip1").opt().run(); + verify_symbols(&tmp_dir().join("foo.wasm")); + rustc().input("foo.rs").target("wasm32-wasip1").arg("-Clto").opt().run(); + verify_symbols(&tmp_dir().join("foo.wasm")); } fn verify_symbols(path: &Path) { |
