|
1 | 1 | #![feature(rustc_private, stmt_expr_attributes)]
|
2 |
| -#![allow(clippy::manual_range_contains)] |
| 2 | +#![allow(clippy::manual_range_contains, clippy::useless_format)] |
3 | 3 |
|
4 | 4 | extern crate rustc_data_structures;
|
5 | 5 | extern crate rustc_driver;
|
@@ -143,6 +143,11 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
|
143 | 143 | }
|
144 | 144 | }
|
145 | 145 |
|
| 146 | +fn show_error(msg: String) -> ! { |
| 147 | + eprintln!("fatal error: {}", msg); |
| 148 | + std::process::exit(1) |
| 149 | +} |
| 150 | + |
146 | 151 | fn init_early_loggers() {
|
147 | 152 | // Note that our `extern crate log` is *not* the same as rustc's; as a result, we have to
|
148 | 153 | // initialize them both, and we always initialize `miri`'s first.
|
@@ -214,13 +219,26 @@ fn compile_time_sysroot() -> Option<String> {
|
214 | 219 | let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
|
215 | 220 | let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
|
216 | 221 | Some(match (home, toolchain) {
|
217 |
| - (Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain), |
218 |
| - _ => |
219 |
| - option_env!("RUST_SYSROOT") |
220 |
| - .expect( |
| 222 | + (Some(home), Some(toolchain)) => { |
| 223 | + // Check that at runtime, we are still in this toolchain. |
| 224 | + let toolchain_runtime = |
| 225 | + env::var_os("RUSTUP_TOOLCHAIN").or_else(|| env::var_os("MULTIRUST_TOOLCHAIN")); |
| 226 | + if !matches!(toolchain_runtime, Some(r) if r == toolchain) { |
| 227 | + show_error(format!( |
| 228 | + "This Miri got built with local toolchain `{toolchain}`, but now is being run under a different toolchain. \n\ |
| 229 | + Make sure to run Miri in the toolchain it got built with, e.g. via `cargo +{toolchain} miri`." |
| 230 | + )); |
| 231 | + } |
| 232 | + |
| 233 | + format!("{}/toolchains/{}", home, toolchain) |
| 234 | + } |
| 235 | + _ => option_env!("RUST_SYSROOT") |
| 236 | + .unwrap_or_else(|| { |
| 237 | + show_error(format!( |
221 | 238 | "To build Miri without rustup, set the `RUST_SYSROOT` env var at build time",
|
222 |
| - ) |
223 |
| - .to_owned(), |
| 239 | + )) |
| 240 | + }) |
| 241 | + .to_owned(), |
224 | 242 | })
|
225 | 243 | }
|
226 | 244 |
|
|
0 commit comments