diff --git a/cargo-miri/bin.rs b/cargo-miri/bin.rs index 5731a9a591f..72c873b229e 100644 --- a/cargo-miri/bin.rs +++ b/cargo-miri/bin.rs @@ -532,8 +532,7 @@ fn is_target_crate() -> bool { fn is_runnable_crate() -> bool { let is_bin = get_arg_flag_value("--crate-type").as_deref().unwrap_or("bin") == "bin"; let is_test = has_arg_flag("--test"); - let print = get_arg_flag_value("--print").is_some(); - (is_bin || is_test) && !print + is_bin || is_test } fn out_filename(prefix: &str, suffix: &str) -> PathBuf { @@ -552,8 +551,21 @@ fn out_filename(prefix: &str, suffix: &str) -> PathBuf { let verbose = std::env::var_os("MIRI_VERBOSE").is_some(); let target_crate = is_target_crate(); + let print = get_arg_flag_value("--print").is_some(); // whether this is cargo passing `--print` to get some infos - if target_crate && is_runnable_crate() { + // rlib and cdylib are just skipped, we cannot interpret them and do not need them + // for the rest of the build either. + match get_arg_flag_value("--crate-type").as_deref() { + Some("rlib") | Some("cdylib") => { + if verbose { + eprint!("[cargo-miri rustc] (rlib/cdylib skipped)"); + } + return; + } + _ => {}, + } + + if !print && target_crate && is_runnable_crate() { // This is the binary or test crate that we want to interpret under Miri. // But we cannot run it here, as cargo invoked us as a compiler -- our stdin and stdout are not // like we want them. @@ -577,7 +589,7 @@ fn out_filename(prefix: &str, suffix: &str) -> PathBuf { let mut emit_link_hack = false; // Arguments are treated very differently depending on whether this crate is // for interpretation by Miri, or for use by a build script / proc macro. - if target_crate { + if !print && target_crate { // Forward arguments, but remove "link" from "--emit" to make this a check-only build. let emit_flag = "--emit"; for arg in args { @@ -607,7 +619,7 @@ fn out_filename(prefix: &str, suffix: &str) -> PathBuf { cmd.arg("--sysroot"); cmd.arg(sysroot); } else { - // For host crates, just forward everything. + // For host crates or when we are printing, just forward everything. cmd.args(args); }