@@ -291,7 +291,7 @@ struct Build {
291291 build_dir : Option < String > ,
292292 cargo : Option < String > ,
293293 rustc : Option < String > ,
294- rustfmt : Option < String > , /* allow bootstrap.py to use rustfmt key */
294+ rustfmt : Option < PathBuf > ,
295295 docs : Option < bool > ,
296296 compiler_docs : Option < bool > ,
297297 submodules : Option < bool > ,
@@ -493,9 +493,8 @@ impl Config {
493493 config. src = manifest_dir. parent ( ) . unwrap ( ) . parent ( ) . unwrap ( ) . to_owned ( ) ;
494494 config. out = Config :: path_from_python ( "BUILD_DIR" ) ;
495495
496- config. initial_rustc = Config :: path_from_python ( "RUSTC" ) ;
497- config. initial_cargo = Config :: path_from_python ( "CARGO" ) ;
498- config. initial_rustfmt = env:: var_os ( "RUSTFMT" ) . map ( Config :: normalize_python_path) ;
496+ config. initial_cargo = PathBuf :: from ( env ! ( "CARGO" ) ) ;
497+ config. initial_rustc = PathBuf :: from ( env ! ( "RUSTC" ) ) ;
499498
500499 config
501500 }
@@ -584,6 +583,9 @@ impl Config {
584583 set ( & mut config. full_bootstrap , build. full_bootstrap ) ;
585584 set ( & mut config. extended , build. extended ) ;
586585 config. tools = build. tools ;
586+ if build. rustfmt . is_some ( ) {
587+ config. initial_rustfmt = build. rustfmt ;
588+ }
587589 set ( & mut config. verbose , build. verbose ) ;
588590 set ( & mut config. sanitizers , build. sanitizers ) ;
589591 set ( & mut config. profiler , build. profiler ) ;
@@ -832,12 +834,15 @@ impl Config {
832834 set ( & mut config. missing_tools , t. missing_tools ) ;
833835 }
834836
837+ // Cargo does not provide a RUSTFMT environment variable, so we
838+ // synthesize it manually. Note that we also later check the config.toml
839+ // and set this to that path if necessary.
840+ let rustfmt = config. initial_rustc . with_file_name ( exe ( "rustfmt" , config. build ) ) ;
841+ config. initial_rustfmt = if rustfmt. exists ( ) { Some ( rustfmt) } else { None } ;
842+
835843 // Now that we've reached the end of our configuration, infer the
836844 // default values for all options that we haven't otherwise stored yet.
837845
838- set ( & mut config. initial_rustc , build. rustc . map ( PathBuf :: from) ) ;
839- set ( & mut config. initial_cargo , build. cargo . map ( PathBuf :: from) ) ;
840-
841846 config. llvm_skip_rebuild = llvm_skip_rebuild. unwrap_or ( false ) ;
842847
843848 let default = false ;
0 commit comments