@@ -14,6 +14,7 @@ use walkdir::WalkDir;
1414use xshell:: { Shell , cmd} ;
1515
1616use crate :: Command ;
17+ use crate :: config:: { Config , Toolchain } ;
1718use crate :: util:: * ;
1819
1920impl MiriEnv {
@@ -67,25 +68,19 @@ impl MiriEnv {
6768}
6869
6970impl Command {
70- fn auto_actions ( ) -> Result < ( ) > {
71+ fn auto_actions ( config : & Config ) -> Result < ( ) > {
7172 if env:: var_os ( "MIRI_AUTO_OPS" ) . is_some_and ( |x| x == "no" ) {
7273 return Ok ( ( ) ) ;
7374 }
7475
75- let miri_dir = miri_dir ( ) ?;
76- let auto_everything = path ! ( miri_dir / ".auto-everything" ) . exists ( ) ;
77- let auto_toolchain = auto_everything || path ! ( miri_dir / ".auto-toolchain" ) . exists ( ) ;
78- let auto_fmt = auto_everything || path ! ( miri_dir / ".auto-fmt" ) . exists ( ) ;
79- let auto_clippy = auto_everything || path ! ( miri_dir / ".auto-clippy" ) . exists ( ) ;
80-
8176 // `toolchain` goes first as it could affect the others
82- if auto_toolchain {
83- Self :: toolchain ( None , vec ! [ ] ) ?;
77+ if config . auto . toolchain {
78+ Self :: toolchain ( None , None , vec ! [ ] , config ) ?;
8479 }
85- if auto_fmt {
80+ if config . auto . fmt {
8681 Self :: fmt ( vec ! [ ] ) ?;
8782 }
88- if auto_clippy {
83+ if config . auto . clippy {
8984 // no features for auto actions, see
9085 // https://github.com/rust-lang/miri/pull/4396#discussion_r2149654845
9186 Self :: clippy ( vec ! [ ] , vec ! [ ] ) ?;
@@ -94,7 +89,7 @@ impl Command {
9489 Ok ( ( ) )
9590 }
9691
97- pub fn exec ( self ) -> Result < ( ) > {
92+ pub fn exec ( self , config : & Config ) -> Result < ( ) > {
9893 // First, and crucially only once, run the auto-actions -- but not for all commands.
9994 match & self {
10095 Command :: Install { .. }
@@ -104,7 +99,7 @@ impl Command {
10499 | Command :: Run { .. }
105100 | Command :: Fmt { .. }
106101 | Command :: Doc { .. }
107- | Command :: Clippy { .. } => Self :: auto_actions ( ) ?,
102+ | Command :: Clippy { .. } => Self :: auto_actions ( config ) ?,
108103 | Command :: Toolchain { .. } | Command :: Bench { .. } | Command :: Squash => { }
109104 }
110105 // Then run the actual command.
@@ -121,20 +116,29 @@ impl Command {
121116 Command :: Clippy { features, flags } => Self :: clippy ( features, flags) ,
122117 Command :: Bench { target, no_install, save_baseline, load_baseline, benches } =>
123118 Self :: bench ( target, no_install, save_baseline, load_baseline, benches) ,
124- Command :: Toolchain { commit, flags } => Self :: toolchain ( commit, flags) ,
119+ Command :: Toolchain { name, commit, flags } =>
120+ Self :: toolchain ( name, commit, flags, config) ,
125121 Command :: Squash => Self :: squash ( ) ,
126122 }
127123 }
128124
129- fn toolchain ( new_commit : Option < String > , flags : Vec < String > ) -> Result < ( ) > {
125+ fn toolchain (
126+ name : Option < String > ,
127+ new_commit : Option < String > ,
128+ flags : Vec < String > ,
129+ config : & Config ,
130+ ) -> Result < ( ) > {
131+ let name =
132+ name. as_deref ( ) . or ( config. toolchain . name . as_deref ( ) ) . unwrap_or ( Toolchain :: DEFAULT_NAME ) ;
133+
130134 let sh = Shell :: new ( ) ?;
131135 sh. change_dir ( miri_dir ( ) ?) ;
132136 let new_commit = match new_commit {
133137 Some ( c) => c,
134138 None => sh. read_file ( "rust-version" ) ?. trim ( ) . to_owned ( ) ,
135139 } ;
136140 let current_commit = {
137- let rustc_info = cmd ! ( sh, "rustc +miri --version -v" ) . read ( ) ;
141+ let rustc_info = cmd ! ( sh, "rustc +{name} --version -v" ) . read ( ) ;
138142 if let Ok ( rustc_info) = rustc_info {
139143 let metadata = rustc_version:: version_meta_for ( & rustc_info) ?;
140144 Some (
@@ -148,18 +152,25 @@ impl Command {
148152 } ;
149153 // Check if we already are at that commit.
150154 if current_commit. as_ref ( ) == Some ( & new_commit) {
151- if active_toolchain ( ) ? != "miri" {
152- cmd ! ( sh, "rustup override set miri" ) . run ( ) ?;
155+ // The toolchain is already at the right version. Make sure it is active in `miri_dir`.
156+ // Ignore errors from `active_toolchain`, the active toolchain might be uninstalled.
157+ if active_toolchain ( ) . ok ( ) . is_none_or ( |toolchain| toolchain != name) {
158+ cmd ! ( sh, "rustup override set {name}" ) . run ( ) ?;
153159 }
154160 return Ok ( ( ) ) ;
155161 }
156- // Install and setup new toolchain.
157- cmd ! ( sh, "rustup toolchain uninstall miri" ) . run ( ) ?;
158162
159- cmd ! ( sh, "rustup-toolchain-install-master -n miri -c cargo -c rust-src -c rustc-dev -c llvm-tools -c rustfmt -c clippy {flags...} -- {new_commit}" )
163+ // Compute rustup-toolchain-install-master flags for additional components.
164+ let components =
165+ config. toolchain . components . as_deref ( ) . unwrap_or ( Toolchain :: DEFAULT_COMPONENTS ) ;
166+ let component_flags = components. iter ( ) . flat_map ( |component| [ "-c" , component] ) ;
167+
168+ // Install and setup new toolchain.
169+ cmd ! ( sh, "rustup toolchain uninstall {name}" ) . run ( ) ?;
170+ cmd ! ( sh, "rustup-toolchain-install-master -n {name} -c cargo -c rust-src -c rustc-dev -c llvm-tools {component_flags...} {flags...} -- {new_commit}" )
160171 . run ( )
161172 . context ( "Failed to run rustup-toolchain-install-master. If it is not installed, run 'cargo install --locked rustup-toolchain-install-master'." ) ?;
162- cmd ! ( sh, "rustup override set miri " ) . run ( ) ?;
173+ cmd ! ( sh, "rustup override set {name} " ) . run ( ) ?;
163174 // Cleanup.
164175 cmd ! ( sh, "cargo clean" ) . run ( ) ?;
165176 // Call `cargo metadata` on the sources in case that changes the lockfile
0 commit comments