@@ -442,8 +442,6 @@ impl Config {
442
442
exec_ctx. set_verbose ( flags_verbose) ;
443
443
exec_ctx. set_fail_fast ( flags_cmd. fail_fast ( ) ) ;
444
444
445
- config. exec_ctx = exec_ctx;
446
-
447
445
// Set flags.
448
446
config. paths = std:: mem:: take ( & mut flags_paths) ;
449
447
@@ -484,8 +482,52 @@ impl Config {
484
482
config. is_running_on_ci = flags_ci. unwrap_or ( CiEnv :: is_ci ( ) ) ;
485
483
config. skip_std_check_if_no_download_rustc = flags_skip_std_check_if_no_download_rustc;
486
484
487
- // Infer the rest of the configuration.
485
+ // Locate the configuration file using the following priority (first match wins):
486
+ // 1. `--config <path>` (explicit flag)
487
+ // 2. `RUST_BOOTSTRAP_CONFIG` environment variable
488
+ // 3. `./bootstrap.toml` (local file)
489
+ // 4. `<root>/bootstrap.toml`
490
+ // 5. `./config.toml` (fallback for backward compatibility)
491
+ // 6. `<root>/config.toml`
492
+ let toml_path = flags_config
493
+ . clone ( )
494
+ . or_else ( || env:: var_os ( "RUST_BOOTSTRAP_CONFIG" ) . map ( PathBuf :: from) ) ;
495
+ let using_default_path = toml_path. is_none ( ) ;
496
+ let mut toml_path = toml_path. unwrap_or_else ( || PathBuf :: from ( "bootstrap.toml" ) ) ;
497
+
498
+ if using_default_path && !toml_path. exists ( ) {
499
+ toml_path = config. src . join ( PathBuf :: from ( "bootstrap.toml" ) ) ;
500
+ if !toml_path. exists ( ) {
501
+ toml_path = PathBuf :: from ( "config.toml" ) ;
502
+ if !toml_path. exists ( ) {
503
+ toml_path = config. src . join ( PathBuf :: from ( "config.toml" ) ) ;
504
+ }
505
+ }
506
+ }
507
+
508
+ // Give a hard error if `--config` or `RUST_BOOTSTRAP_CONFIG` are set to a missing path,
509
+ // but not if `bootstrap.toml` hasn't been created.
510
+ let mut toml = if !using_default_path || toml_path. exists ( ) {
511
+ config. config = Some ( if cfg ! ( not( test) ) {
512
+ toml_path = toml_path. canonicalize ( ) . unwrap ( ) ;
513
+ toml_path. clone ( )
514
+ } else {
515
+ toml_path. clone ( )
516
+ } ) ;
517
+ get_toml ( & toml_path) . unwrap_or_else ( |e| {
518
+ eprintln ! ( "ERROR: Failed to parse '{}': {e}" , toml_path. display( ) ) ;
519
+ exit ! ( 2 ) ;
520
+ } )
521
+ } else {
522
+ config. config = None ;
523
+ TomlConfig :: default ( )
524
+ } ;
525
+
526
+ exec_ctx. set_cache_cmd ( toml. cache_cmd . unwrap_or_default ( ) ) ;
488
527
528
+ config. exec_ctx = exec_ctx;
529
+
530
+ // Infer the rest of the configuration.
489
531
if let Some ( src) = flags_src {
490
532
config. src = src
491
533
} else {
@@ -545,47 +587,6 @@ impl Config {
545
587
546
588
config. stage0_metadata = build_helper:: stage0_parser:: parse_stage0_file ( ) ;
547
589
548
- // Locate the configuration file using the following priority (first match wins):
549
- // 1. `--config <path>` (explicit flag)
550
- // 2. `RUST_BOOTSTRAP_CONFIG` environment variable
551
- // 3. `./bootstrap.toml` (local file)
552
- // 4. `<root>/bootstrap.toml`
553
- // 5. `./config.toml` (fallback for backward compatibility)
554
- // 6. `<root>/config.toml`
555
- let toml_path = flags_config
556
- . clone ( )
557
- . or_else ( || env:: var_os ( "RUST_BOOTSTRAP_CONFIG" ) . map ( PathBuf :: from) ) ;
558
- let using_default_path = toml_path. is_none ( ) ;
559
- let mut toml_path = toml_path. unwrap_or_else ( || PathBuf :: from ( "bootstrap.toml" ) ) ;
560
-
561
- if using_default_path && !toml_path. exists ( ) {
562
- toml_path = config. src . join ( PathBuf :: from ( "bootstrap.toml" ) ) ;
563
- if !toml_path. exists ( ) {
564
- toml_path = PathBuf :: from ( "config.toml" ) ;
565
- if !toml_path. exists ( ) {
566
- toml_path = config. src . join ( PathBuf :: from ( "config.toml" ) ) ;
567
- }
568
- }
569
- }
570
-
571
- // Give a hard error if `--config` or `RUST_BOOTSTRAP_CONFIG` are set to a missing path,
572
- // but not if `bootstrap.toml` hasn't been created.
573
- let mut toml = if !using_default_path || toml_path. exists ( ) {
574
- config. config = Some ( if cfg ! ( not( test) ) {
575
- toml_path = toml_path. canonicalize ( ) . unwrap ( ) ;
576
- toml_path. clone ( )
577
- } else {
578
- toml_path. clone ( )
579
- } ) ;
580
- get_toml ( & toml_path) . unwrap_or_else ( |e| {
581
- eprintln ! ( "ERROR: Failed to parse '{}': {e}" , toml_path. display( ) ) ;
582
- exit ! ( 2 ) ;
583
- } )
584
- } else {
585
- config. config = None ;
586
- TomlConfig :: default ( )
587
- } ;
588
-
589
590
if cfg ! ( test) {
590
591
// When configuring bootstrap for tests, make sure to set the rustc and Cargo to the
591
592
// same ones used to call the tests (if custom ones are not defined in the toml). If we
0 commit comments