@@ -35,6 +35,11 @@ The cargo options are exactly the same as for `cargo run` and `cargo test`, resp
35
35
Examples:
36
36
cargo miri run
37
37
cargo miri test -- test-suite-filter
38
+
39
+ cargo miri setup --print sysroot
40
+ This will print the path to the generated sysroot (and nothing else) on stdout.
41
+ stderr will still contain progress information about how the build is doing.
42
+
38
43
"# ;
39
44
40
45
#[ derive( Clone , Debug ) ]
@@ -361,17 +366,15 @@ fn write_to_file(filename: &Path, content: &str) {
361
366
/// done all this already.
362
367
fn setup ( subcommand : & MiriCommand ) {
363
368
let only_setup = matches ! ( subcommand, MiriCommand :: Setup ) ;
369
+ let ask_user = !only_setup;
370
+ let print_sysroot = only_setup && has_arg_flag ( "--print-sysroot" ) ; // whether we just print the sysroot path
364
371
if std:: env:: var_os ( "MIRI_SYSROOT" ) . is_some ( ) {
365
372
if only_setup {
366
373
println ! ( "WARNING: MIRI_SYSROOT already set, not doing anything." )
367
374
}
368
375
return ;
369
376
}
370
377
371
- // Subcommands other than `setup` will do a setup if necessary, but
372
- // interactively confirm first.
373
- let ask_user = !only_setup;
374
-
375
378
// First, we need xargo.
376
379
if xargo_version ( ) . map_or ( true , |v| v < XARGO_MIN_VERSION ) {
377
380
if std:: env:: var_os ( "XARGO_CHECK" ) . is_some ( ) {
@@ -507,8 +510,14 @@ path = "lib.rs"
507
510
command. env ( "RUSTFLAGS" , "-Cdebug-assertions=off -Coverflow-checks=on" ) ;
508
511
// Manage the output the user sees.
509
512
if only_setup {
513
+ // We want to be explicit.
510
514
eprintln ! ( "Preparing a sysroot for Miri..." ) ;
515
+ if print_sysroot {
516
+ // Be extra sure there is no noise on stdout.
517
+ command. stdout ( process:: Stdio :: null ( ) ) ;
518
+ }
511
519
} else {
520
+ // We want to be quiet, but still let the user know that something is happening.
512
521
eprint ! ( "Preparing a sysroot for Miri... " ) ;
513
522
command. stdout ( process:: Stdio :: null ( ) ) ;
514
523
command. stderr ( process:: Stdio :: null ( ) ) ;
@@ -523,22 +532,21 @@ path = "lib.rs"
523
532
) )
524
533
}
525
534
}
526
- if !only_setup {
527
- eprintln ! ( "done" ) ;
528
- }
529
535
530
536
// That should be it! But we need to figure out where xargo built stuff.
531
537
// Unfortunately, it puts things into a different directory when the
532
538
// architecture matches the host.
533
539
let sysroot = if target == & host { dir. join ( "HOST" ) } else { PathBuf :: from ( dir) } ;
534
540
std:: env:: set_var ( "MIRI_SYSROOT" , & sysroot) ; // pass the env var to the processes we spawn, which will turn it into "--sysroot" flags
535
541
// Figure out what to print.
536
- let print_sysroot = only_setup && has_arg_flag ( "--print-sysroot" ) ; // whether we just print the sysroot path
542
+ if only_setup {
543
+ eprintln ! ( "A sysroot for Miri is now available in `{}`." , sysroot. display( ) ) ;
544
+ } else {
545
+ eprintln ! ( "done" ) ;
546
+ }
537
547
if print_sysroot {
538
548
// Print just the sysroot and nothing else to stdout; this way we do not need any escaping.
539
549
println ! ( "{}" , sysroot. display( ) ) ;
540
- } else if only_setup {
541
- eprintln ! ( "A sysroot for Miri is now available in `{}`." , sysroot. display( ) ) ;
542
550
}
543
551
}
544
552
0 commit comments