@@ -84,40 +84,31 @@ fn get_arg_flag_value(name: &str) -> Option<String> {
84
84
}
85
85
}
86
86
87
- fn is_build_dep ( mut args : impl Iterator < Item = String > ) -> bool {
88
- //eprintln!("Out dir: {:?}", std::env::var("OUT_DIR"));
89
- args. any ( |arg| arg. starts_with ( "--emit=" ) && arg. contains ( "link" ) )
87
+
88
+ /// Determines if we are being invoked (as rustc) to build a runnable
89
+ /// executable. We run "cargo check", so this should only happen when
90
+ /// we are trying to compile a build script or build script dependency,
91
+ /// which actually needs to be executed on the host platform.
92
+ ///
93
+ /// Currently, we detect this by checking for "--emit=link",
94
+ /// which indicates that Cargo instruced rustc to output
95
+ /// a native object.
96
+ fn is_build_dep ( ) -> bool {
97
+ std:: env:: args ( ) . any ( |arg| arg. starts_with ( "--emit=" ) && arg. contains ( "link" ) )
90
98
}
91
99
92
- // Returns whether or not Cargo invoked the wrapper (this binary) to compile
93
- // the final, target crate (either a test for 'cargo test', or a binary for 'cargo run')
94
- // Right now, this is an awful hack that checks several different pieces of information
95
- // to try to figure out if the crate being compiled is the right one.
96
- // Ideally, Cargo would set en environment variable indicating whether or
97
- // not the wrapper is being invoked on the target crate.
98
- // For now, this is the best we can do
100
+ /// Returns whether or not Cargo invoked the wrapper (this binary) to compile
101
+ /// the final, target crate (either a test for 'cargo test', or a binary for 'cargo run')
102
+ /// Cargo does not give us this information directly, so we need to check
103
+ /// various command-line flags.
99
104
fn is_target_crate ( is_build_script : bool ) -> bool {
100
- //eprintln!("Args: {:?}", std::env::args().collect::<Vec<_>>());
101
105
let is_bin = get_arg_flag_value ( "--crate-type" ) . as_deref ( ) == Some ( "bin" ) ;
102
106
let is_test = std:: env:: args ( ) . find ( |arg| arg == "--test" ) . is_some ( ) ;
103
- ( is_bin || is_test) && !is_build_script
104
- // Cargo sets this to the directory containing the manifest of the crate
105
- // the wrapper is being invoekd to compile. This should be unique
106
- // across the entire build (except for build scripts, which we handle below).
107
- // We cannot check the crate name, since this may not be unique
108
- // (e.g. if the build contains multiple versions of the same crate,
109
- // or the same crate from multiple sources)
110
- //let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").ok();
111
-
112
- // The manifest directory for our target crate. This is set by `cargo-miri`
113
- // (the original invoation by the user) by using `cargo_metadata` to locate
114
- // the manifest.
115
- //let expected_dir = std::env::var("MIRI_MAGIC_DIR").expect("MIRI_MAGIC_DIR not set!");
116
-
117
- //manifest_dir == Some(expected_dir) && !is_build_script
118
- //
119
- //false
120
107
108
+ // The final runnable (under Miri) crate will either be a binary crate
109
+ // or a test crate. We make sure to exclude build scripts here, since
110
+ // they are also build with "--crate-type bin"
111
+ ( is_bin || is_test) && !is_build_script
121
112
}
122
113
123
114
0 commit comments