@@ -20,6 +20,7 @@ Subcommands:
20
20
test, t Run tests
21
21
nextest Run tests with nextest (requires cargo-nextest installed)
22
22
setup Only perform automatic setup, but without asking questions (for getting a proper libstd)
23
+ clean Clean the Miri cache & target directory
23
24
24
25
The cargo options are exactly the same as for `cargo run` and `cargo test`, respectively.
25
26
@@ -74,14 +75,15 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
74
75
// We cannot know which of those flags take arguments and which do not,
75
76
// so we cannot detect subcommands later.
76
77
let Some ( subcommand) = args. next ( ) else {
77
- show_error ! ( "`cargo miri` needs to be called with a subcommand (`run`, `test`)" ) ;
78
+ show_error ! ( "`cargo miri` needs to be called with a subcommand (`run`, `test`, `clean` )" ) ;
78
79
} ;
79
80
let subcommand = match & * subcommand {
80
81
"setup" => MiriCommand :: Setup ,
81
82
"test" | "t" | "run" | "r" | "nextest" => MiriCommand :: Forward ( subcommand) ,
83
+ "clean" => MiriCommand :: Clean ,
82
84
_ =>
83
85
show_error ! (
84
- "`cargo miri` supports the following subcommands: `run`, `test`, `nextest`, and `setup`."
86
+ "`cargo miri` supports the following subcommands: `run`, `test`, `nextest`, `clean`, and `setup`."
85
87
) ,
86
88
} ;
87
89
let verbose = num_arg_flag ( "-v" ) ;
@@ -93,6 +95,16 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
93
95
let target = get_arg_flag_value ( "--target" ) ;
94
96
let target = target. as_ref ( ) . unwrap_or ( host) ;
95
97
98
+ // If cleaning the the target directory & sysroot cache,
99
+ // delete them then exit. There is no reason to setup a new
100
+ // sysroot in this execution.
101
+ if let MiriCommand :: Clean = subcommand {
102
+ let metadata = get_cargo_metadata ( ) ;
103
+ clean_target_dir ( & metadata) ;
104
+ clean_sysroot ( ) ;
105
+ return ;
106
+ }
107
+
96
108
// We always setup.
97
109
let miri_sysroot = setup ( & subcommand, target, & rustc_version, verbose) ;
98
110
@@ -110,6 +122,7 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
110
122
let cargo_cmd = match subcommand {
111
123
MiriCommand :: Forward ( s) => s,
112
124
MiriCommand :: Setup => return , // `cargo miri setup` stops here.
125
+ MiriCommand :: Clean => unreachable ! ( ) ,
113
126
} ;
114
127
let metadata = get_cargo_metadata ( ) ;
115
128
let mut cmd = cargo ( ) ;
@@ -142,11 +155,7 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
142
155
. arg ( format ! ( "target.'cfg(all())'.runner=[{cargo_miri_path_for_toml}, 'runner']" ) ) ;
143
156
144
157
// Set `--target-dir` to `miri` inside the original target directory.
145
- let mut target_dir = match get_arg_flag_value ( "--target-dir" ) {
146
- Some ( dir) => PathBuf :: from ( dir) ,
147
- None => metadata. target_directory . clone ( ) . into_std_path_buf ( ) ,
148
- } ;
149
- target_dir. push ( "miri" ) ;
158
+ let target_dir = get_target_dir ( & metadata) ;
150
159
cmd. arg ( "--target-dir" ) . arg ( target_dir) ;
151
160
152
161
// *After* we set all the flags that need setting, forward everything else. Make sure to skip
0 commit comments