@@ -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 ) ;
@@ -838,12 +840,15 @@ impl Config {
838840 set ( & mut config. missing_tools , t. missing_tools ) ;
839841 }
840842
843+ // Cargo does not provide a RUSTFMT environment variable, so we
844+ // synthesize it manually. Note that we also later check the config.toml
845+ // and set this to that path if necessary.
846+ let rustfmt = config. initial_rustc . with_file_name ( exe ( "rustfmt" , config. build ) ) ;
847+ config. initial_rustfmt = if rustfmt. exists ( ) { Some ( rustfmt) } else { None } ;
848+
841849 // Now that we've reached the end of our configuration, infer the
842850 // default values for all options that we haven't otherwise stored yet.
843851
844- set ( & mut config. initial_rustc , build. rustc . map ( PathBuf :: from) ) ;
845- set ( & mut config. initial_cargo , build. cargo . map ( PathBuf :: from) ) ;
846-
847852 config. llvm_skip_rebuild = llvm_skip_rebuild. unwrap_or ( false ) ;
848853
849854 let default = false ;
0 commit comments