Skip to content

Commit 5a6820e

Browse files
committed
make our filename handling work better across platforms
1 parent 868dcbb commit 5a6820e

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

cargo-miri/bin.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -485,14 +485,14 @@ fn phase_cargo_rustc(args: env::ArgsOs) {
485485
let filename = out_filename("", "");
486486

487487
if verbose {
488-
eprintln!("[cargo-miri rustc] writing run info to {:?}", filename.display());
488+
eprintln!("[cargo-miri rustc] writing run info to `{}`", filename.display());
489489
}
490490

491491
let file = File::create(&filename)
492-
.unwrap_or_else(|_| show_error(format!("Cannot create {:?}", filename.display())));
492+
.unwrap_or_else(|_| show_error(format!("Cannot create `{}`", filename.display())));
493493
let file = BufWriter::new(file);
494494
serde_json::ser::to_writer(file, &info)
495-
.unwrap_or_else(|_| show_error(format!("Cannot write to {:?}", filename.display())));
495+
.unwrap_or_else(|_| show_error(format!("Cannot write to `{}`", filename.display())));
496496
return;
497497
}
498498

@@ -501,7 +501,7 @@ fn phase_cargo_rustc(args: env::ArgsOs) {
501501
// Arguments are treated very differently depending on whether this crate is
502502
// for interpretation by Miri, or for use by a build script / proc macro.
503503
if target_crate {
504-
// Forward arguments, butremove "link" from "--emit" to make this a check-only build.
504+
// Forward arguments, but remove "link" from "--emit" to make this a check-only build.
505505
let emit_flag = "--emit";
506506
for arg in args {
507507
if arg.to_string_lossy().starts_with(emit_flag) {
@@ -547,21 +547,26 @@ fn phase_cargo_rustc(args: env::ArgsOs) {
547547

548548
// Create a stub .rlib file if "link" was requested by cargo.
549549
if emit_link_hack {
550-
// FIXME: is "lib" always right?
550+
// Some platforms prepend "lib", some do not... let's just create both files.
551551
let filename = out_filename("lib", ".rlib");
552552
File::create(filename).expect("Failed to create rlib file");
553+
let filename = out_filename("", ".rlib");
554+
File::create(filename).expect("Failed to create rlib file");
553555
}
554556
}
555557

556558
fn phase_cargo_runner(binary: &OsStr, binary_args: env::ArgsOs) {
557559
let verbose = std::env::var_os("MIRI_VERBOSE").is_some();
558560

559-
let file = File::open(binary)
561+
// Strip extension from binary name (Windows adds ".exe").
562+
let mut filename = PathBuf::from(binary);
563+
filename.set_extension("");
564+
let file = File::open(&filename)
560565
.unwrap_or_else(|_| show_error(format!("File {:?} not found or `cargo-miri` invoked incorrectly; please only invoke this binary through `cargo miri`", binary)));
561566
let file = BufReader::new(file);
562567
let info: CrateRunInfo = serde_json::from_reader(file)
563568
.unwrap_or_else(|_| show_error(format!("File {:?} does not contain valid JSON", binary)));
564-
fs::remove_file(binary)
569+
fs::remove_file(&filename)
565570
.unwrap_or_else(|_| show_error(format!("Unable to remove file {:?}", binary)));
566571

567572
let mut cmd = miri();

0 commit comments

Comments
 (0)