This means the sysroot you are using was not compiled with Miri in mind. This
should never happen when you use `cargo miri` because that takes care of setting
-up the sysroot. If you are using `miri` (the Miri driver) directly, see
-[CONTRIBUTING.md](CONTRIBUTING.md) for how to use `./miri`.
+up the sysroot. If you are using `miri` (the Miri driver) directly, see the
+[contributors' guide](CONTRIBUTING.md) for how to use `./miri` to best do that.
## Miri `-Z` flags and environment variables
fn is_runnable_crate() -> bool {
let is_bin = get_arg_flag_value("--crate-type").as_deref() == Some("bin");
let is_test = has_arg_flag("--test");
-
- // The final runnable (under Miri) crate will either be a binary crate
- // or a test crate. We make sure to exclude build scripts here, since
- // they are also build with "--crate-type bin"
is_bin || is_test
}
cmd.args(std::env::args().skip(2)); // skip `cargo-miri rustc`
// We make sure to only specify our custom Xargo sysroot for target crates - that is,
- // crates which are ultimately going to get interpreted by Miri.
+ // crates which are needed for interpretation by Miri. proc-macros and build scripts
+ // should use the default sysroot.
if target_crate {
let sysroot =
env::var_os("MIRI_SYSROOT").expect("The wrapper should have set MIRI_SYSROOT");
// otherwise we want Miri to behave like rustc and build the crate as usual.
if target_crate && is_runnable_crate() {
// This is the binary or test crate that we want to interpret under Miri.
+ // (Testing `target_crate` is needed to exclude build scripts.)
// We deserialize the arguments that are meant for Miri from the special environment
// variable "MIRI_ARGS", and feed them to the 'miri' binary.
//
fn init_late_loggers(tcx: TyCtxt<'_>) {
// We initialize loggers right before we start evaluation. We overwrite the `RUSTC_LOG`
// env var if it is not set, control it based on `MIRI_LOG`.
- // (FIXE: use `var_os`, but then we need to manually concatenate instead of `format!`.)
+ // (FIXME: use `var_os`, but then we need to manually concatenate instead of `format!`.)
if let Ok(var) = env::var("MIRI_LOG") {
if env::var_os("RUSTC_LOG").is_none() {
// We try to be a bit clever here: if `MIRI_LOG` is just a single level
}
/// Execute a compiler with the given CLI arguments and callbacks.
-fn run_compiler(mut args: Vec<String>, callbacks: &mut (dyn rustc_driver::Callbacks + Send)) {
+fn run_compiler(mut args: Vec<String>, callbacks: &mut (dyn rustc_driver::Callbacks + Send)) -> ! {
// Make sure we use the right default sysroot. The default sysroot is wrong,
// because `get_or_default_sysroot` in `librustc_session` bases that on `current_exe`.
//
Ok(()) => rustc_driver::EXIT_SUCCESS,
Err(_) => rustc_driver::EXIT_FAILURE,
};
- std::process::exit(exit_code);
+ std::process::exit(exit_code)
}
fn main() {
rustc_driver::init_rustc_env_logger();
// We cannot use `rustc_driver::main` as we need to adjust the CLI arguments.
let mut callbacks = rustc_driver::TimePassesCallbacks::default();
- return run_compiler(env::args().collect(), &mut callbacks);
+ run_compiler(env::args().collect(), &mut callbacks)
}
// Init loggers the Miri way.
tracked_pointer_tag,
tracked_alloc_id,
};
- return run_compiler(rustc_args, &mut MiriCompilerCalls { miri_config });
+ run_compiler(rustc_args, &mut MiriCompilerCalls { miri_config })
}