Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1f2178b

Browse files
committedMar 24, 2024
Rework rmake support library to have a weakly-typed API with helper methods
1 parent 6a92312 commit 1f2178b

File tree

19 files changed

+404
-282
lines changed

19 files changed

+404
-282
lines changed
 

‎src/tools/run-make-support/src/lib.rs

Lines changed: 12 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1+
pub mod run;
2+
pub mod rustc;
3+
pub mod rustdoc;
4+
15
use std::env;
2-
use std::path::{Path, PathBuf};
3-
use std::process::{Command, Output};
6+
use std::path::PathBuf;
7+
use std::process::Output;
48

59
pub use object;
610
pub use wasmparser;
711

8-
pub fn out_dir() -> PathBuf {
9-
env::var_os("TMPDIR").unwrap().into()
10-
}
12+
pub use run::{run, run_fail};
13+
pub use rustc::{aux_build, rustc, Rustc};
14+
pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc};
1115

12-
fn setup_common_build_cmd(command: &str) -> Command {
13-
let rustc = env::var(command).unwrap();
14-
let mut cmd = Command::new(rustc);
15-
cmd.arg("--out-dir").arg(out_dir()).arg("-L").arg(out_dir());
16-
cmd
16+
/// Path of `TMPDIR` (a temporary build directory, not under `/tmp`).
17+
pub fn tmp_dir() -> PathBuf {
18+
env::var_os("TMPDIR").unwrap().into()
1719
}
1820

1921
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) -> !
2426
eprintln!("=== STDERR ===\n{}\n\n", String::from_utf8(output.stderr).unwrap());
2527
std::process::exit(1)
2628
}
27-
28-
pub fn rustc() -> RustcInvocationBuilder {
29-
RustcInvocationBuilder::new()
30-
}
31-
32-
pub fn aux_build() -> AuxBuildInvocationBuilder {
33-
AuxBuildInvocationBuilder::new()
34-
}
35-
36-
pub fn rustdoc() -> Rustdoc {
37-
Rustdoc::new()
38-
}
39-
40-
#[derive(Debug)]
41-
pub struct RustcInvocationBuilder {
42-
cmd: Command,
43-
}
44-
45-
impl RustcInvocationBuilder {
46-
fn new() -> Self {
47-
let cmd = setup_common_build_cmd("RUSTC");
48-
Self { cmd }
49-
}
50-
51-
pub fn arg(&mut self, arg: &str) -> &mut RustcInvocationBuilder {
52-
self.cmd.arg(arg);
53-
self
54-
}
55-
56-
pub fn args(&mut self, args: &[&str]) -> &mut RustcInvocationBuilder {
57-
self.cmd.args(args);
58-
self
59-
}
60-
61-
#[track_caller]
62-
pub fn run(&mut self) -> Output {
63-
let caller_location = std::panic::Location::caller();
64-
let caller_line_number = caller_location.line();
65-
66-
let output = self.cmd.output().unwrap();
67-
if !output.status.success() {
68-
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
69-
}
70-
output
71-
}
72-
}
73-
74-
#[derive(Debug)]
75-
pub struct AuxBuildInvocationBuilder {
76-
cmd: Command,
77-
}
78-
79-
impl AuxBuildInvocationBuilder {
80-
fn new() -> Self {
81-
let mut cmd = setup_common_build_cmd("RUSTC");
82-
cmd.arg("--crate-type=lib");
83-
Self { cmd }
84-
}
85-
86-
pub fn arg(&mut self, arg: &str) -> &mut AuxBuildInvocationBuilder {
87-
self.cmd.arg(arg);
88-
self
89-
}
90-
91-
#[track_caller]
92-
pub fn run(&mut self) -> Output {
93-
let caller_location = std::panic::Location::caller();
94-
let caller_line_number = caller_location.line();
95-
96-
let output = self.cmd.output().unwrap();
97-
if !output.status.success() {
98-
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
99-
}
100-
output
101-
}
102-
}
103-
104-
#[derive(Debug)]
105-
pub struct Rustdoc {
106-
cmd: Command,
107-
}
108-
109-
impl Rustdoc {
110-
fn new() -> Self {
111-
let cmd = setup_common_build_cmd("RUSTDOC");
112-
Self { cmd }
113-
}
114-
115-
pub fn arg(&mut self, arg: &str) -> &mut Self {
116-
self.cmd.arg(arg);
117-
self
118-
}
119-
120-
#[track_caller]
121-
pub fn run(&mut self) -> Output {
122-
let caller_location = std::panic::Location::caller();
123-
let caller_line_number = caller_location.line();
124-
125-
let output = self.cmd.output().unwrap();
126-
if !output.status.success() {
127-
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
128-
}
129-
output
130-
}
131-
}
132-
133-
fn run_common(bin_name: &str) -> (Command, Output) {
134-
let target = env::var("TARGET").unwrap();
135-
136-
let bin_name =
137-
if target.contains("windows") { format!("{}.exe", bin_name) } else { bin_name.to_owned() };
138-
139-
let mut bin_path = PathBuf::new();
140-
bin_path.push(env::var("TMPDIR").unwrap());
141-
bin_path.push(&bin_name);
142-
let ld_lib_path_envvar = env::var("LD_LIB_PATH_ENVVAR").unwrap();
143-
let mut cmd = Command::new(bin_path);
144-
cmd.env(&ld_lib_path_envvar, {
145-
let mut paths = vec![];
146-
paths.push(PathBuf::from(env::var("TMPDIR").unwrap()));
147-
for p in env::split_paths(&env::var("TARGET_RPATH_ENV").unwrap()) {
148-
paths.push(p.to_path_buf());
149-
}
150-
for p in env::split_paths(&env::var(&ld_lib_path_envvar).unwrap()) {
151-
paths.push(p.to_path_buf());
152-
}
153-
env::join_paths(paths.iter()).unwrap()
154-
});
155-
156-
if target.contains("windows") {
157-
let mut paths = vec![];
158-
for p in env::split_paths(&std::env::var("PATH").unwrap_or(String::new())) {
159-
paths.push(p.to_path_buf());
160-
}
161-
paths.push(Path::new(&std::env::var("TARGET_RPATH_DIR").unwrap()).to_path_buf());
162-
cmd.env("PATH", env::join_paths(paths.iter()).unwrap());
163-
}
164-
165-
let output = cmd.output().unwrap();
166-
(cmd, output)
167-
}
168-
169-
/// Run a built binary and make sure it succeeds.
170-
#[track_caller]
171-
pub fn run(bin_name: &str) -> Output {
172-
let caller_location = std::panic::Location::caller();
173-
let caller_line_number = caller_location.line();
174-
175-
let (cmd, output) = run_common(bin_name);
176-
if !output.status.success() {
177-
handle_failed_output(&format!("{:#?}", cmd), output, caller_line_number);
178-
}
179-
output
180-
}
181-
182-
/// Run a built binary and make sure it fails.
183-
#[track_caller]
184-
pub fn run_fail(bin_name: &str) -> Output {
185-
let caller_location = std::panic::Location::caller();
186-
let caller_line_number = caller_location.line();
187-
188-
let (cmd, output) = run_common(bin_name);
189-
if output.status.success() {
190-
handle_failed_output(&format!("{:#?}", cmd), output, caller_line_number);
191-
}
192-
output
193-
}

‎src/tools/run-make-support/src/run.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
use std::env;
2+
use std::path::{Path, PathBuf};
3+
use std::process::{Command, Output};
4+
5+
use super::handle_failed_output;
6+
7+
fn run_common(bin_name: &str) -> (Command, Output) {
8+
let target = env::var("TARGET").unwrap();
9+
10+
let bin_name =
11+
if target.contains("windows") { format!("{}.exe", bin_name) } else { bin_name.to_owned() };
12+
13+
let mut bin_path = PathBuf::new();
14+
bin_path.push(env::var("TMPDIR").unwrap());
15+
bin_path.push(&bin_name);
16+
let ld_lib_path_envvar = env::var("LD_LIB_PATH_ENVVAR").unwrap();
17+
let mut cmd = Command::new(bin_path);
18+
cmd.env(&ld_lib_path_envvar, {
19+
let mut paths = vec![];
20+
paths.push(PathBuf::from(env::var("TMPDIR").unwrap()));
21+
for p in env::split_paths(&env::var("TARGET_RPATH_ENV").unwrap()) {
22+
paths.push(p.to_path_buf());
23+
}
24+
for p in env::split_paths(&env::var(&ld_lib_path_envvar).unwrap()) {
25+
paths.push(p.to_path_buf());
26+
}
27+
env::join_paths(paths.iter()).unwrap()
28+
});
29+
30+
if target.contains("windows") {
31+
let mut paths = vec![];
32+
for p in env::split_paths(&std::env::var("PATH").unwrap_or(String::new())) {
33+
paths.push(p.to_path_buf());
34+
}
35+
paths.push(Path::new(&std::env::var("TARGET_RPATH_DIR").unwrap()).to_path_buf());
36+
cmd.env("PATH", env::join_paths(paths.iter()).unwrap());
37+
}
38+
39+
let output = cmd.output().unwrap();
40+
(cmd, output)
41+
}
42+
43+
/// Run a built binary and make sure it succeeds.
44+
#[track_caller]
45+
pub fn run(bin_name: &str) -> Output {
46+
let caller_location = std::panic::Location::caller();
47+
let caller_line_number = caller_location.line();
48+
49+
let (cmd, output) = run_common(bin_name);
50+
if !output.status.success() {
51+
handle_failed_output(&format!("{:#?}", cmd), output, caller_line_number);
52+
}
53+
output
54+
}
55+
56+
/// Run a built binary and make sure it fails.
57+
#[track_caller]
58+
pub fn run_fail(bin_name: &str) -> Output {
59+
let caller_location = std::panic::Location::caller();
60+
let caller_line_number = caller_location.line();
61+
62+
let (cmd, output) = run_common(bin_name);
63+
if output.status.success() {
64+
handle_failed_output(&format!("{:#?}", cmd), output, caller_line_number);
65+
}
66+
output
67+
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
use std::env;
2+
use std::path::Path;
3+
use std::process::{Command, Output};
4+
5+
use crate::{handle_failed_output, tmp_dir};
6+
7+
/// Construct a new `rustc` invocation.
8+
pub fn rustc() -> Rustc {
9+
Rustc::new()
10+
}
11+
12+
/// Construct a new `rustc` aux-build invocation.
13+
pub fn aux_build() -> Rustc {
14+
Rustc::new_aux_build()
15+
}
16+
17+
/// A `rustc` invocation builder.
18+
#[derive(Debug)]
19+
pub struct Rustc {
20+
cmd: Command,
21+
}
22+
23+
fn setup_common() -> Command {
24+
let rustc = env::var("RUSTC").unwrap();
25+
let mut cmd = Command::new(rustc);
26+
cmd.arg("--out-dir").arg(tmp_dir()).arg("-L").arg(tmp_dir());
27+
cmd
28+
}
29+
30+
impl Rustc {
31+
// `rustc` invocation constructor methods
32+
33+
/// Construct a new `rustc` invocation.
34+
pub fn new() -> Self {
35+
let cmd = setup_common();
36+
Self { cmd }
37+
}
38+
39+
/// Construct a new `rustc` invocation with `aux_build` preset (setting `--crate-type=lib`).
40+
pub fn new_aux_build() -> Self {
41+
let mut cmd = setup_common();
42+
cmd.arg("--crate-type=lib");
43+
Self { cmd }
44+
}
45+
46+
// Argument provider methods
47+
48+
/// Configure the compilation environment.
49+
pub fn cfg(&mut self, s: &str) -> &mut Self {
50+
self.cmd.arg("--cfg");
51+
self.cmd.arg(s);
52+
self
53+
}
54+
55+
/// Specify default optimization level `-O` (alias for `-C opt-level=2`).
56+
pub fn opt(&mut self) -> &mut Self {
57+
self.cmd.arg("-O");
58+
self
59+
}
60+
61+
/// Specify type(s) of output files to generate.
62+
pub fn emit(&mut self, kinds: &str) -> &mut Self {
63+
self.cmd.arg(format!("--emit={kinds}"));
64+
self
65+
}
66+
67+
/// Specify where an external library is located.
68+
pub fn extern_<P: AsRef<Path>>(&mut self, crate_name: &str, path: P) -> &mut Self {
69+
assert!(
70+
!crate_name.contains(|c: char| c.is_whitespace() || c == '\\' || c == '/'),
71+
"crate name cannot contain whitespace or path separators"
72+
);
73+
74+
let path = path.as_ref().to_string_lossy();
75+
76+
self.cmd.arg("--extern");
77+
self.cmd.arg(format!("{crate_name}={path}"));
78+
79+
self
80+
}
81+
82+
/// Specify path to the input file.
83+
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
84+
self.cmd.arg(path.as_ref());
85+
self
86+
}
87+
88+
/// Specify target triple.
89+
pub fn target(&mut self, target: &str) -> &mut Self {
90+
assert!(!target.contains(char::is_whitespace), "target triple cannot contain spaces");
91+
self.cmd.arg(format!("--target={target}"));
92+
self
93+
}
94+
95+
/// Generic command argument provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
96+
/// This method will panic if a plain `-Z` or `-C` is passed, or if `-Z <name>` or `-C <name>`
97+
/// is passed (note the space).
98+
pub fn arg(&mut self, arg: &str) -> &mut Self {
99+
assert!(
100+
!(["-Z", "-C"].contains(&arg) || arg.starts_with("-Z ") || arg.starts_with("-C ")),
101+
"use `-Zarg` or `-Carg` over split `-Z` `arg` or `-C` `arg`"
102+
);
103+
self.cmd.arg(arg);
104+
self
105+
}
106+
107+
/// Generic command arguments provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
108+
/// This method will panic if a plain `-Z` or `-C` is passed, or if `-Z <name>` or `-C <name>`
109+
/// is passed (note the space).
110+
pub fn args(&mut self, args: &[&str]) -> &mut Self {
111+
for arg in args {
112+
assert!(
113+
!(["-Z", "-C"].contains(&arg) || arg.starts_with("-Z ") || arg.starts_with("-C ")),
114+
"use `-Zarg` or `-Carg` over split `-Z` `arg` or `-C` `arg`"
115+
);
116+
}
117+
118+
self.cmd.args(args);
119+
self
120+
}
121+
122+
// Command inspection, output and running helper methods
123+
124+
/// Get the [`Output`][std::process::Output] of the finished `rustc` process.
125+
pub fn output(&mut self) -> Output {
126+
self.cmd.output().unwrap()
127+
}
128+
129+
/// Run the constructed `rustc` command and assert that it is successfully run.
130+
#[track_caller]
131+
pub fn run(&mut self) -> Output {
132+
let caller_location = std::panic::Location::caller();
133+
let caller_line_number = caller_location.line();
134+
135+
let output = self.cmd.output().unwrap();
136+
if !output.status.success() {
137+
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
138+
}
139+
output
140+
}
141+
142+
/// Inspect what the underlying [`Command`] is up to the current construction.
143+
pub fn inspect(&mut self, f: impl FnOnce(&Command)) -> &mut Self {
144+
f(&self.cmd);
145+
self
146+
}
147+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
use std::env;
2+
use std::path::Path;
3+
use std::process::{Command, Output};
4+
5+
use crate::handle_failed_output;
6+
7+
/// Construct a plain `rustdoc` invocation with no flags set.
8+
pub fn bare_rustdoc() -> Rustdoc {
9+
Rustdoc::bare()
10+
}
11+
12+
/// Construct a new `rustdoc` invocation with `-L $(TARGET_RPATH_DIR)` set.
13+
pub fn rustdoc() -> Rustdoc {
14+
Rustdoc::new()
15+
}
16+
17+
#[derive(Debug)]
18+
pub struct Rustdoc {
19+
cmd: Command,
20+
}
21+
22+
fn setup_common() -> Command {
23+
let rustdoc = env::var("RUSTDOC").unwrap();
24+
Command::new(rustdoc)
25+
}
26+
27+
impl Rustdoc {
28+
/// Construct a bare `rustdoc` invocation.
29+
pub fn bare() -> Self {
30+
let cmd = setup_common();
31+
Self { cmd }
32+
}
33+
34+
/// Construct a `rustdoc` invocation with `-L $(TARGET_RPATH_DIR)` set.
35+
pub fn new() -> Self {
36+
let mut cmd = setup_common();
37+
let target_rpath_dir = env::var_os("TARGET_RPATH_DIR").unwrap();
38+
cmd.arg(format!("-L{}", target_rpath_dir.to_string_lossy()));
39+
Self { cmd }
40+
}
41+
42+
/// Specify path to the input file.
43+
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
44+
self.cmd.arg(path.as_ref());
45+
self
46+
}
47+
48+
/// Specify output directory.
49+
pub fn out_dir<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
50+
self.cmd.arg("--out-dir").arg(path.as_ref());
51+
self
52+
}
53+
54+
/// Given a `path`, pass `@{path}` to `rustdoc` as an
55+
/// [arg file](https://doc.rust-lang.org/rustdoc/command-line-arguments.html#path-load-command-line-flags-from-a-path).
56+
pub fn arg_file<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
57+
self.cmd.arg(format!("@{}", path.as_ref().display()));
58+
self
59+
}
60+
61+
/// Fallback argument provider. Consider adding meaningfully named methods instead of using
62+
/// this method.
63+
pub fn arg(&mut self, arg: &str) -> &mut Self {
64+
self.cmd.arg(arg);
65+
self
66+
}
67+
68+
/// Run the build `rustdoc` command and assert that the run is successful.
69+
#[track_caller]
70+
pub fn run(&mut self) -> Output {
71+
let caller_location = std::panic::Location::caller();
72+
let caller_line_number = caller_location.line();
73+
74+
let output = self.cmd.output().unwrap();
75+
if !output.status.success() {
76+
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
77+
}
78+
output
79+
}
80+
}

‎tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
// ignore-tidy-linelength
22

3+
// Check that the `CURRENT_RUSTC_VERSION` placeholder is correctly replaced by the current
4+
// `rustc` version and the `since` property in feature stability gating is properly respected.
5+
36
extern crate run_make_support;
47

58
use std::path::PathBuf;
69

7-
use run_make_support::{aux_build, rustc};
10+
use run_make_support::{rustc, aux_build};
811

912
fn main() {
10-
aux_build()
11-
.arg("--emit=metadata")
12-
.arg("stable.rs")
13-
.run();
13+
aux_build().input("stable.rs").emit("metadata").run();
14+
1415
let mut stable_path = PathBuf::from(env!("TMPDIR"));
1516
stable_path.push("libstable.rmeta");
17+
1618
let output = rustc()
17-
.arg("--emit=metadata")
18-
.arg("--extern")
19-
.arg(&format!("stable={}", &stable_path.to_string_lossy()))
20-
.arg("main.rs")
21-
.run();
19+
.input("main.rs")
20+
.emit("metadata")
21+
.extern_("stable", &stable_path)
22+
.output();
2223

2324
let stderr = String::from_utf8_lossy(&output.stderr);
2425
let version = include_str!(concat!(env!("S"), "/src/version"));

‎tests/run-make/a-b-a-linker-guard/rmake.rs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,36 @@
11
// ignore-tidy-linelength
22

3+
// Test that if we build `b` against a version of `a` that has one set of types, it will not run
4+
// with a dylib that has a different set of types.
5+
36
extern crate run_make_support;
47

58
use run_make_support::{run, run_fail, rustc};
69

710
fn main() {
811
rustc()
9-
.arg("a.rs")
10-
.arg("--cfg")
11-
.arg("x")
12-
.arg("-C")
13-
.arg("prefer-dynamic")
14-
.arg("-Z")
15-
.arg("unstable-options")
16-
.arg("-C")
17-
.arg("symbol-mangling-version=legacy")
12+
.input("a.rs")
13+
.cfg("x")
14+
.arg("-Zunstable-options")
15+
.arg("-Cprefer-dynamic")
16+
.arg("-Csymbol-mangling-version=legacy")
1817
.run();
1918

2019
rustc()
21-
.arg("b.rs")
22-
.arg("-C")
23-
.arg("prefer-dynamic")
24-
.arg("-Z")
25-
.arg("unstable-options")
26-
.arg("-C")
27-
.arg("symbol-mangling-version=legacy")
28-
.run();
20+
.input("b.rs")
21+
.arg("-Zunstable-options")
22+
.arg("-Cprefer-dynamic")
23+
.arg("-Csymbol-mangling-version=legacy")
24+
.run();
2925

3026
run("b");
3127

3228
rustc()
33-
.arg("a.rs")
34-
.arg("--cfg")
35-
.arg("y")
36-
.arg("-C")
37-
.arg("prefer-dynamic")
38-
.arg("-Z")
39-
.arg("unstable-options")
40-
.arg("-C")
41-
.arg("symbol-mangling-version=legacy")
29+
.input("a.rs")
30+
.cfg("y")
31+
.arg("-Zunstable-options")
32+
.arg("-Cprefer-dynamic")
33+
.arg("-Csymbol-mangling-version=legacy")
4234
.run();
4335

4436
run_fail("b");

‎tests/run-make/compiler-builtins/rmake.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use run_make_support::object::read::Object;
1818
use run_make_support::object::ObjectSection;
1919
use run_make_support::object::ObjectSymbol;
2020
use run_make_support::object::RelocationTarget;
21-
use run_make_support::out_dir;
21+
use run_make_support::tmp_dir;
2222
use std::collections::HashSet;
2323

2424
const MANIFEST: &str = r#"
@@ -31,7 +31,7 @@ edition = "2021"
3131
path = "lib.rs""#;
3232

3333
fn main() {
34-
let target_dir = out_dir().join("target");
34+
let target_dir = tmp_dir().join("target");
3535
let target = std::env::var("TARGET").unwrap();
3636
if target.starts_with("wasm") || target.starts_with("nvptx") {
3737
// wasm and nvptx targets don't produce rlib files that object can parse.
@@ -41,9 +41,9 @@ fn main() {
4141
println!("Testing compiler_builtins for {}", target);
4242

4343
// Set up the tiniest Cargo project: An empty no_std library. Just enough to run -Zbuild-std.
44-
let manifest_path = out_dir().join("Cargo.toml");
44+
let manifest_path = tmp_dir().join("Cargo.toml");
4545
std::fs::write(&manifest_path, MANIFEST.as_bytes()).unwrap();
46-
std::fs::write(out_dir().join("lib.rs"), b"#![no_std]").unwrap();
46+
std::fs::write(tmp_dir().join("lib.rs"), b"#![no_std]").unwrap();
4747

4848
let path = std::env::var("PATH").unwrap();
4949
let rustc = std::env::var("RUSTC").unwrap();
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
extern crate run_make_support;
22

3-
use run_make_support::{out_dir, rustdoc};
4-
use std::{fs, iter};
3+
use run_make_support::{rustdoc, tmp_dir};
54
use std::path::Path;
5+
use std::{fs, iter};
66

77
fn generate_a_lot_of_cfgs(path: &Path) {
88
let content = iter::repeat("--cfg=a\n").take(100_000).collect::<String>();
99
fs::write(path, content.as_bytes()).expect("failed to create args file");
1010
}
1111

1212
fn main() {
13-
let arg_file = out_dir().join("args");
13+
let arg_file = tmp_dir().join("args");
1414
generate_a_lot_of_cfgs(&arg_file);
1515

16-
let arg_file = format!("@{}", arg_file.display());
17-
rustdoc().arg("--test").arg(&arg_file).arg("foo.rs").run();
16+
rustdoc().out_dir(tmp_dir()).input("foo.rs").arg_file(&arg_file).arg("--test").run();
1817
}

‎tests/run-make/wasm-abi/rmake.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extern crate run_make_support;
22

3-
use run_make_support::{out_dir, rustc};
3+
use run_make_support::{rustc, tmp_dir};
44
use std::path::Path;
55
use std::process::Command;
66

@@ -9,8 +9,9 @@ fn main() {
99
return;
1010
}
1111

12-
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").run();
13-
let file = out_dir().join("foo.wasm");
12+
rustc().input("foo.rs").target("wasm32-wasip1").run();
13+
14+
let file = tmp_dir().join("foo.wasm");
1415

1516
let has_wasmtime = match Command::new("wasmtime").arg("--version").output() {
1617
Ok(s) => s.status.success(),

‎tests/run-make/wasm-custom-section/rmake.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
extern crate run_make_support;
22

3-
use run_make_support::{out_dir, rustc, wasmparser};
3+
use run_make_support::{rustc, tmp_dir, wasmparser};
44
use std::collections::HashMap;
55

66
fn main() {
77
if std::env::var("TARGET").unwrap() != "wasm32-wasip1" {
88
return;
99
}
1010

11-
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").run();
12-
rustc().arg("bar.rs").arg("--target=wasm32-wasip1").arg("-Clto").arg("-O").run();
11+
rustc().input("foo.rs").target("wasm32-wasip1").run();
12+
rustc().input("bar.rs").target("wasm32-wasip1").arg("-Clto").opt().run();
1313

14-
let file = std::fs::read(&out_dir().join("bar.wasm")).unwrap();
14+
let file = std::fs::read(&tmp_dir().join("bar.wasm")).unwrap();
1515

1616
let mut custom = HashMap::new();
1717
for payload in wasmparser::Parser::new(0).parse_all(&file) {

‎tests/run-make/wasm-custom-sections-opt/rmake.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extern crate run_make_support;
22

3-
use run_make_support::{out_dir, rustc, wasmparser};
3+
use run_make_support::{tmp_dir, wasmparser, rustc};
44
use std::collections::HashMap;
55
use std::path::Path;
66

@@ -9,8 +9,9 @@ fn main() {
99
return;
1010
}
1111

12-
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").arg("-O").run();
13-
verify(&out_dir().join("foo.wasm"));
12+
rustc().input("foo.rs").target("wasm32-wasip1").opt().run();
13+
14+
verify(&tmp_dir().join("foo.wasm"));
1415
}
1516

1617
fn verify(path: &Path) {

‎tests/run-make/wasm-export-all-symbols/rmake.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extern crate run_make_support;
22

3-
use run_make_support::{out_dir, rustc, wasmparser};
3+
use run_make_support::{tmp_dir, wasmparser, rustc};
44
use std::collections::HashMap;
55
use std::path::Path;
66
use wasmparser::ExternalKind::*;
@@ -17,16 +17,17 @@ fn main() {
1717

1818
fn test(args: &[&str]) {
1919
eprintln!("running with {args:?}");
20-
rustc().arg("bar.rs").arg("--target=wasm32-wasip1").args(args).run();
21-
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").args(args).run();
22-
rustc().arg("main.rs").arg("--target=wasm32-wasip1").args(args).run();
20+
21+
rustc().input("bar.rs").target("wasm32-wasip1").args(args).run();
22+
rustc().input("foo.rs").target("wasm32-wasip1").args(args).run();
23+
rustc().input("main.rs").target("wasm32-wasip1").args(args).run();
2324

2425
verify_exports(
25-
&out_dir().join("foo.wasm"),
26+
&tmp_dir().join("foo.wasm"),
2627
&[("foo", Func), ("FOO", Global), ("memory", Memory)],
2728
);
2829
verify_exports(
29-
&out_dir().join("main.wasm"),
30+
&tmp_dir().join("main.wasm"),
3031
&[
3132
("foo", Func),
3233
("FOO", Global),

‎tests/run-make/wasm-import-module/rmake.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extern crate run_make_support;
22

3-
use run_make_support::{out_dir, rustc, wasmparser};
3+
use run_make_support::{tmp_dir, wasmparser, rustc};
44
use std::collections::HashMap;
55
use wasmparser::TypeRef::Func;
66

@@ -9,10 +9,15 @@ fn main() {
99
return;
1010
}
1111

12-
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").run();
13-
rustc().arg("bar.rs").arg("--target=wasm32-wasip1").arg("-Clto").arg("-O").run();
12+
rustc().input("foo.rs").target("wasm32-wasip1").run();
13+
rustc()
14+
.input("bar.rs")
15+
.target("wasm32-wasip1")
16+
.arg("-Clto")
17+
.opt()
18+
.run();
1419

15-
let file = std::fs::read(&out_dir().join("bar.wasm")).unwrap();
20+
let file = std::fs::read(&tmp_dir().join("bar.wasm")).unwrap();
1621

1722
let mut imports = HashMap::new();
1823
for payload in wasmparser::Parser::new(0).parse_all(&file) {

‎tests/run-make/wasm-panic-small/rmake.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
extern crate run_make_support;
44

5-
use run_make_support::{out_dir, rustc};
5+
use run_make_support::{rustc, tmp_dir};
66

77
fn main() {
88
if std::env::var("TARGET").unwrap() != "wasm32-wasip1" {
@@ -17,16 +17,10 @@ fn main() {
1717

1818
fn test(cfg: &str) {
1919
eprintln!("running cfg {cfg:?}");
20-
rustc()
21-
.arg("foo.rs")
22-
.arg("--target=wasm32-wasip1")
23-
.arg("-Clto")
24-
.arg("-O")
25-
.arg("--cfg")
26-
.arg(cfg)
27-
.run();
2820

29-
let bytes = std::fs::read(&out_dir().join("foo.wasm")).unwrap();
21+
rustc().input("foo.rs").target("wasm32-wasip1").arg("-Clto").opt().cfg(cfg).run();
22+
23+
let bytes = std::fs::read(&tmp_dir().join("foo.wasm")).unwrap();
3024
println!("{}", bytes.len());
3125
assert!(bytes.len() < 40_000);
3226
}

‎tests/run-make/wasm-spurious-import/rmake.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
extern crate run_make_support;
22

3-
use run_make_support::{out_dir, rustc, wasmparser};
3+
use run_make_support::{rustc, tmp_dir, wasmparser};
44
use std::collections::HashMap;
5-
use wasmparser::TypeRef::Func;
65

76
fn main() {
87
if std::env::var("TARGET").unwrap() != "wasm32-wasip1" {
98
return;
109
}
1110

1211
rustc()
13-
.arg("main.rs")
14-
.arg("--target=wasm32-wasip1")
15-
.arg("-Coverflow-checks=yes")
12+
.input("main.rs")
13+
.target("wasm32-wasip1")
14+
.arg("-Coverflow-checks")
1615
.arg("-Cpanic=abort")
1716
.arg("-Clto")
1817
.arg("-Copt-level=z")
1918
.run();
2019

21-
let file = std::fs::read(&out_dir().join("main.wasm")).unwrap();
20+
let file = std::fs::read(&tmp_dir().join("main.wasm")).unwrap();
2221

2322
let mut imports = HashMap::new();
2423
for payload in wasmparser::Parser::new(0).parse_all(&file) {

‎tests/run-make/wasm-stringify-ints-small/rmake.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
extern crate run_make_support;
44

5-
use run_make_support::{out_dir, rustc};
5+
use run_make_support::{rustc, tmp_dir};
66

77
fn main() {
88
if std::env::var("TARGET").unwrap() != "wasm32-wasip1" {
99
return;
1010
}
1111

12-
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").arg("-Clto").arg("-O").run();
12+
rustc().input("foo.rs").target("wasm32-wasip1").arg("-Clto").opt().run();
1313

14-
let bytes = std::fs::read(&out_dir().join("foo.wasm")).unwrap();
14+
let bytes = std::fs::read(&tmp_dir().join("foo.wasm")).unwrap();
1515
println!("{}", bytes.len());
1616
assert!(bytes.len() < 50_000);
1717
}

‎tests/run-make/wasm-symbols-different-module/rmake.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extern crate run_make_support;
22

3-
use run_make_support::{out_dir, rustc, wasmparser};
3+
use run_make_support::{rustc, tmp_dir, wasmparser};
44
use std::collections::{HashMap, HashSet};
55

66
fn main() {
@@ -24,9 +24,9 @@ fn test_file(file: &str, expected_imports: &[(&str, &[&str])]) {
2424
fn test(file: &str, args: &[&str], expected_imports: &[(&str, &[&str])]) {
2525
println!("test {file:?} {args:?} for {expected_imports:?}");
2626

27-
rustc().arg(file).arg("--target=wasm32-wasip1").args(args).run();
27+
rustc().input(file).target("wasm32-wasip1").args(args).run();
2828

29-
let file = std::fs::read(&out_dir().join(file).with_extension("wasm")).unwrap();
29+
let file = std::fs::read(&tmp_dir().join(file).with_extension("wasm")).unwrap();
3030

3131
let mut imports = HashMap::new();
3232
for payload in wasmparser::Parser::new(0).parse_all(&file) {

‎tests/run-make/wasm-symbols-not-exported/rmake.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
extern crate run_make_support;
22

3-
use run_make_support::{out_dir, rustc, wasmparser};
3+
use run_make_support::{rustc, tmp_dir, wasmparser};
44
use std::path::Path;
55

66
fn main() {
77
if std::env::var("TARGET").unwrap() != "wasm32-wasip1" {
88
return;
99
}
1010

11-
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").run();
12-
verify_symbols(&out_dir().join("foo.wasm"));
13-
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").arg("-O").run();
14-
verify_symbols(&out_dir().join("foo.wasm"));
11+
rustc().input("foo.rs").target("wasm32-wasip1").run();
12+
verify_symbols(&tmp_dir().join("foo.wasm"));
13+
rustc().input("foo.rs").target("wasm32-wasip1").opt().run();
14+
verify_symbols(&tmp_dir().join("foo.wasm"));
1515

16-
rustc().arg("bar.rs").arg("--target=wasm32-wasip1").run();
17-
verify_symbols(&out_dir().join("bar.wasm"));
18-
rustc().arg("bar.rs").arg("--target=wasm32-wasip1").arg("-O").run();
19-
verify_symbols(&out_dir().join("bar.wasm"));
16+
rustc().input("bar.rs").target("wasm32-wasip1").run();
17+
verify_symbols(&tmp_dir().join("bar.wasm"));
18+
rustc().input("bar.rs").target("wasm32-wasip1").opt().run();
19+
verify_symbols(&tmp_dir().join("bar.wasm"));
2020
}
2121

2222
fn verify_symbols(path: &Path) {

‎tests/run-make/wasm-symbols-not-imported/rmake.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
extern crate run_make_support;
22

3-
use run_make_support::{out_dir, rustc, wasmparser};
3+
use run_make_support::{rustc, tmp_dir, wasmparser};
44
use std::path::Path;
55

66
fn main() {
77
if std::env::var("TARGET").unwrap() != "wasm32-wasip1" {
88
return;
99
}
1010

11-
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").run();
12-
verify_symbols(&out_dir().join("foo.wasm"));
13-
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").arg("-Clto").run();
14-
verify_symbols(&out_dir().join("foo.wasm"));
15-
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").arg("-O").run();
16-
verify_symbols(&out_dir().join("foo.wasm"));
17-
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").arg("-Clto").arg("-O").run();
18-
verify_symbols(&out_dir().join("foo.wasm"));
11+
rustc().input("foo.rs").target("wasm32-wasip1").run();
12+
verify_symbols(&tmp_dir().join("foo.wasm"));
13+
rustc().input("foo.rs").target("wasm32-wasip1").arg("-Clto").run();
14+
verify_symbols(&tmp_dir().join("foo.wasm"));
15+
rustc().input("foo.rs").target("wasm32-wasip1").opt().run();
16+
verify_symbols(&tmp_dir().join("foo.wasm"));
17+
rustc().input("foo.rs").target("wasm32-wasip1").arg("-Clto").opt().run();
18+
verify_symbols(&tmp_dir().join("foo.wasm"));
1919
}
2020

2121
fn verify_symbols(path: &Path) {

0 commit comments

Comments
 (0)
Please sign in to comment.