@@ -85,6 +85,7 @@ fn get_arg_flag_value(name: &str) -> Option<String> {
85
85
}
86
86
87
87
fn is_build_dep ( mut args : impl Iterator < Item = String > ) -> bool {
88
+ //eprintln!("Out dir: {:?}", std::env::var("OUT_DIR"));
88
89
args. any ( |arg| arg. starts_with ( "--emit=" ) && arg. contains ( "link" ) )
89
90
}
90
91
@@ -96,20 +97,26 @@ fn is_build_dep(mut args: impl Iterator<Item = String>) -> bool {
96
97
// not the wrapper is being invoked on the target crate.
97
98
// For now, this is the best we can do
98
99
fn is_target_crate ( is_build_script : bool ) -> bool {
100
+ //eprintln!("Args: {:?}", std::env::args().collect::<Vec<_>>());
101
+ let is_bin = get_arg_flag_value ( "--crate-type" ) . as_deref ( ) == Some ( "bin" ) ;
102
+ let is_test = std:: env:: args ( ) . find ( |arg| arg == "--test" ) . is_some ( ) ;
103
+ ( is_bin || is_test) && !is_build_script
99
104
// Cargo sets this to the directory containing the manifest of the crate
100
105
// the wrapper is being invoekd to compile. This should be unique
101
106
// across the entire build (except for build scripts, which we handle below).
102
107
// We cannot check the crate name, since this may not be unique
103
108
// (e.g. if the build contains multiple versions of the same crate,
104
109
// or the same crate from multiple sources)
105
- let manifest_dir = std:: env:: var ( "CARGO_MANIFEST_DIR" ) . ok ( ) ;
110
+ // let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").ok();
106
111
107
112
// The manifest directory for our target crate. This is set by `cargo-miri`
108
113
// (the original invoation by the user) by using `cargo_metadata` to locate
109
114
// the manifest.
110
- let expected_dir = std:: env:: var ( "MIRI_MAGIC_DIR" ) . expect ( "MIRI_MAGIC_DIR not set!" ) ;
115
+ // let expected_dir = std::env::var("MIRI_MAGIC_DIR").expect("MIRI_MAGIC_DIR not set!");
111
116
112
- manifest_dir == Some ( expected_dir) && !is_build_script
117
+ //manifest_dir == Some(expected_dir) && !is_build_script
118
+ //
119
+ //false
113
120
114
121
}
115
122
@@ -427,7 +434,7 @@ path = "lib.rs"
427
434
// architecture matches the host.
428
435
let is_host = match target {
429
436
None => true ,
430
- Some ( target) => target == rustc_version :: version_meta ( ) . unwrap ( ) . host ,
437
+ Some ( target) => target == host_triple ( ) ,
431
438
} ;
432
439
let sysroot = if is_host { dir. join ( "HOST" ) } else { PathBuf :: from ( dir) } ;
433
440
std:: env:: set_var ( "MIRI_SYSROOT" , & sysroot) ; // pass the env var to the processes we spawn, which will turn it into "--sysroot" flags
@@ -521,6 +528,17 @@ fn in_cargo_miri() {
521
528
// The remaining targets we do not even want to build.
522
529
_ => continue ,
523
530
}
531
+
532
+ let target = match get_arg_flag_value ( "--target" ) {
533
+ Some ( target) => target,
534
+ None => {
535
+ let target = host_triple ( ) ;
536
+ cmd. arg ( "--target" ) . arg ( & target) ;
537
+ target
538
+ }
539
+ } ;
540
+
541
+
524
542
// Add user-defined args until first `--`.
525
543
while let Some ( arg) = args. next ( ) {
526
544
if arg == "--" {
@@ -530,7 +548,8 @@ fn in_cargo_miri() {
530
548
}
531
549
532
550
let args_vec: Vec < String > = args. collect ( ) ;
533
- cmd. env ( "MIRI_MAGIC_DIR" , root_dir. clone ( ) ) ;
551
+ cmd. env ( "MIRI_MAGIC_TARGET" , target. clone ( ) ) ;
552
+ //cmd.env("MIRI_MAGIC_DIR", root_dir.clone());
534
553
cmd. env ( "MIRI_MAGIC_ARGS" , serde_json:: to_string ( & args_vec) . expect ( "failed to serialize args" ) ) ;
535
554
536
555
// Add `--` (to end the `cargo` flags), and then the user flags. We add markers around the
@@ -552,6 +571,10 @@ fn in_cargo_miri() {
552
571
}
553
572
}
554
573
574
+ fn host_triple ( ) -> String {
575
+ rustc_version:: version_meta ( ) . unwrap ( ) . host
576
+ }
577
+
555
578
fn inside_cargo_rustc ( ) {
556
579
let sysroot = std:: env:: var ( "MIRI_SYSROOT" ) . expect ( "The wrapper should have set MIRI_SYSROOT" ) ;
557
580
0 commit comments