Skip to content

fix for rlib/cdylib crates in dependency tree #1577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions cargo-miri/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,7 @@ fn phase_cargo_rustc(args: env::Args) {
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 {
Expand All @@ -552,8 +551,21 @@ fn phase_cargo_rustc(args: env::Args) {

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

// 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 target_crate && is_runnable_crate() {
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.
Expand All @@ -577,7 +589,7 @@ fn phase_cargo_rustc(args: env::Args) {
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 {
Expand Down Expand Up @@ -607,7 +619,7 @@ fn phase_cargo_rustc(args: env::Args) {
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);
}

Expand Down