@@ -20,6 +20,7 @@ Subcommands:
2020 test, t Run tests
2121 nextest Run tests with nextest (requires cargo-nextest installed)
2222 setup Only perform automatic setup, but without asking questions (for getting a proper libstd)
23+ clean Clean the Miri cache & target directory
2324
2425The cargo options are exactly the same as for `cargo run` and `cargo test`, respectively.
2526
@@ -74,14 +75,15 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
7475 // We cannot know which of those flags take arguments and which do not,
7576 // so we cannot detect subcommands later.
7677 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` )" ) ;
7879 } ;
7980 let subcommand = match & * subcommand {
8081 "setup" => MiriCommand :: Setup ,
8182 "test" | "t" | "run" | "r" | "nextest" => MiriCommand :: Forward ( subcommand) ,
83+ "clean" => MiriCommand :: Clean ,
8284 _ =>
8385 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`."
8587 ) ,
8688 } ;
8789 let verbose = num_arg_flag ( "-v" ) ;
@@ -93,6 +95,16 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
9395 let target = get_arg_flag_value ( "--target" ) ;
9496 let target = target. as_ref ( ) . unwrap_or ( host) ;
9597
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+
96108 // We always setup.
97109 let miri_sysroot = setup ( & subcommand, target, & rustc_version, verbose) ;
98110
@@ -110,6 +122,7 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
110122 let cargo_cmd = match subcommand {
111123 MiriCommand :: Forward ( s) => s,
112124 MiriCommand :: Setup => return , // `cargo miri setup` stops here.
125+ MiriCommand :: Clean => unreachable ! ( ) ,
113126 } ;
114127 let metadata = get_cargo_metadata ( ) ;
115128 let mut cmd = cargo ( ) ;
@@ -142,11 +155,7 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
142155 . arg ( format ! ( "target.'cfg(all())'.runner=[{cargo_miri_path_for_toml}, 'runner']" ) ) ;
143156
144157 // 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) ;
150159 cmd. arg ( "--target-dir" ) . arg ( target_dir) ;
151160
152161 // *After* we set all the flags that need setting, forward everything else. Make sure to skip
0 commit comments