Skip to content

Commit 5a7e23a

Browse files
committed
Auto merge of #141116 - RalfJung:miri-sync, r=RalfJung
Miri subtree update r? `@ghost`
2 parents 7a1f9ad + f36f541 commit 5a7e23a

23 files changed

+69
-111
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name = "miri"
66
repository = "https://github.com/rust-lang/miri"
77
version = "0.1.0"
88
default-run = "miri"
9-
edition = "2021"
9+
edition = "2024"
1010

1111
[lib]
1212
test = true # we have unit tests

cargo-miri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ license = "MIT OR Apache-2.0"
55
name = "cargo-miri"
66
repository = "https://github.com/rust-lang/miri"
77
version = "0.1.0"
8-
edition = "2021"
8+
edition = "2024"
99

1010
[[bin]]
1111
name = "cargo-miri"

cargo-miri/src/main.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,37 @@ fn main() {
6363
return;
6464
}
6565

66+
let Some(first) = args.next() else {
67+
show_error!(
68+
"`cargo-miri` called without first argument; please only invoke this binary through `cargo miri`"
69+
)
70+
};
71+
6672
// The way rustdoc invokes rustc is indistinguishable from the way cargo invokes rustdoc by the
6773
// arguments alone. `phase_cargo_rustdoc` sets this environment variable to let us disambiguate.
6874
if env::var_os("MIRI_CALLED_FROM_RUSTDOC").is_some() {
6975
// ...however, we then also see this variable when rustdoc invokes us as the testrunner!
70-
// The runner is invoked as `$runtool ($runtool-arg)* output_file`;
71-
// since we don't specify any runtool-args, and rustdoc supplies multiple arguments to
72-
// the test-builder unconditionally, we can just check the number of remaining arguments:
73-
if args.len() == 1 {
74-
phase_runner(args, RunnerPhase::Rustdoc);
75-
} else {
76-
phase_rustc(args, RustcPhase::Rustdoc);
76+
// In that case the first argument is `runner` and there are no more arguments.
77+
match first.as_str() {
78+
"runner" => phase_runner(args, RunnerPhase::Rustdoc),
79+
flag if flag.starts_with("--") || flag.starts_with("@") => {
80+
// This is probably rustdoc invoking us to build the test. But we need to get `first`
81+
// "back onto the iterator", it is some part of the rustc invocation.
82+
phase_rustc(iter::once(first).chain(args), RustcPhase::Rustdoc);
83+
}
84+
_ => {
85+
show_error!(
86+
"`cargo-miri` failed to recognize which phase of the build process this is, please report a bug.\n\
87+
We are inside MIRI_CALLED_FROM_RUSTDOC.\n\
88+
The command-line arguments were: {:#?}",
89+
Vec::from_iter(env::args()),
90+
);
91+
}
7792
}
7893

7994
return;
8095
}
8196

82-
let Some(first) = args.next() else {
83-
show_error!(
84-
"`cargo-miri` called without first argument; please only invoke this binary through `cargo miri`"
85-
)
86-
};
8797
match first.as_str() {
8898
"miri" => phase_cargo_miri(args),
8999
"runner" => phase_runner(args, RunnerPhase::Cargo),

cargo-miri/src/phases.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
176176
// Set `--target-dir` to `miri` inside the original target directory.
177177
let target_dir = get_target_dir(&metadata);
178178
cmd.arg("--target-dir").arg(target_dir);
179+
// Enable cross-target doctests (for consistency between different cargo versions).
180+
cmd.arg("-Zdoctest-xcompile");
179181

180182
// *After* we set all the flags that need setting, forward everything else. Make sure to skip
181183
// `--target-dir` (which would otherwise be set twice).
@@ -666,11 +668,6 @@ pub fn phase_rustdoc(mut args: impl Iterator<Item = String>) {
666668
if arg == "--extern" {
667669
// Patch --extern arguments to use *.rmeta files, since phase_cargo_rustc only creates stub *.rlib files.
668670
forward_patched_extern_arg(&mut args, &mut cmd);
669-
} else if arg == "--test-runtool" {
670-
// An existing --test-runtool flag indicates cargo is running in cross-target mode, which we don't support.
671-
// Note that this is only passed when cargo is run with the unstable -Zdoctest-xcompile flag;
672-
// otherwise, we won't be called as rustdoc at all.
673-
show_error!("cross-interpreting doctests is not currently supported by Miri.");
674671
} else {
675672
cmd.arg(arg);
676673
}
@@ -702,10 +699,10 @@ pub fn phase_rustdoc(mut args: impl Iterator<Item = String>) {
702699
// make sure the 'miri' flag is set for rustdoc
703700
cmd.arg("--cfg").arg("miri");
704701

705-
// Make rustdoc call us back.
702+
// Make rustdoc call us back for the build.
703+
// (cargo already sets `--test-runtool` to us since we are the cargo test runner.)
706704
let cargo_miri_path = env::current_exe().expect("current executable path invalid");
707705
cmd.arg("--test-builder").arg(&cargo_miri_path); // invoked by forwarding most arguments
708-
cmd.arg("--test-runtool").arg(&cargo_miri_path); // invoked with just a single path argument
709706

710707
debug_cmd("[cargo-miri rustdoc]", verbose, &cmd);
711708
exec(cmd)

cargo-miri/src/setup.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ pub fn setup(
2424
let ask_user = !only_setup;
2525
let print_sysroot = only_setup && has_arg_flag("--print-sysroot"); // whether we just print the sysroot path
2626
let show_setup = only_setup && !print_sysroot;
27-
if !only_setup {
28-
if let Some(sysroot) = std::env::var_os("MIRI_SYSROOT") {
29-
// Skip setup step if MIRI_SYSROOT is explicitly set, *unless* we are `cargo miri setup`.
30-
return sysroot.into();
31-
}
27+
if !only_setup && let Some(sysroot) = std::env::var_os("MIRI_SYSROOT") {
28+
// Skip setup step if MIRI_SYSROOT is explicitly set, *unless* we are `cargo miri setup`.
29+
return sysroot.into();
3230
}
3331

3432
// Determine where the rust sources are located. The env var trumps auto-detection.

miri-script/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name = "miri-script"
66
repository = "https://github.com/rust-lang/miri"
77
version = "0.1.0"
88
default-run = "miri-script"
9-
edition = "2021"
9+
edition = "2024"
1010

1111
[workspace]
1212
# We make this a workspace root so that cargo does not go looking in ../Cargo.toml for the workspace root.

miri-script/src/commands.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -675,11 +675,9 @@ impl Command {
675675
let mut early_flags = Vec::<OsString>::new();
676676

677677
// In `dep` mode, the target is already passed via `MIRI_TEST_TARGET`
678-
if !dep {
679-
if let Some(target) = &target {
680-
early_flags.push("--target".into());
681-
early_flags.push(target.into());
682-
}
678+
if !dep && let Some(target) = &target {
679+
early_flags.push("--target".into());
680+
early_flags.push(target.into());
683681
}
684682
early_flags.push("--edition".into());
685683
early_flags.push(edition.as_deref().unwrap_or("2021").into());
@@ -707,10 +705,8 @@ impl Command {
707705
// Add Miri flags
708706
let mut cmd = cmd.args(&miri_flags).args(&early_flags).args(&flags);
709707
// For `--dep` we also need to set the target in the env var.
710-
if dep {
711-
if let Some(target) = &target {
712-
cmd = cmd.env("MIRI_TEST_TARGET", target);
713-
}
708+
if dep && let Some(target) = &target {
709+
cmd = cmd.env("MIRI_TEST_TARGET", target);
714710
}
715711
// Finally, run the thing.
716712
Ok(cmd.run()?)

miri-script/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl MiriEnv {
213213
let toolchain = &self.toolchain;
214214
let mut cmd = cmd!(
215215
self.sh,
216-
"rustfmt +{toolchain} --edition=2021 --config-path {config_path} --unstable-features --skip-children {flags...}"
216+
"rustfmt +{toolchain} --edition=2024 --config-path {config_path} --unstable-features --skip-children {flags...}"
217217
);
218218
if first {
219219
// Log an abbreviating command, and only once.

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2ad5f8607d0e192b60b130e5cc416b477b351c18
1+
a69bc17fb8026bdc0d24bb1896ff95f0eba1da4e

src/bin/miri.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ fn jemalloc_magic() {
459459
// linking, so we need to explicitly depend on the function.
460460
#[cfg(target_os = "macos")]
461461
{
462-
extern "C" {
462+
unsafe extern "C" {
463463
fn _rjem_je_zone_register();
464464
}
465465

0 commit comments

Comments
 (0)