Skip to content

Commit

Permalink
Copy and paste the --extern flag patching
Browse files Browse the repository at this point in the history
  • Loading branch information
hyd-dev committed Feb 13, 2021
1 parent e09dce0 commit 12dcbad
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions cargo-miri/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ fn phase_cargo_miri(mut args: env::Args) {
exec(cmd)
}

fn phase_cargo_rustc(args: env::Args) {
fn phase_cargo_rustc(mut args: env::Args) {
/// Determines if we are being invoked (as rustc) to build a crate for
/// the "target" architecture, in contrast to the "host" architecture.
/// Host crates are for build scripts and proc macros and still need to
Expand Down Expand Up @@ -646,7 +646,8 @@ fn phase_cargo_rustc(args: env::Args) {
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 {
let extern_flag = "--extern";
while let Some(arg) = args.next() {
if arg.starts_with(emit_flag) {
// Patch this argument. First, extract its value.
let val = &arg[emit_flag.len()..];
Expand All @@ -662,6 +663,17 @@ fn phase_cargo_rustc(args: env::Args) {
}
}
cmd.arg(format!("{}={}", emit_flag, val.join(",")));
} else if arg == extern_flag {
cmd.arg(extern_flag); // always forward flag, but adjust filename
// `--extern` is always passed as a separate argument by cargo.
let next_arg = args.next().expect("`--extern` should be followed by a filename");
if let Some(next_lib) = next_arg.strip_suffix(".rlib") {
// If this is an rlib, make it an rmeta.
cmd.arg(format!("{}.rmeta", next_lib));
} else {
// Some other extern file (e.g., a `.so`). Forward unchanged.
cmd.arg(next_arg);
}
} else {
cmd.arg(arg);
}
Expand Down

0 comments on commit 12dcbad

Please sign in to comment.