Skip to content

Commit 3cfaed2

Browse files
authored
Merge pull request #533 from RalfJung/cargo-miri-2018
port cargo-miri-test to 2018 edition, mostly to test that that works with cargo miri
2 parents adfede5 + f41decc commit 3cfaed2

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

cargo-miri-test/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "cargo-miri-test"
33
version = "0.1.0"
44
authors = ["Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>"]
5+
edition = "2018"
56

67
[dependencies]
7-
byteorder = "1.0"
8+
byteorder = "1.0"

cargo-miri-test/src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate byteorder;
2-
31
use byteorder::{BigEndian, ByteOrder};
42

53
fn main() {

src/bin/cargo-miri.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,15 @@ fn main() {
4646
}
4747

4848
if let Some("miri") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) {
49-
// this arm is when `cargo miri` is called
49+
// this arm is when `cargo miri` is called. We call `cargo rustc` for
50+
// each applicable target, but with the RUSTC env var set to the `cargo-miri`
51+
// binary so that we come back in the other branch, and dispatch
52+
// the invocations to rustc and miri, respectively.
5053

5154
let test = std::env::args().nth(2).map_or(false, |text| text == "test");
5255
let skip = if test { 3 } else { 2 };
5356

57+
// We need to get the manifest, and then the metadata, to enumerate targets.
5458
let manifest_path_arg = std::env::args().skip(skip).find(|val| {
5559
val.starts_with("--manifest-path=")
5660
});
@@ -92,6 +96,9 @@ fn main() {
9296
})
9397
.expect("could not find matching package");
9498
let package = metadata.packages.remove(package_index);
99+
100+
// Finally we got the metadata, iterate all targets and see for which ones
101+
// we do anything.
95102
for target in package.targets {
96103
let args = std::env::args().skip(skip);
97104
let kind = target.kind.get(0).expect(
@@ -139,7 +146,8 @@ fn main() {
139146
}
140147
}
141148
} else {
142-
// this arm is executed when cargo-miri runs `cargo rustc` with the `RUSTC` env var set to itself
149+
// This arm is executed when cargo-miri runs `cargo rustc` with the `RUSTC` env var set to itself:
150+
// Dependencies get dispatched to rustc, the final test/binary to miri.
143151

144152
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
145153
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));

0 commit comments

Comments
 (0)