@@ -190,17 +190,28 @@ path = "lib.rs"
190190 "# ) . unwrap ( ) ;
191191 File :: create ( dir. join ( "lib.rs" ) ) . unwrap ( ) ;
192192 // Run xargo
193- if !Command :: new ( "xargo" ) . arg ( "build" ) . arg ( "-q" )
193+ let target = get_arg_flag_value ( "--target" ) ;
194+ let mut command = Command :: new ( "xargo" ) ;
195+ command. arg ( "build" ) . arg ( "-q" )
194196 . current_dir ( & dir)
195197 . env ( "RUSTFLAGS" , miri:: miri_default_args ( ) . join ( " " ) )
196- . env ( "XARGO_HOME" , dir. to_str ( ) . unwrap ( ) )
197- . status ( ) . unwrap ( ) . success ( )
198+ . env ( "XARGO_HOME" , dir. to_str ( ) . unwrap ( ) ) ;
199+ if let Some ( ref target) = target {
200+ command. arg ( "--target" ) . arg ( & target) ;
201+ }
202+ if !command. status ( ) . unwrap ( ) . success ( )
198203 {
199204 show_error ( format ! ( "Failed to run xargo" ) ) ;
200205 }
201206
202- // That should be it!
203- let sysroot = dir. join ( "HOST" ) ;
207+ // That should be it! But we need to figure out where xargo built stuff.
208+ // Unfortunately, it puts things into a different directory when the
209+ // architecture matches the host.
210+ let is_host = match target {
211+ None => true ,
212+ Some ( target) => target == rustc_version:: version_meta ( ) . unwrap ( ) . host ,
213+ } ;
214+ let sysroot = if is_host { dir. join ( "HOST" ) } else { PathBuf :: from ( dir) } ;
204215 std:: env:: set_var ( "MIRI_SYSROOT" , & sysroot) ;
205216 if !ask_user {
206217 println ! ( "A libstd for miri is now available in `{}`" , sysroot. display( ) ) ;
0 commit comments