@@ -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