Skip to content

Commit adb15a2

Browse files
committed
Auto merge of rust-lang#114560 - RalfJung:miri, r=RalfJung
update Miri
2 parents 4a71a05 + d1174a9 commit adb15a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1645
-778
lines changed

Diff for: src/tools/miri/.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ jobs:
130130
- name: clippy
131131
run: ./miri clippy -- -D warnings
132132
- name: rustdoc
133-
run: RUSTDOCFLAGS="-Dwarnings" cargo doc --document-private-items
133+
run: RUSTDOCFLAGS="-Dwarnings" ./miri cargo doc --document-private-items
134134

135135
# These jobs doesn't actually test anything, but they're only used to tell
136136
# bors the build completed, as there is no practical way to detect when a

Diff for: src/tools/miri/CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ evaluation error was originally raised.
107107
### UI testing
108108

109109
We use ui-testing in Miri, meaning we generate `.stderr` and `.stdout` files for the output
110-
produced by Miri. You can use `./miri bless` to automatically (re)generate these files when
110+
produced by Miri. You can use `./miri test --bless` to automatically (re)generate these files when
111111
you add new tests or change how Miri presents certain output.
112112

113113
Note that when you also use `MIRIFLAGS` to change optimizations and similar, the ui output

Diff for: src/tools/miri/cargo-miri/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn main() {
5656
return;
5757
}
5858

59-
// The way rustdoc invokes rustc is indistuingishable from the way cargo invokes rustdoc by the
59+
// The way rustdoc invokes rustc is indistinguishable from the way cargo invokes rustdoc by the
6060
// arguments alone. `phase_cargo_rustdoc` sets this environment variable to let us disambiguate.
6161
if env::var_os("MIRI_CALLED_FROM_RUSTDOC").is_some() {
6262
// ...however, we then also see this variable when rustdoc invokes us as the testrunner!

Diff for: src/tools/miri/cargo-miri/src/phases.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
9494
let target = target.as_ref().unwrap_or(host);
9595

9696
// We always setup.
97-
setup(&subcommand, target, &rustc_version, verbose);
97+
let miri_sysroot = setup(&subcommand, target, &rustc_version, verbose);
9898

9999
// Invoke actual cargo for the job, but with different flags.
100100
// We re-use `cargo test` and `cargo run`, which makes target and binary handling very easy but
@@ -159,6 +159,8 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
159159
// Forward all further arguments (not consumed by `ArgSplitFlagValue`) to cargo.
160160
cmd.args(args);
161161

162+
// Let it know where the Miri sysroot lives.
163+
cmd.env("MIRI_SYSROOT", miri_sysroot);
162164
// Set `RUSTC_WRAPPER` to ourselves. Cargo will prepend that binary to its usual invocation,
163165
// i.e., the first argument is `rustc` -- which is what we use in `main` to distinguish
164166
// the two codepaths. (That extra argument is why we prefer this over setting `RUSTC`.)
@@ -519,7 +521,7 @@ pub fn phase_runner(mut binary_args: impl Iterator<Item = String>, phase: Runner
519521
// `.rmeta`.
520522
// We also need to remove `--error-format` as cargo specifies that to be JSON,
521523
// but when we run here, cargo does not interpret the JSON any more. `--json`
522-
// then also nees to be dropped.
524+
// then also needs to be dropped.
523525
let mut args = info.args.into_iter();
524526
let error_format_flag = "--error-format";
525527
let json_flag = "--json";
@@ -538,8 +540,7 @@ pub fn phase_runner(mut binary_args: impl Iterator<Item = String>, phase: Runner
538540
}
539541
// Respect `MIRIFLAGS`.
540542
if let Ok(a) = env::var("MIRIFLAGS") {
541-
// This code is taken from `RUSTFLAGS` handling in cargo.
542-
let args = a.split(' ').map(str::trim).filter(|s| !s.is_empty()).map(str::to_string);
543+
let args = flagsplit(&a);
543544
cmd.args(args);
544545
}
545546

Diff for: src/tools/miri/cargo-miri/src/setup.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@ use crate::util::*;
1313
/// Performs the setup required to make `cargo miri` work: Getting a custom-built libstd. Then sets
1414
/// `MIRI_SYSROOT`. Skipped if `MIRI_SYSROOT` is already set, in which case we expect the user has
1515
/// done all this already.
16-
pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta, verbose: usize) {
16+
pub fn setup(
17+
subcommand: &MiriCommand,
18+
target: &str,
19+
rustc_version: &VersionMeta,
20+
verbose: usize,
21+
) -> PathBuf {
1722
let only_setup = matches!(subcommand, MiriCommand::Setup);
1823
let ask_user = !only_setup;
1924
let print_sysroot = only_setup && has_arg_flag("--print-sysroot"); // whether we just print the sysroot path
20-
if !only_setup && std::env::var_os("MIRI_SYSROOT").is_some() {
21-
// Skip setup step if MIRI_SYSROOT is explicitly set, *unless* we are `cargo miri setup`.
22-
return;
25+
if !only_setup {
26+
if let Some(sysroot) = std::env::var_os("MIRI_SYSROOT") {
27+
// Skip setup step if MIRI_SYSROOT is explicitly set, *unless* we are `cargo miri setup`.
28+
return sysroot.into();
29+
}
2330
}
2431

2532
// Determine where the rust sources are located. The env var trumps auto-detection.
@@ -92,6 +99,8 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
9299
command.env("RUSTC", &cargo_miri_path);
93100
}
94101
command.env("MIRI_CALLED_FROM_SETUP", "1");
102+
// Miri expects `MIRI_SYSROOT` to be set when invoked in target mode. Even if that directory is empty.
103+
command.env("MIRI_SYSROOT", &sysroot_dir);
95104
// Make sure there are no other wrappers getting in our way (Cc
96105
// https://github.com/rust-lang/miri/issues/1421,
97106
// https://github.com/rust-lang/miri/issues/2429). Looks like setting
@@ -105,7 +114,7 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
105114
command.arg("-v");
106115
}
107116
} else {
108-
// Supress output.
117+
// Suppress output.
109118
command.stdout(process::Stdio::null());
110119
command.stderr(process::Stdio::null());
111120
}
@@ -117,8 +126,6 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
117126
// the user might have set, which is consistent with normal `cargo build` that does
118127
// not apply `RUSTFLAGS` to the sysroot either.
119128
let rustflags = &["-Cdebug-assertions=off", "-Coverflow-checks=on"];
120-
// Make sure all target-level Miri invocations know their sysroot.
121-
std::env::set_var("MIRI_SYSROOT", &sysroot_dir);
122129

123130
// Do the build.
124131
if print_sysroot {
@@ -159,4 +166,6 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
159166
// Print just the sysroot and nothing else to stdout; this way we do not need any escaping.
160167
println!("{}", sysroot_dir.display());
161168
}
169+
170+
sysroot_dir
162171
}

Diff for: src/tools/miri/cargo-miri/src/util.rs

+6-39
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use std::collections::HashMap;
21
use std::env;
32
use std::ffi::OsString;
4-
use std::fmt::Write as _;
53
use std::fs::File;
64
use std::io::{self, BufWriter, Read, Write};
75
use std::ops::Not;
@@ -114,6 +112,11 @@ pub fn cargo() -> Command {
114112
Command::new(env::var_os("CARGO").unwrap_or_else(|| OsString::from("cargo")))
115113
}
116114

115+
pub fn flagsplit(flags: &str) -> Vec<String> {
116+
// This code is taken from `RUSTFLAGS` handling in cargo.
117+
flags.split(' ').map(str::trim).filter(|s| !s.is_empty()).map(str::to_string).collect()
118+
}
119+
117120
/// Execute the `Command`, where possible by replacing the current process with a new process
118121
/// described by the `Command`. Then exit this process with the exit code of the new process.
119122
pub fn exec(mut cmd: Command) -> ! {
@@ -242,46 +245,10 @@ pub fn local_crates(metadata: &Metadata) -> String {
242245
local_crates
243246
}
244247

245-
fn env_vars_from_cmd(cmd: &Command) -> Vec<(String, String)> {
246-
let mut envs = HashMap::new();
247-
for (key, value) in std::env::vars() {
248-
envs.insert(key, value);
249-
}
250-
for (key, value) in cmd.get_envs() {
251-
if let Some(value) = value {
252-
envs.insert(key.to_string_lossy().to_string(), value.to_string_lossy().to_string());
253-
} else {
254-
envs.remove(&key.to_string_lossy().to_string());
255-
}
256-
}
257-
let mut envs: Vec<_> = envs.into_iter().collect();
258-
envs.sort();
259-
envs
260-
}
261-
262248
/// Debug-print a command that is going to be run.
263249
pub fn debug_cmd(prefix: &str, verbose: usize, cmd: &Command) {
264250
if verbose == 0 {
265251
return;
266252
}
267-
// We only do a single `eprintln!` call to minimize concurrency interactions.
268-
let mut out = prefix.to_string();
269-
writeln!(out, " running command: env \\").unwrap();
270-
if verbose > 1 {
271-
// Print the full environment this will be called in.
272-
for (key, value) in env_vars_from_cmd(cmd) {
273-
writeln!(out, "{key}={value:?} \\").unwrap();
274-
}
275-
} else {
276-
// Print only what has been changed for this `cmd`.
277-
for (var, val) in cmd.get_envs() {
278-
if let Some(val) = val {
279-
writeln!(out, "{}={val:?} \\", var.to_string_lossy()).unwrap();
280-
} else {
281-
writeln!(out, "--unset={}", var.to_string_lossy()).unwrap();
282-
}
283-
}
284-
}
285-
write!(out, "{cmd:?}").unwrap();
286-
eprintln!("{out}");
253+
eprintln!("{prefix} running command: {cmd:?}");
287254
}

0 commit comments

Comments
 (0)