Skip to content

Commit 4fa71ad

Browse files
authored
Merge pull request rust-lang#230 from dwrensha/cargo-miri
get cargo-miri to work
2 parents 8722ce8 + 7a755ce commit 4fa71ad

File tree

4 files changed

+35
-20
lines changed

4 files changed

+35
-20
lines changed

cargo-miri-test/Cargo.lock

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cargo-miri-test/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ version = "0.1.0"
44
authors = ["Oliver Schneider <[email protected]>"]
55

66
[dependencies]
7+
byteorder = "1.0"

cargo-miri-test/src/main.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
extern crate byteorder;
2+
3+
use byteorder::{BigEndian, ByteOrder};
4+
15
fn main() {
2-
assert_eq!(5, 5);
6+
let buf = &[1,2,3,4];
7+
let n = <BigEndian as ByteOrder>::read_u32(buf);
8+
assert_eq!(n, 0x01020304);
39
}

src/bin/cargo-miri.rs

+17-19
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ fn main() {
4444
return;
4545
}
4646

47-
let dep_path = std::env::current_dir().expect("current dir is not readable").join("target").join("debug").join("deps");
48-
4947
if let Some("miri") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) {
5048
// this arm is when `cargo miri` is called
5149

@@ -84,13 +82,11 @@ fn main() {
8482
let args = std::env::args().skip(skip);
8583
let kind = target.kind.get(0).expect("badly formatted cargo metadata: target::kind is an empty array");
8684
if test && kind == "test" {
87-
if let Err(code) = process(vec!["--test".to_string(), target.name].into_iter().chain(args),
88-
&dep_path) {
85+
if let Err(code) = process(vec!["--test".to_string(), target.name].into_iter().chain(args)) {
8986
std::process::exit(code);
9087
}
9188
} else if !test && kind == "bin" {
92-
if let Err(code) = process(vec!["--bin".to_string(), target.name].into_iter().chain(args),
93-
&dep_path) {
89+
if let Err(code) = process(vec!["--bin".to_string(), target.name].into_iter().chain(args)) {
9490
std::process::exit(code);
9591
}
9692
}
@@ -117,7 +113,7 @@ fn main() {
117113
.expect("need to specify RUST_SYSROOT env var during miri compilation, or use rustup or multirust")
118114
};
119115

120-
// this conditional check for the --sysroot flag is there so users can call `cargo-clippy` directly
116+
// this conditional check for the --sysroot flag is there so users can call `cargo-miri` directly
121117
// without having to pass --sysroot or anything
122118
let mut args: Vec<String> = if std::env::args().any(|s| s == "--sysroot") {
123119
std::env::args().skip(1).collect()
@@ -129,25 +125,29 @@ fn main() {
129125
// interpreted but not built
130126
let miri_enabled = std::env::args().any(|s| s == "-Zno-trans");
131127

132-
if miri_enabled {
133-
args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-miri""#.to_owned()]);
134-
}
128+
let mut command = if miri_enabled {
129+
let mut path = std::env::current_exe().expect("current executable path invalid");
130+
path.set_file_name("miri");
131+
Command::new(path)
132+
} else {
133+
Command::new("rustc")
134+
};
135135

136-
let mut path = std::env::current_exe().expect("current executable path invalid");
137-
path.set_file_name("miri");
136+
args.extend_from_slice(&["-Z".to_owned(), "always-encode-mir".to_owned()]);
137+
args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-miri""#.to_owned()]);
138138

139-
match Command::new(path).args(&args).status() {
139+
match command.args(&args).status() {
140140
Ok(exit) => if !exit.success() {
141141
std::process::exit(exit.code().unwrap_or(42));
142142
},
143-
Err(e) => panic!("error during miri run: {:?}", e),
143+
Err(ref e) if miri_enabled => panic!("error during miri run: {:?}", e),
144+
Err(ref e) => panic!("error during rustc call: {:?}", e),
144145
}
145146
}
146147
}
147148

148-
fn process<P, I>(old_args: I, dep_path: P) -> Result<(), i32>
149-
where P: AsRef<Path>,
150-
I: Iterator<Item = String>
149+
fn process<I>(old_args: I) -> Result<(), i32>
150+
where I: Iterator<Item = String>
151151
{
152152
let mut args = vec!["rustc".to_owned()];
153153

@@ -159,8 +159,6 @@ fn process<P, I>(old_args: I, dep_path: P) -> Result<(), i32>
159159
if !found_dashes {
160160
args.push("--".to_owned());
161161
}
162-
args.push("-L".to_owned());
163-
args.push(dep_path.as_ref().to_string_lossy().into_owned());
164162
args.push("-Zno-trans".to_owned());
165163
args.push("--cfg".to_owned());
166164
args.push(r#"feature="cargo-miri""#.to_owned());

0 commit comments

Comments
 (0)