diff --git a/cargo-miri-test/Cargo.lock b/cargo-miri-test/Cargo.lock index a62bb86226cdb..8b2387fa64109 100644 --- a/cargo-miri-test/Cargo.lock +++ b/cargo-miri-test/Cargo.lock @@ -1,4 +1,14 @@ [root] name = "cargo-miri-test" version = "0.1.0" +dependencies = [ + "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] +[[package]] +name = "byteorder" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8" diff --git a/cargo-miri-test/Cargo.toml b/cargo-miri-test/Cargo.toml index 29886d99a394b..5fbe923f23d3b 100644 --- a/cargo-miri-test/Cargo.toml +++ b/cargo-miri-test/Cargo.toml @@ -4,3 +4,4 @@ version = "0.1.0" authors = ["Oliver Schneider "] [dependencies] +byteorder = "1.0" \ No newline at end of file diff --git a/cargo-miri-test/src/main.rs b/cargo-miri-test/src/main.rs index aa00ab84cb096..07b0e4cee4e5c 100644 --- a/cargo-miri-test/src/main.rs +++ b/cargo-miri-test/src/main.rs @@ -1,3 +1,9 @@ +extern crate byteorder; + +use byteorder::{BigEndian, ByteOrder}; + fn main() { - assert_eq!(5, 5); + let buf = &[1,2,3,4]; + let n = ::read_u32(buf); + assert_eq!(n, 0x01020304); } diff --git a/src/bin/cargo-miri.rs b/src/bin/cargo-miri.rs index f67bbd39a7482..6eff6650fa9c4 100644 --- a/src/bin/cargo-miri.rs +++ b/src/bin/cargo-miri.rs @@ -44,8 +44,6 @@ fn main() { return; } - let dep_path = std::env::current_dir().expect("current dir is not readable").join("target").join("debug").join("deps"); - if let Some("miri") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) { // this arm is when `cargo miri` is called @@ -84,13 +82,11 @@ fn main() { let args = std::env::args().skip(skip); let kind = target.kind.get(0).expect("badly formatted cargo metadata: target::kind is an empty array"); if test && kind == "test" { - if let Err(code) = process(vec!["--test".to_string(), target.name].into_iter().chain(args), - &dep_path) { + if let Err(code) = process(vec!["--test".to_string(), target.name].into_iter().chain(args)) { std::process::exit(code); } } else if !test && kind == "bin" { - if let Err(code) = process(vec!["--bin".to_string(), target.name].into_iter().chain(args), - &dep_path) { + if let Err(code) = process(vec!["--bin".to_string(), target.name].into_iter().chain(args)) { std::process::exit(code); } } @@ -117,7 +113,7 @@ fn main() { .expect("need to specify RUST_SYSROOT env var during miri compilation, or use rustup or multirust") }; - // this conditional check for the --sysroot flag is there so users can call `cargo-clippy` directly + // this conditional check for the --sysroot flag is there so users can call `cargo-miri` directly // without having to pass --sysroot or anything let mut args: Vec = if std::env::args().any(|s| s == "--sysroot") { std::env::args().skip(1).collect() @@ -129,25 +125,29 @@ fn main() { // interpreted but not built let miri_enabled = std::env::args().any(|s| s == "-Zno-trans"); - if miri_enabled { - args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-miri""#.to_owned()]); - } + let mut command = if miri_enabled { + let mut path = std::env::current_exe().expect("current executable path invalid"); + path.set_file_name("miri"); + Command::new(path) + } else { + Command::new("rustc") + }; - let mut path = std::env::current_exe().expect("current executable path invalid"); - path.set_file_name("miri"); + args.extend_from_slice(&["-Z".to_owned(), "always-encode-mir".to_owned()]); + args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-miri""#.to_owned()]); - match Command::new(path).args(&args).status() { + match command.args(&args).status() { Ok(exit) => if !exit.success() { std::process::exit(exit.code().unwrap_or(42)); }, - Err(e) => panic!("error during miri run: {:?}", e), + Err(ref e) if miri_enabled => panic!("error during miri run: {:?}", e), + Err(ref e) => panic!("error during rustc call: {:?}", e), } } } -fn process(old_args: I, dep_path: P) -> Result<(), i32> - where P: AsRef, - I: Iterator +fn process(old_args: I) -> Result<(), i32> + where I: Iterator { let mut args = vec!["rustc".to_owned()]; @@ -159,8 +159,6 @@ fn process(old_args: I, dep_path: P) -> Result<(), i32> if !found_dashes { args.push("--".to_owned()); } - args.push("-L".to_owned()); - args.push(dep_path.as_ref().to_string_lossy().into_owned()); args.push("-Zno-trans".to_owned()); args.push("--cfg".to_owned()); args.push(r#"feature="cargo-miri""#.to_owned());