@@ -38,7 +38,7 @@ enum MiriCommand {
38
38
}
39
39
40
40
/// The information to run a crate with the given environment.
41
- #[ derive( Serialize , Deserialize ) ]
41
+ #[ derive( Serialize , Deserialize , Clone ) ]
42
42
struct CrateRunEnv {
43
43
/// The command-line arguments.
44
44
args : Vec < String > ,
@@ -50,16 +50,7 @@ struct CrateRunEnv {
50
50
stdin : Vec < u8 > ,
51
51
}
52
52
53
- /// The information Miri needs to run a crate. Stored as JSON when the crate is "compiled".
54
- #[ derive( Serialize , Deserialize ) ]
55
- enum CrateRunInfo {
56
- /// Run it with the given environment.
57
- RunWith ( CrateRunEnv ) ,
58
- /// Skip it as Miri does not support interpreting such kind of crates.
59
- SkipProcMacroTest ,
60
- }
61
-
62
- impl CrateRunInfo {
53
+ impl CrateRunEnv {
63
54
/// Gather all the information we need.
64
55
fn collect ( args : env:: Args ) -> Self {
65
56
let args = args. collect ( ) ;
@@ -71,9 +62,20 @@ impl CrateRunInfo {
71
62
std:: io:: stdin ( ) . lock ( ) . read_to_end ( & mut stdin) . expect ( "cannot read stdin" ) ;
72
63
}
73
64
74
- Self :: RunWith ( CrateRunEnv { args, env, current_dir, stdin } )
65
+ CrateRunEnv { args, env, current_dir, stdin }
75
66
}
67
+ }
76
68
69
+ /// The information Miri needs to run a crate. Stored as JSON when the crate is "compiled".
70
+ #[ derive( Serialize , Deserialize ) ]
71
+ enum CrateRunInfo {
72
+ /// Run it with the given environment.
73
+ RunWith ( CrateRunEnv ) ,
74
+ /// Skip it as Miri does not support interpreting such kind of crates.
75
+ SkipProcMacroTest ,
76
+ }
77
+
78
+ impl CrateRunInfo {
77
79
fn store ( & self , filename : & Path ) {
78
80
let file = File :: create ( filename)
79
81
. unwrap_or_else ( |_| show_error ( format ! ( "cannot create `{}`" , filename. display( ) ) ) ) ;
@@ -644,7 +646,7 @@ fn phase_cargo_rustc(mut args: env::Args) {
644
646
let target_crate = is_target_crate ( ) ;
645
647
let print = get_arg_flag_value ( "--print" ) . is_some ( ) ; // whether this is cargo passing `--print` to get some infos
646
648
647
- let store_json = |info : & CrateRunInfo | {
649
+ let store_json = |info : CrateRunInfo | {
648
650
// Create a stub .d file to stop Cargo from "rebuilding" the crate:
649
651
// https://github.com/rust-lang/miri/issues/1724#issuecomment-787115693
650
652
// As we store a JSON file instead of building the crate here, an empty file is fine.
@@ -672,30 +674,24 @@ fn phase_cargo_rustc(mut args: env::Args) {
672
674
// like we want them.
673
675
// Instead of compiling, we write JSON into the output file with all the relevant command-line flags
674
676
// and environment variables; this is used when cargo calls us again in the CARGO_TARGET_RUNNER phase.
675
- let info = CrateRunInfo :: collect ( args) ;
676
- store_json ( & info) ;
677
+ let env = CrateRunEnv :: collect ( args) ;
677
678
678
679
// Rustdoc expects us to exit with an error code if the test is marked as `compile_fail`,
679
680
// just creating the JSON file is not enough: we need to detect syntax errors,
680
681
// so we need to run Miri with `MIRI_BE_RUSTC` for a check-only build.
681
682
if std:: env:: var_os ( "MIRI_CALLED_FROM_RUSTDOC" ) . is_some ( ) {
682
683
let mut cmd = miri ( ) ;
683
- let env = if let CrateRunInfo :: RunWith ( env) = info {
684
- env
685
- } else {
686
- return ;
687
- } ;
688
684
689
- // ensure --emit argument for a check-only build is present
685
+ // Ensure --emit argument for a check-only build is present.
690
686
if let Some ( i) = env. args . iter ( ) . position ( |arg| arg. starts_with ( "--emit=" ) ) {
691
- // We need to make sure we're not producing a binary that overwrites the JSON file.
692
- // rustdoc should only ever pass an --emit=metadata argument for tests marked as `no_run`:
687
+ // For `no_run` tests, rustdoc passes a `--emit` flag; make sure it has the right shape.
693
688
assert_eq ! ( env. args[ i] , "--emit=metadata" ) ;
694
689
} else {
695
- cmd. arg ( "--emit=dep-info,metadata" ) ;
690
+ // For all other kinds of tests, we can just add our flag.
691
+ cmd. arg ( "--emit=metadata" ) ;
696
692
}
697
693
698
- cmd. args ( env. args ) ;
694
+ cmd. args ( & env. args ) ;
699
695
cmd. env ( "MIRI_BE_RUSTC" , "1" ) ;
700
696
701
697
if verbose {
@@ -706,14 +702,16 @@ fn phase_cargo_rustc(mut args: env::Args) {
706
702
exec_with_pipe ( cmd, & env. stdin ) ;
707
703
}
708
704
705
+ store_json ( CrateRunInfo :: RunWith ( env) ) ;
706
+
709
707
return ;
710
708
}
711
709
712
710
if runnable_crate && ArgFlagValueIter :: new ( "--extern" ) . any ( |krate| krate == "proc_macro" ) {
713
711
// This is a "runnable" `proc-macro` crate (unit tests). We do not support
714
712
// interpreting that under Miri now, so we write a JSON file to (display a
715
713
// helpful message and) skip it in the runner phase.
716
- store_json ( & CrateRunInfo :: SkipProcMacroTest ) ;
714
+ store_json ( CrateRunInfo :: SkipProcMacroTest ) ;
717
715
return ;
718
716
}
719
717
0 commit comments