@@ -117,7 +117,7 @@ impl Display for DebuginfoLevel {
117
117
/// 2) MSVC
118
118
/// - Self-contained: `-Clinker=<path to rust-lld>`
119
119
/// - External: `-Clinker=lld`
120
- #[ derive( Default , Copy , Clone ) ]
120
+ #[ derive( Copy , Clone , Default , PartialEq ) ]
121
121
pub enum LldMode {
122
122
/// Do not use LLD
123
123
#[ default]
@@ -1593,24 +1593,6 @@ impl Config {
1593
1593
let mut is_user_configured_rust_channel = false ;
1594
1594
1595
1595
if let Some ( rust) = toml. rust {
1596
- if let Some ( commit) = config. download_ci_rustc_commit ( rust. download_rustc . clone ( ) ) {
1597
- // Primarily used by CI runners to avoid handling download-rustc incompatible
1598
- // options one by one on shell scripts.
1599
- let disable_ci_rustc_if_incompatible =
1600
- env:: var_os ( "DISABLE_CI_RUSTC_IF_INCOMPATIBLE" )
1601
- . is_some_and ( |s| s == "1" || s == "true" ) ;
1602
-
1603
- if let Err ( e) = check_incompatible_options_for_ci_rustc ( & rust) {
1604
- if disable_ci_rustc_if_incompatible {
1605
- config. download_rustc_commit = None ;
1606
- } else {
1607
- panic ! ( "{}" , e) ;
1608
- }
1609
- } else {
1610
- config. download_rustc_commit = Some ( commit) ;
1611
- }
1612
- }
1613
-
1614
1596
let Rust {
1615
1597
optimize : optimize_toml,
1616
1598
debug : debug_toml,
@@ -1658,7 +1640,7 @@ impl Config {
1658
1640
new_symbol_mangling,
1659
1641
profile_generate,
1660
1642
profile_use,
1661
- download_rustc : _ ,
1643
+ download_rustc,
1662
1644
lto,
1663
1645
validate_mir_opts,
1664
1646
frame_pointers,
@@ -1670,6 +1652,8 @@ impl Config {
1670
1652
is_user_configured_rust_channel = channel. is_some ( ) ;
1671
1653
set ( & mut config. channel , channel. clone ( ) ) ;
1672
1654
1655
+ config. download_rustc_commit = config. download_ci_rustc_commit ( download_rustc) ;
1656
+
1673
1657
debug = debug_toml;
1674
1658
debug_assertions = debug_assertions_toml;
1675
1659
debug_assertions_std = debug_assertions_std_toml;
@@ -2347,6 +2331,29 @@ impl Config {
2347
2331
None => None ,
2348
2332
Some ( commit) => {
2349
2333
self . download_ci_rustc ( commit) ;
2334
+
2335
+ let builder_config_path =
2336
+ self . out . join ( self . build . triple ) . join ( "ci-rustc/builder-config" ) ;
2337
+ let ci_config_toml = Self :: get_toml ( & builder_config_path) ;
2338
+ let current_config_toml = Self :: get_toml ( self . config . as_ref ( ) . unwrap ( ) ) ;
2339
+
2340
+ // Check the config compatibility
2341
+ let res = check_incompatible_options_for_ci_rustc (
2342
+ current_config_toml,
2343
+ ci_config_toml,
2344
+ ) ;
2345
+
2346
+ let disable_ci_rustc_if_incompatible =
2347
+ env:: var_os ( "DISABLE_CI_RUSTC_IF_INCOMPATIBLE" )
2348
+ . is_some_and ( |s| s == "1" || s == "true" ) ;
2349
+
2350
+ if disable_ci_rustc_if_incompatible && res. is_err ( ) {
2351
+ println ! ( "WARNING: download-rustc is disabled with `DISABLE_CI_RUSTC_IF_INCOMPATIBLE` env." ) ;
2352
+ return None ;
2353
+ }
2354
+
2355
+ res. unwrap ( ) ;
2356
+
2350
2357
Some ( commit. clone ( ) )
2351
2358
}
2352
2359
} )
@@ -2664,31 +2671,44 @@ impl Config {
2664
2671
}
2665
2672
}
2666
2673
2667
- /// Checks the CI rustc incompatible options by destructuring the `Rust` instance
2668
- /// and makes sure that no rust options from config.toml are missed.
2669
- fn check_incompatible_options_for_ci_rustc ( rust : & Rust ) -> Result < ( ) , String > {
2674
+ /// Compares the current Rust options against those in the CI rustc builder and detects any incompatible options.
2675
+ /// It does this by destructuring the `Rust` instance to make sure every `Rust` field is covered and not missing.
2676
+ fn check_incompatible_options_for_ci_rustc (
2677
+ current_config_toml : TomlConfig ,
2678
+ ci_config_toml : TomlConfig ,
2679
+ ) -> Result < ( ) , String > {
2670
2680
macro_rules! err {
2671
- ( $name: expr) => {
2672
- if $name. is_some( ) {
2681
+ ( $current: expr, $expected: expr) => {
2682
+ if let Some ( current) = $current {
2683
+ if Some ( current) != $expected {
2673
2684
return Err ( format!(
2674
2685
"ERROR: Setting `rust.{}` is incompatible with `rust.download-rustc`." ,
2675
- stringify!( $name ) . replace( "_" , "-" )
2686
+ stringify!( $expected ) . replace( "_" , "-" )
2676
2687
) ) ;
2677
- }
2688
+ } ;
2689
+ } ;
2678
2690
} ;
2679
2691
}
2680
2692
2681
2693
macro_rules! warn {
2682
- ( $name: expr) => {
2683
- if $name. is_some( ) {
2694
+ ( $current: expr, $expected: expr) => {
2695
+ if let Some ( current) = $current {
2696
+ if Some ( current) != $expected {
2684
2697
println!(
2685
2698
"WARNING: `rust.{}` has no effect with `rust.download-rustc`." ,
2686
- stringify!( $name ) . replace( "_" , "-" )
2699
+ stringify!( $expected ) . replace( "_" , "-" )
2687
2700
) ;
2688
- }
2701
+ } ;
2702
+ } ;
2689
2703
} ;
2690
2704
}
2691
2705
2706
+ let ( Some ( current_rust_config) , Some ( ci_rust_config) ) =
2707
+ ( current_config_toml. rust , ci_config_toml. rust )
2708
+ else {
2709
+ return Ok ( ( ) ) ;
2710
+ } ;
2711
+
2692
2712
let Rust {
2693
2713
// Following options are the CI rustc incompatible ones.
2694
2714
optimize,
@@ -2746,30 +2766,31 @@ fn check_incompatible_options_for_ci_rustc(rust: &Rust) -> Result<(), String> {
2746
2766
download_rustc : _,
2747
2767
validate_mir_opts : _,
2748
2768
frame_pointers : _,
2749
- } = rust ;
2769
+ } = ci_rust_config ;
2750
2770
2751
2771
// There are two kinds of checks for CI rustc incompatible options:
2752
2772
// 1. Checking an option that may change the compiler behaviour/output.
2753
2773
// 2. Checking an option that have no effect on the compiler behaviour/output.
2754
2774
//
2755
2775
// If the option belongs to the first category, we call `err` macro for a hard error;
2756
2776
// otherwise, we just print a warning with `warn` macro.
2757
- err ! ( optimize) ;
2758
- err ! ( debug_logging) ;
2759
- err ! ( debuginfo_level_rustc) ;
2760
- err ! ( default_linker) ;
2761
- err ! ( rpath) ;
2762
- err ! ( strip) ;
2763
- err ! ( stack_protector) ;
2764
- err ! ( lld_mode) ;
2765
- err ! ( llvm_tools) ;
2766
- err ! ( llvm_bitcode_linker) ;
2767
- err ! ( jemalloc) ;
2768
- err ! ( lto) ;
2769
-
2770
- warn ! ( channel) ;
2771
- warn ! ( description) ;
2772
- warn ! ( incremental) ;
2777
+
2778
+ err ! ( current_rust_config. optimize, optimize) ;
2779
+ err ! ( current_rust_config. debug_logging, debug_logging) ;
2780
+ err ! ( current_rust_config. debuginfo_level_rustc, debuginfo_level_rustc) ;
2781
+ err ! ( current_rust_config. rpath, rpath) ;
2782
+ err ! ( current_rust_config. strip, strip) ;
2783
+ err ! ( current_rust_config. lld_mode, lld_mode) ;
2784
+ err ! ( current_rust_config. llvm_tools, llvm_tools) ;
2785
+ err ! ( current_rust_config. llvm_bitcode_linker, llvm_bitcode_linker) ;
2786
+ err ! ( current_rust_config. jemalloc, jemalloc) ;
2787
+ err ! ( current_rust_config. default_linker, default_linker) ;
2788
+ err ! ( current_rust_config. stack_protector, stack_protector) ;
2789
+ err ! ( current_rust_config. lto, lto) ;
2790
+
2791
+ warn ! ( current_rust_config. channel, channel) ;
2792
+ warn ! ( current_rust_config. description, description) ;
2793
+ warn ! ( current_rust_config. incremental, incremental) ;
2773
2794
2774
2795
Ok ( ( ) )
2775
2796
}
0 commit comments