Skip to content

Commit 6d098b2

Browse files
Rollup merge of #163226 - RalfJung:miri, r=RalfJung
miri subtree update Let's get the fix for rust-lang/miri#5341 shipped. Subtree update of `miri` to rust-lang/miri@a018306. Created using https://github.com/rust-lang/josh-sync. r? @ghost
2 parents c092ef0 + b2e7048 commit 6d098b2

17 files changed

Lines changed: 220 additions & 47 deletions

‎src/tools/miri/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ flamegraph*.svg
1313
rustc-ice*.txt
1414
tests/native-lib/libtestlib.so
1515
.auto-*
16+
miri.toml
1617

1718
/genmc/

‎src/tools/miri/CONTRIBUTING.md‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,36 @@ install that exact version of rustc as a toolchain:
111111
This will set up a rustup toolchain called `miri` and set it as an override for
112112
the current directory.
113113

114-
You can also create a `.auto-everything` file (contents don't matter, can be empty), which
115-
will cause any `./miri` command to automatically call `./miri toolchain`, `clippy` and `rustfmt`
116-
for you. If you don't want all of these to happen, you can add individual `.auto-toolchain`,
117-
`.auto-clippy` and `.auto-fmt` files respectively.
118-
119114
[`rustup-toolchain-install-master`]: https://github.com/kennytm/rustup-toolchain-install-master
120115

116+
### Configuring `./miri`
117+
118+
The `./miri` script supports optional configuration via a `miri.toml` file.
119+
The following configuration keys are currently supported, with the given default values:
120+
121+
```toml
122+
[toolchain]
123+
# Overwrite the default toolchain name used by `./miri toolchain`.
124+
# Note that all other commands will just use the currently active rustup toolchain!
125+
# (Though note that if you have `auto.toolchain` enabled, most commands will run `./miri toolchain`
126+
# first, which will activate the toolchain given here.)
127+
name = "miri"
128+
# Additional components to install with the toolchain. Note that if you remove `clippy` or `rustfmt`
129+
# from this list then obviously `./miri clippy`/`./miri fmt` will not work.
130+
# Only takes effect when a new toolchain is installed. Run `rustup toolchain remove <name>` followed
131+
# by `./miri toolchain` to force this to have effect.
132+
components = ["clippy", "rustfmt"]
133+
134+
[auto]
135+
# Automatically run `./miri toolchain` before most commands.
136+
# Uses the toolchain name configured above, if any.
137+
toolchain = false
138+
# Automatically run `./miri clippy` before most commands.
139+
clippy = false
140+
# Automatically run `./miri fmt` before most commands.
141+
fmt = false
142+
```
143+
121144
## Building and testing Miri
122145

123146
Invoking Miri requires getting a bunch of flags right and setting up a custom

‎src/tools/miri/cargo-miri/src/util.rs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,17 @@ impl CrateRunInfo {
4242
let env = env::vars_os()
4343
.filter(|(var, _val)| {
4444
// We only need to bother with env vars cargo actually sets.
45-
// We try to avoid storing anything that may contain secrets.
4645
var.to_str().is_some_and(|var| {
47-
var == "OUT_DIR" || (var.starts_with("CARGO_") && !var.ends_with("_TOKEN"))
46+
( // Env vars cargo sets for crates.
47+
// <https://doc.rust-lang.org/nightly/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates>
48+
var == "OUT_DIR"
49+
|| var.starts_with("CARGO_")
50+
// Env vars rustdoc sets for its rustc invocation.
51+
|| var.starts_with("UNSTABLE_RUSTDOC_")
52+
|| var.starts_with("RUSTDOC_")
53+
)
54+
// We try to avoid storing anything that may contain secrets.
55+
&& !var.ends_with("_TOKEN")
4856
})
4957
})
5058
.collect();

‎src/tools/miri/etc/rust_analyzer_vscode.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@
2525
"--compile-time-deps",
2626
"--message-format=json",
2727
],
28+
// RA reports false errors due to <https://github.com/rust-lang/rust-analyzer/issues/19755>
29+
"rust-analyzer.diagnostics.enable": false,
2830
}

‎src/tools/miri/miri-script/Cargo.lock‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ dependencies = [
274274
"serde_json",
275275
"shell-words",
276276
"tempfile",
277+
"toml",
277278
"walkdir",
278279
"xshell",
279280
]
@@ -409,6 +410,15 @@ dependencies = [
409410
"zmij",
410411
]
411412

413+
[[package]]
414+
name = "serde_spanned"
415+
version = "1.1.1"
416+
source = "registry+https://github.com/rust-lang/crates.io-index"
417+
checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26"
418+
dependencies = [
419+
"serde_core",
420+
]
421+
412422
[[package]]
413423
name = "shell-words"
414424
version = "1.1.1"
@@ -445,6 +455,37 @@ dependencies = [
445455
"windows-sys",
446456
]
447457

458+
[[package]]
459+
name = "toml"
460+
version = "1.1.4+spec-1.1.0"
461+
source = "registry+https://github.com/rust-lang/crates.io-index"
462+
checksum = "3aace63f4bbcdfc2c965b059de67119c89c4017a70d633be6c104910f67056f5"
463+
dependencies = [
464+
"serde_core",
465+
"serde_spanned",
466+
"toml_datetime",
467+
"toml_parser",
468+
"winnow",
469+
]
470+
471+
[[package]]
472+
name = "toml_datetime"
473+
version = "1.1.1+spec-1.1.0"
474+
source = "registry+https://github.com/rust-lang/crates.io-index"
475+
checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7"
476+
dependencies = [
477+
"serde_core",
478+
]
479+
480+
[[package]]
481+
name = "toml_parser"
482+
version = "1.1.3+spec-1.1.0"
483+
source = "registry+https://github.com/rust-lang/crates.io-index"
484+
checksum = "1d38ac1cf9b95face32296c0a3ede1fdc270627c9d9c02a7274dd6d960dc4d56"
485+
dependencies = [
486+
"winnow",
487+
]
488+
448489
[[package]]
449490
name = "unicode-ident"
450491
version = "1.0.24"
@@ -549,6 +590,12 @@ dependencies = [
549590
"windows-link",
550591
]
551592

593+
[[package]]
594+
name = "winnow"
595+
version = "1.0.4"
596+
source = "registry+https://github.com/rust-lang/crates.io-index"
597+
checksum = "23b97319f7b8343df12cc98938e5c3eb436064524c8d2b4e30a1d3a36eecdf81"
598+
552599
[[package]]
553600
name = "wit-bindgen"
554601
version = "0.46.0"

‎src/tools/miri/miri-script/Cargo.toml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ xshell = "0.2.6"
2222
rustc_version = "0.4"
2323
dunce = "1.0.4"
2424
serde = "1"
25+
serde_derive = "1" # direct dependency better parallelizes builds
2526
serde_json = "1"
26-
serde_derive = "1"
2727
tempfile = "3.13.0"
2828
clap = { version = "4.5.21", features = ["derive"] }
29+
toml = {version = "1", default-features = false, features = ["serde", "parse"] }

‎src/tools/miri/miri-script/src/commands.rs‎

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use walkdir::WalkDir;
1414
use xshell::{Shell, cmd};
1515

1616
use crate::Command;
17+
use crate::config::{Config, Toolchain};
1718
use crate::util::*;
1819

1920
impl MiriEnv {
@@ -67,25 +68,19 @@ impl MiriEnv {
6768
}
6869

6970
impl Command {
70-
fn auto_actions() -> Result<()> {
71+
fn auto_actions(config: &Config) -> Result<()> {
7172
if env::var_os("MIRI_AUTO_OPS").is_some_and(|x| x == "no") {
7273
return Ok(());
7374
}
7475

75-
let miri_dir = miri_dir()?;
76-
let auto_everything = path!(miri_dir / ".auto-everything").exists();
77-
let auto_toolchain = auto_everything || path!(miri_dir / ".auto-toolchain").exists();
78-
let auto_fmt = auto_everything || path!(miri_dir / ".auto-fmt").exists();
79-
let auto_clippy = auto_everything || path!(miri_dir / ".auto-clippy").exists();
80-
8176
// `toolchain` goes first as it could affect the others
82-
if auto_toolchain {
83-
Self::toolchain(None, vec![])?;
77+
if config.auto.toolchain {
78+
Self::toolchain(None, None, vec![], config)?;
8479
}
85-
if auto_fmt {
80+
if config.auto.fmt {
8681
Self::fmt(vec![])?;
8782
}
88-
if auto_clippy {
83+
if config.auto.clippy {
8984
// no features for auto actions, see
9085
// https://github.com/rust-lang/miri/pull/4396#discussion_r2149654845
9186
Self::clippy(vec![], vec![])?;
@@ -94,7 +89,7 @@ impl Command {
9489
Ok(())
9590
}
9691

97-
pub fn exec(self) -> Result<()> {
92+
pub fn exec(self, config: &Config) -> Result<()> {
9893
// First, and crucially only once, run the auto-actions -- but not for all commands.
9994
match &self {
10095
Command::Install { .. }
@@ -104,7 +99,7 @@ impl Command {
10499
| Command::Run { .. }
105100
| Command::Fmt { .. }
106101
| Command::Doc { .. }
107-
| Command::Clippy { .. } => Self::auto_actions()?,
102+
| Command::Clippy { .. } => Self::auto_actions(config)?,
108103
| Command::Toolchain { .. } | Command::Bench { .. } | Command::Squash => {}
109104
}
110105
// Then run the actual command.
@@ -121,20 +116,29 @@ impl Command {
121116
Command::Clippy { features, flags } => Self::clippy(features, flags),
122117
Command::Bench { target, no_install, save_baseline, load_baseline, benches } =>
123118
Self::bench(target, no_install, save_baseline, load_baseline, benches),
124-
Command::Toolchain { commit, flags } => Self::toolchain(commit, flags),
119+
Command::Toolchain { name, commit, flags } =>
120+
Self::toolchain(name, commit, flags, config),
125121
Command::Squash => Self::squash(),
126122
}
127123
}
128124

129-
fn toolchain(new_commit: Option<String>, flags: Vec<String>) -> Result<()> {
125+
fn toolchain(
126+
name: Option<String>,
127+
new_commit: Option<String>,
128+
flags: Vec<String>,
129+
config: &Config,
130+
) -> Result<()> {
131+
let name =
132+
name.as_deref().or(config.toolchain.name.as_deref()).unwrap_or(Toolchain::DEFAULT_NAME);
133+
130134
let sh = Shell::new()?;
131135
sh.change_dir(miri_dir()?);
132136
let new_commit = match new_commit {
133137
Some(c) => c,
134138
None => sh.read_file("rust-version")?.trim().to_owned(),
135139
};
136140
let current_commit = {
137-
let rustc_info = cmd!(sh, "rustc +miri --version -v").read();
141+
let rustc_info = cmd!(sh, "rustc +{name} --version -v").read();
138142
if let Ok(rustc_info) = rustc_info {
139143
let metadata = rustc_version::version_meta_for(&rustc_info)?;
140144
Some(
@@ -148,18 +152,25 @@ impl Command {
148152
};
149153
// Check if we already are at that commit.
150154
if current_commit.as_ref() == Some(&new_commit) {
151-
if active_toolchain()? != "miri" {
152-
cmd!(sh, "rustup override set miri").run()?;
155+
// The toolchain is already at the right version. Make sure it is active in `miri_dir`.
156+
// Ignore errors from `active_toolchain`, the active toolchain might be uninstalled.
157+
if active_toolchain().ok().is_none_or(|toolchain| toolchain != name) {
158+
cmd!(sh, "rustup override set {name}").run()?;
153159
}
154160
return Ok(());
155161
}
156-
// Install and setup new toolchain.
157-
cmd!(sh, "rustup toolchain uninstall miri").run()?;
158162

159-
cmd!(sh, "rustup-toolchain-install-master -n miri -c cargo -c rust-src -c rustc-dev -c llvm-tools -c rustfmt -c clippy {flags...} -- {new_commit}")
163+
// Compute rustup-toolchain-install-master flags for additional components.
164+
let components =
165+
config.toolchain.components.as_deref().unwrap_or(Toolchain::DEFAULT_COMPONENTS);
166+
let component_flags = components.iter().flat_map(|component| ["-c", component]);
167+
168+
// Install and setup new toolchain.
169+
cmd!(sh, "rustup toolchain uninstall {name}").run()?;
170+
cmd!(sh, "rustup-toolchain-install-master -n {name} -c cargo -c rust-src -c rustc-dev -c llvm-tools {component_flags...} {flags...} -- {new_commit}")
160171
.run()
161172
.context("Failed to run rustup-toolchain-install-master. If it is not installed, run 'cargo install --locked rustup-toolchain-install-master'.")?;
162-
cmd!(sh, "rustup override set miri").run()?;
173+
cmd!(sh, "rustup override set {name}").run()?;
163174
// Cleanup.
164175
cmd!(sh, "cargo clean").run()?;
165176
// Call `cargo metadata` on the sources in case that changes the lockfile
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
use std::borrow::Cow;
2+
use std::{fs, io};
3+
4+
use anyhow::{Context, Result, bail};
5+
use path_macro::path;
6+
use serde_derive::Deserialize;
7+
8+
use crate::util::miri_dir;
9+
10+
#[derive(Deserialize, Default)]
11+
pub struct Config {
12+
#[serde(default)]
13+
pub toolchain: Toolchain,
14+
#[serde(default)]
15+
pub auto: Auto,
16+
}
17+
18+
#[derive(Deserialize, Default)]
19+
pub struct Toolchain {
20+
pub name: Option<String>,
21+
pub components: Option<Vec<Cow<'static, str>>>,
22+
}
23+
24+
impl Toolchain {
25+
pub const DEFAULT_NAME: &str = "miri";
26+
pub const DEFAULT_COMPONENTS: &[Cow<'static, str>] =
27+
&[Cow::Borrowed("clippy"), Cow::Borrowed("rustfmt")];
28+
}
29+
30+
#[derive(Deserialize, Default)]
31+
pub struct Auto {
32+
#[serde(default)]
33+
pub toolchain: bool,
34+
#[serde(default)]
35+
pub fmt: bool,
36+
#[serde(default)]
37+
pub clippy: bool,
38+
}
39+
40+
impl Config {
41+
pub fn load() -> Result<Self> {
42+
let miri_dir = miri_dir()?;
43+
44+
Ok(match fs::read(path!(miri_dir / "miri.toml")) {
45+
Ok(config) => toml::from_slice(&config).context("failed to parse `miri.toml`")?,
46+
Err(err) if err.kind() == io::ErrorKind::NotFound => {
47+
// Just ignore error if the file does not exist. Fall back to parsing the `.auto-*`
48+
// files.
49+
let mut config = Config::default();
50+
let everything = path!(miri_dir / ".auto-everything").exists();
51+
config.auto.toolchain = everything || path!(miri_dir / ".auto-toolchain").exists();
52+
config.auto.fmt = everything || path!(miri_dir / ".auto-fmt").exists();
53+
config.auto.clippy = everything || path!(miri_dir / ".auto-clippy").exists();
54+
config
55+
}
56+
Err(err) => bail!("unable to open `miri.toml`: {err}"),
57+
})
58+
}
59+
}

‎src/tools/miri/miri-script/src/main.rs‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![allow(clippy::needless_question_mark, rustc::internal)]
22

33
mod commands;
4+
mod config;
45
mod coverage;
56
mod util;
67

@@ -137,11 +138,15 @@ pub enum Command {
137138
/// List of benchmarks to run (default: run all benchmarks).
138139
benches: Vec<String>,
139140
},
140-
/// Update and activate the rustup toolchain 'miri'.
141+
/// Update and activate the rustup toolchain 'miri' (or whatever name is configured in
142+
/// `miri.toml`).
141143
///
142144
/// The `rust-version` file is used to determine the commit that will be intsalled.
143145
/// `rustup-toolchain-install-master` must be installed for this to work.
144146
Toolchain {
147+
/// Overwrite the name the toolchain will have in `rustup`.
148+
#[arg(long)]
149+
name: Option<String>,
145150
/// Overwrite the commit to install.
146151
#[arg(long)]
147152
commit: Option<String>,
@@ -200,6 +205,10 @@ fn main() -> Result<()> {
200205
let args = Cli::parse_from(miri_args);
201206
let mut command = args.command;
202207
command.add_remainder(remainder)?;
203-
command.exec()?;
204-
Ok(())
208+
209+
// Parse config file.
210+
let config = config::Config::load()?;
211+
212+
// Run the thing.
213+
command.exec(&config)
205214
}

‎src/tools/miri/rust-version‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
feaadeeaca7db0594da854e7c8c07495341c7439
1+
88638df1e741778019e42fcdf307072865d19501

0 commit comments

Comments
 (0)