Merge pull request #230 from dwrensha/cargo-miri
get cargo-miri to work
This commit is contained in:
commit
4fa71ad3eb
4 changed files with 35 additions and 20 deletions
10
cargo-miri-test/Cargo.lock
generated
10
cargo-miri-test/Cargo.lock
generated
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -4,3 +4,4 @@ version = "0.1.0"
|
|||
authors = ["Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>"]
|
||||
|
||||
[dependencies]
|
||||
byteorder = "1.0"
|
||||
|
|
@ -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 = <BigEndian as ByteOrder>::read_u32(buf);
|
||||
assert_eq!(n, 0x01020304);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String> = 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<P, I>(old_args: I, dep_path: P) -> Result<(), i32>
|
||||
where P: AsRef<Path>,
|
||||
I: Iterator<Item = String>
|
||||
fn process<I>(old_args: I) -> Result<(), i32>
|
||||
where I: Iterator<Item = String>
|
||||
{
|
||||
let mut args = vec!["rustc".to_owned()];
|
||||
|
||||
|
|
@ -159,8 +159,6 @@ fn process<P, I>(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());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue