@@ -23,7 +23,9 @@ const JOSH_PORT: &str = "42042";
23
23
24
24
impl MiriEnv {
25
25
/// Returns the location of the sysroot.
26
- fn build_miri_sysroot ( & mut self , quiet : bool ) -> Result < PathBuf > {
26
+ ///
27
+ /// If the target is None the sysroot will be built for the host machine.
28
+ fn build_miri_sysroot ( & mut self , quiet : bool , target : Option < & str > ) -> Result < PathBuf > {
27
29
if let Some ( miri_sysroot) = self . sh . var_os ( "MIRI_SYSROOT" ) {
28
30
// Sysroot already set, use that.
29
31
return Ok ( miri_sysroot. into ( ) ) ;
@@ -35,26 +37,27 @@ impl MiriEnv {
35
37
self . build ( path ! ( self . miri_dir / "Cargo.toml" ) , & [ ] , quiet) ?;
36
38
self . build ( & manifest_path, & [ ] , quiet) ?;
37
39
38
- let target = & match self . sh . var ( "MIRI_TEST_TARGET" ) {
39
- Ok ( target) => vec ! [ "--target" . into( ) , target] ,
40
- Err ( _) => vec ! [ ] ,
41
- } ;
40
+ let target_flag =
41
+ & if let Some ( target) = target { vec ! [ "--target" , target] } else { vec ! [ ] } ;
42
+
42
43
if !quiet {
43
- match self . sh . var ( "MIRI_TEST_TARGET" ) {
44
- Ok ( target) => eprintln ! ( "$ (building Miri sysroot for {target})" ) ,
45
- Err ( _) => eprintln ! ( "$ (building Miri sysroot)" ) ,
44
+ if let Some ( target) = target {
45
+ eprintln ! ( "$ (building Miri sysroot for {target})" ) ;
46
+ } else {
47
+ eprintln ! ( "$ (building Miri sysroot)" ) ;
46
48
}
47
49
}
50
+
48
51
let output = cmd ! ( self . sh,
49
52
"cargo +{toolchain} --quiet run {cargo_extra_flags...} --manifest-path {manifest_path} --
50
- miri setup --print-sysroot {target ...}"
53
+ miri setup --print-sysroot {target_flag ...}"
51
54
) . read ( ) ;
52
55
let Ok ( output) = output else {
53
56
// Run it again (without `--print-sysroot` or `--quiet`) so the user can see the error.
54
57
cmd ! (
55
58
self . sh,
56
59
"cargo +{toolchain} run {cargo_extra_flags...} --manifest-path {manifest_path} --
57
- miri setup {target ...}"
60
+ miri setup {target_flag ...}"
58
61
)
59
62
. run ( )
60
63
. with_context ( || "`cargo miri setup` failed" ) ?;
@@ -161,7 +164,7 @@ impl Command {
161
164
Command :: Install { flags } => Self :: install ( flags) ,
162
165
Command :: Build { flags } => Self :: build ( flags) ,
163
166
Command :: Check { flags } => Self :: check ( flags) ,
164
- Command :: Test { bless, flags } => Self :: test ( bless, flags) ,
167
+ Command :: Test { bless, flags, target } => Self :: test ( bless, flags, target ) ,
165
168
Command :: Run { dep, verbose, many_seeds, flags } =>
166
169
Self :: run ( dep, verbose, many_seeds, flags) ,
167
170
Command :: Fmt { flags } => Self :: fmt ( flags) ,
@@ -446,16 +449,23 @@ impl Command {
446
449
Ok ( ( ) )
447
450
}
448
451
449
- fn test ( bless : bool , flags : Vec < OsString > ) -> Result < ( ) > {
452
+ fn test ( bless : bool , flags : Vec < OsString > , target : Option < String > ) -> Result < ( ) > {
450
453
let mut e = MiriEnv :: new ( ) ?;
454
+
455
+ if let Some ( target) = target. as_deref ( ) {
456
+ // Tell the sysroot which target to test.
457
+ e. sh . set_var ( "MIRI_TEST_TARGET" , target) ;
458
+ }
459
+
451
460
// Prepare a sysroot.
452
- e. build_miri_sysroot ( /* quiet */ false ) ?;
461
+ e. build_miri_sysroot ( /* quiet */ false , target . as_deref ( ) ) ?;
453
462
454
463
// Then test, and let caller control flags.
455
464
// Only in root project as `cargo-miri` has no tests.
456
465
if bless {
457
466
e. sh . set_var ( "RUSTC_BLESS" , "Gesundheit" ) ;
458
467
}
468
+
459
469
e. test ( path ! ( e. miri_dir / "Cargo.toml" ) , & flags) ?;
460
470
Ok ( ( ) )
461
471
}
@@ -476,14 +486,24 @@ impl Command {
476
486
. take_while ( |arg| * arg != "--" )
477
487
. tuple_windows ( )
478
488
. find ( |( first, _) | * first == "--target" ) ;
479
- if let Some ( ( _, target) ) = target {
489
+
490
+ let target_triple = if let Some ( ( _, target) ) = target {
480
491
// Found it!
481
492
e. sh . set_var ( "MIRI_TEST_TARGET" , target) ;
493
+
494
+ let triple =
495
+ target. clone ( ) . into_string ( ) . map_err ( |_| anyhow ! ( "target triple is not UTF-8" ) ) ?;
496
+ Some ( triple)
482
497
} else if let Ok ( target) = std:: env:: var ( "MIRI_TEST_TARGET" ) {
483
498
// Convert `MIRI_TEST_TARGET` into `--target`.
484
499
flags. push ( "--target" . into ( ) ) ;
485
- flags. push ( target. into ( ) ) ;
486
- }
500
+ flags. push ( target. clone ( ) . into ( ) ) ;
501
+
502
+ Some ( target)
503
+ } else {
504
+ None
505
+ } ;
506
+
487
507
// Scan for "--edition", set one ourselves if that flag is not present.
488
508
let have_edition =
489
509
flags. iter ( ) . take_while ( |arg| * arg != "--" ) . any ( |arg| * arg == "--edition" ) ;
@@ -492,7 +512,8 @@ impl Command {
492
512
}
493
513
494
514
// Prepare a sysroot, and add it to the flags.
495
- let miri_sysroot = e. build_miri_sysroot ( /* quiet */ !verbose) ?;
515
+ let miri_sysroot =
516
+ e. build_miri_sysroot ( /* quiet */ !verbose, target_triple. as_deref ( ) ) ?;
496
517
flags. push ( "--sysroot" . into ( ) ) ;
497
518
flags. push ( miri_sysroot. into ( ) ) ;
498
519
0 commit comments