@@ -47,7 +47,7 @@ use crate::core::config::toml::rust::{
47
47
use crate :: core:: config:: toml:: target:: Target ;
48
48
use crate :: core:: config:: {
49
49
DebuginfoLevel , DryRun , GccCiMode , LlvmLibunwind , Merge , ReplaceOpt , RustcLto , SplitDebuginfo ,
50
- StringOrBool , set , threads_from_config,
50
+ StringOrBool , threads_from_config,
51
51
} ;
52
52
use crate :: core:: download:: {
53
53
DownloadContext , download_beta_toolchain, is_download_ci_available, maybe_download_rustfmt,
@@ -479,8 +479,6 @@ impl Config {
479
479
// Now load the TOML config, as soon as possible
480
480
let ( mut toml, toml_path) = load_toml_config ( & src, flags_config, & get_toml) ;
481
481
482
- let compile_time_deps = flags_compile_time_deps;
483
- let cmd = flags_cmd;
484
482
let is_running_on_ci = flags_ci. unwrap_or ( CiEnv :: is_ci ( ) ) ;
485
483
486
484
postprocess_toml ( & mut toml, & src, toml_path. clone ( ) , & exec_ctx, & flags_set, & get_toml) ;
@@ -654,6 +652,14 @@ impl Config {
654
652
655
653
let Gcc { download_ci_gcc : gcc_download_ci_gcc } = toml. gcc . unwrap_or_default ( ) ;
656
654
655
+ if rust_optimize_. as_ref ( ) . is_some_and ( |v| matches ! ( v, RustOptimize :: Bool ( false ) ) ) {
656
+ eprintln ! (
657
+ "WARNING: setting `optimize` to `false` is known to cause errors and \
658
+ should be considered unsupported. Refer to `bootstrap.example.toml` \
659
+ for more details."
660
+ ) ;
661
+ }
662
+
657
663
// Prefer CLI verbosity flags if set (`flags_verbose` > 0), otherwise take the value from
658
664
// TOML.
659
665
exec_ctx. set_verbosity ( cmp:: max ( build_verbose. unwrap_or_default ( ) as u8 , flags_verbose) ) ;
@@ -664,14 +670,6 @@ impl Config {
664
670
665
671
let path_modification_cache = Arc :: new ( Mutex :: new ( HashMap :: new ( ) ) ) ;
666
672
667
- if rust_optimize_. as_ref ( ) . is_some_and ( |v| matches ! ( v, RustOptimize :: Bool ( false ) ) ) {
668
- eprintln ! (
669
- "WARNING: setting `optimize` to `false` is known to cause errors and \
670
- should be considered unsupported. Refer to `bootstrap.example.toml` \
671
- for more details."
672
- ) ;
673
- }
674
-
675
673
let host_target = flags_build
676
674
. or ( build_build)
677
675
. map ( |build| TargetSelection :: from_user ( & build) )
@@ -690,7 +688,6 @@ impl Config {
690
688
let mut download_rustc_commit = None ;
691
689
let llvm_link_shared = Cell :: default ( ) ;
692
690
let mut llvm_from_ci = false ;
693
- let mut lld_enabled = false ;
694
691
let mut channel = "dev" . to_string ( ) ;
695
692
let mut out = flags_build_dir
696
693
. or ( build_build_dir. map ( PathBuf :: from) )
@@ -756,12 +753,10 @@ impl Config {
756
753
is_running_on_ci,
757
754
) ;
758
755
759
- let initial_rustc = if let Some ( rustc) = build_rustc {
760
- rustc
761
- } else {
756
+ let initial_rustc = build_rustc. unwrap_or_else ( || {
762
757
download_beta_toolchain ( & dwn_ctx) ;
763
758
out. join ( host_target) . join ( "stage0" ) . join ( "bin" ) . join ( exe ( "rustc" , host_target) )
764
- } ;
759
+ } ) ;
765
760
766
761
let initial_sysroot = t ! ( PathBuf :: from_str(
767
762
command( & initial_rustc)
@@ -772,20 +767,15 @@ impl Config {
772
767
. trim( )
773
768
) ) ;
774
769
775
- let initial_cargo_clippy = build_cargo_clippy;
776
-
777
- let initial_cargo = if let Some ( cargo) = build_cargo {
778
- cargo
779
- } else {
780
- download_beta_toolchain ( & dwn_ctx) ;
770
+ let initial_cargo = build_cargo. unwrap_or_else ( || {
771
+ download_beta_toolchain ( & mut dwn_ctx) ;
781
772
initial_sysroot. join ( "bin" ) . join ( exe ( "cargo" , host_target) )
782
- } ;
773
+ } ) ;
783
774
784
775
// NOTE: it's important this comes *after* we set `initial_rustc` just above.
785
776
if exec_ctx. dry_run ( ) {
786
- let dir = out. join ( "tmp-dry-run" ) ;
787
- t ! ( fs:: create_dir_all( & dir) ) ;
788
- out = dir;
777
+ out = out. join ( "tmp-dry-run" ) ;
778
+ fs:: create_dir_all ( & out) . expect ( "Failed to create dry-run directory" ) ;
789
779
dwn_ctx. out = out. clone ( ) ;
790
780
}
791
781
@@ -809,12 +799,6 @@ impl Config {
809
799
rust_info = git_info ( & exec_ctx, omit_git_hash, & src) ;
810
800
dwn_ctx. rust_info = rust_info. clone ( ) ;
811
801
812
- let vendor = build_vendor. unwrap_or (
813
- rust_info. is_from_tarball ( )
814
- && src. join ( "vendor" ) . exists ( )
815
- && src. join ( ".cargo/config.toml" ) . exists ( ) ,
816
- ) ;
817
-
818
802
if !is_user_configured_rust_channel && rust_info. is_from_tarball ( ) {
819
803
channel = ci_channel. into ( ) ;
820
804
}
@@ -858,6 +842,23 @@ impl Config {
858
842
dwn_ctx. download_rustc_commit = None ;
859
843
}
860
844
845
+ // We need to override `rust.channel` if it's manually specified when using the CI rustc.
846
+ // This is because if the compiler uses a different channel than the one specified in bootstrap.toml,
847
+ // tests may fail due to using a different channel than the one used by the compiler during tests.
848
+ if let Some ( commit) = & download_rustc_commit
849
+ && is_user_configured_rust_channel
850
+ {
851
+ println ! (
852
+ "WARNING: `rust.download-rustc` is enabled. The `rust.channel` option will be overridden by the CI rustc's channel."
853
+ ) ;
854
+
855
+ let channel_ = read_file_by_commit ( & dwn_ctx, Path :: new ( "src/ci/channel" ) , commit)
856
+ . trim ( )
857
+ . to_owned ( ) ;
858
+
859
+ channel = channel_;
860
+ }
861
+
861
862
if let Some ( t) = toml. target {
862
863
for ( triple, cfg) in t {
863
864
let mut target = Target :: from_triple ( & triple) ;
@@ -932,35 +933,15 @@ impl Config {
932
933
// thus, disabled
933
934
// - similarly, lld will not be built nor used by default when explicitly asked not to, e.g.
934
935
// when the config sets `rust.lld = false`
935
- if default_lld_opt_in_targets ( ) . contains ( & host_target. triple . to_string ( ) )
936
+ let lld_enabled = if default_lld_opt_in_targets ( ) . contains ( & host_target. triple . to_string ( ) )
936
937
&& hosts == [ host_target]
937
938
{
938
- let no_llvm_config = target_config
939
- . get ( & host_target)
940
- . is_none_or ( |target_config| target_config. llvm_config . is_none ( ) ) ;
941
- let enable_lld = llvm_from_ci || no_llvm_config;
942
- // Prefer the config setting in case an explicit opt-out is needed.
943
- lld_enabled = rust_lld_enabled. unwrap_or ( enable_lld) ;
939
+ let no_llvm_config =
940
+ target_config. get ( & host_target) . map_or ( true , |config| config. llvm_config . is_none ( ) ) ;
941
+ rust_lld_enabled. unwrap_or ( llvm_from_ci || no_llvm_config)
944
942
} else {
945
- set ( & mut lld_enabled, rust_lld_enabled) ;
946
- }
947
-
948
- // We need to override `rust.channel` if it's manually specified when using the CI rustc.
949
- // This is because if the compiler uses a different channel than the one specified in bootstrap.toml,
950
- // tests may fail due to using a different channel than the one used by the compiler during tests.
951
- if let Some ( commit) = & download_rustc_commit
952
- && is_user_configured_rust_channel
953
- {
954
- println ! (
955
- "WARNING: `rust.download-rustc` is enabled. The `rust.channel` option will be overridden by the CI rustc's channel."
956
- ) ;
957
-
958
- let channel_ = read_file_by_commit ( & dwn_ctx, Path :: new ( "src/ci/channel" ) , commit)
959
- . trim ( )
960
- . to_owned ( ) ;
961
-
962
- channel = channel_;
963
- }
943
+ rust_lld_enabled. unwrap_or ( false )
944
+ } ;
964
945
965
946
if let Some ( v) = llvm_link_shared_ {
966
947
llvm_link_shared. set ( Some ( v) ) ;
@@ -1024,8 +1005,7 @@ impl Config {
1024
1005
build_target. llvm_filecheck = Some ( ci_llvm_bin. join ( exe ( "FileCheck" , host_target) ) ) ;
1025
1006
}
1026
1007
1027
- let initial_rustfmt =
1028
- if let Some ( r) = build_rustfmt { Some ( r) } else { maybe_download_rustfmt ( & dwn_ctx) } ;
1008
+ let initial_rustfmt = build_rustfmt. or_else ( || maybe_download_rustfmt ( & dwn_ctx) ) ;
1029
1009
1030
1010
if matches ! ( rust_lld_mode. unwrap_or_default( ) , LldMode :: SelfContained )
1031
1011
&& !lld_enabled
@@ -1042,7 +1022,7 @@ impl Config {
1042
1022
1043
1023
let download_rustc = download_rustc_commit. is_some ( ) ;
1044
1024
1045
- let stage = match cmd {
1025
+ let stage = match flags_cmd {
1046
1026
Subcommand :: Check { .. } => flags_stage. or ( build_check_stage) . unwrap_or ( 1 ) ,
1047
1027
Subcommand :: Clippy { .. } | Subcommand :: Fix => {
1048
1028
flags_stage. or ( build_check_stage) . unwrap_or ( 1 )
@@ -1071,7 +1051,7 @@ impl Config {
1071
1051
} ;
1072
1052
1073
1053
// Now check that the selected stage makes sense, and if not, print a warning and end
1074
- match ( stage, & cmd ) {
1054
+ match ( stage, & flags_cmd ) {
1075
1055
( 0 , Subcommand :: Build ) => {
1076
1056
eprintln ! ( "ERROR: cannot build anything on stage 0. Use at least stage 1." ) ;
1077
1057
exit ! ( 1 ) ;
@@ -1087,7 +1067,7 @@ impl Config {
1087
1067
_ => { }
1088
1068
}
1089
1069
1090
- if compile_time_deps && !matches ! ( cmd , Subcommand :: Check { .. } ) {
1070
+ if flags_compile_time_deps && !matches ! ( flags_cmd , Subcommand :: Check { .. } ) {
1091
1071
eprintln ! (
1092
1072
"WARNING: Can't use --compile-time-deps with any subcommand other than check."
1093
1073
) ;
@@ -1097,7 +1077,7 @@ impl Config {
1097
1077
// CI should always run stage 2 builds, unless it specifically states otherwise
1098
1078
#[ cfg( not( test) ) ]
1099
1079
if flags_stage. is_none ( ) && is_running_on_ci {
1100
- match cmd {
1080
+ match flags_cmd {
1101
1081
Subcommand :: Test { .. }
1102
1082
| Subcommand :: Miri { .. }
1103
1083
| Subcommand :: Doc { .. }
@@ -1351,21 +1331,25 @@ impl Config {
1351
1331
llvm_thin_lto : llvm_thin_lto_. unwrap_or ( false ) ,
1352
1332
rustc_debug_assertions : rust_rustc_debug_assertions. unwrap_or ( rust_debug == Some ( true ) ) ,
1353
1333
lld_mode : rust_lld_mode. unwrap_or_default ( ) ,
1334
+ initial_cargo_clippy : build_cargo_clippy,
1335
+ vendor : build_vendor. unwrap_or (
1336
+ rust_info. is_from_tarball ( )
1337
+ && src. join ( "vendor" ) . exists ( )
1338
+ && src. join ( ".cargo/config.toml" ) . exists ( ) ,
1339
+ ) ,
1340
+ cmd : flags_cmd,
1354
1341
exec_ctx,
1355
1342
out,
1356
1343
rust_info,
1357
1344
initial_cargo,
1358
1345
initial_rustc,
1359
- initial_cargo_clippy,
1360
1346
initial_sysroot,
1361
1347
initial_rustfmt,
1362
1348
submodules,
1363
- vendor,
1364
1349
target_config,
1365
1350
omit_git_hash,
1366
1351
stage,
1367
1352
src,
1368
- cmd,
1369
1353
llvm_from_ci,
1370
1354
llvm_assertions,
1371
1355
lld_enabled,
0 commit comments