Skip to content

Commit 56250cc

Browse files
hyd-devteryror
andcommitted
Extract --extern filenames patching code to forward_patched_extern_arg()
Co-authored-by: Tristan Dannenberg <dtristan@hotmail.de>
1 parent c3f7069 commit 56250cc

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

cargo-miri/bin.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,18 @@ fn get_arg_flag_value(name: &str) -> Option<String> {
143143
ArgFlagValueIter::new(name).next()
144144
}
145145

146+
fn forward_patched_extern_arg(args: &mut impl Iterator<Item = String>, cmd: &mut Command) {
147+
cmd.arg("--extern"); // always forward flag, but adjust filename:
148+
let path = args.next().expect("`--extern` should be followed by a filename");
149+
if let Some(lib) = path.strip_suffix(".rlib") {
150+
// If this is an rlib, make it an rmeta.
151+
cmd.arg(format!("{}.rmeta", lib));
152+
} else {
153+
// Some other extern file (e.g. a `.so`). Forward unchanged.
154+
cmd.arg(path);
155+
}
156+
}
157+
146158
/// Returns the path to the `miri` binary
147159
fn find_miri() -> PathBuf {
148160
if let Some(path) = env::var_os("MIRI") {
@@ -734,21 +746,11 @@ fn phase_cargo_runner(binary: &Path, binary_args: env::Args) {
734746
// but when we run here, cargo does not interpret the JSON any more. `--json`
735747
// then also nees to be dropped.
736748
let mut args = info.args.into_iter();
737-
let extern_flag = "--extern";
738749
let error_format_flag = "--error-format";
739750
let json_flag = "--json";
740751
while let Some(arg) = args.next() {
741-
if arg == extern_flag {
742-
cmd.arg(extern_flag); // always forward flag, but adjust filename
743-
// `--extern` is always passed as a separate argument by cargo.
744-
let next_arg = args.next().expect("`--extern` should be followed by a filename");
745-
if let Some(next_lib) = next_arg.strip_suffix(".rlib") {
746-
// If this is an rlib, make it an rmeta.
747-
cmd.arg(format!("{}.rmeta", next_lib));
748-
} else {
749-
// Some other extern file (e.g., a `.so`). Forward unchanged.
750-
cmd.arg(next_arg);
751-
}
752+
if arg == "--extern" {
753+
forward_patched_extern_arg(&mut args, &mut cmd);
752754
} else if arg.starts_with(error_format_flag) {
753755
let suffix = &arg[error_format_flag.len()..];
754756
assert!(suffix.starts_with('='));

0 commit comments

Comments
 (0)