@@ -13,6 +13,7 @@ use std::str::FromStr;
13
13
use std:: sync:: OnceLock ;
14
14
use std:: { cmp, env, fs} ;
15
15
16
+ use build_helper:: ci:: CiEnv ;
16
17
use build_helper:: exit;
17
18
use build_helper:: git:: { GitConfig , get_closest_merge_commit, output_result} ;
18
19
use serde:: { Deserialize , Deserializer } ;
@@ -22,6 +23,7 @@ use crate::core::build_steps::compile::CODEGEN_BACKEND_PREFIX;
22
23
use crate :: core:: build_steps:: llvm;
23
24
pub use crate :: core:: config:: flags:: Subcommand ;
24
25
use crate :: core:: config:: flags:: { Color , Flags , Warnings } ;
26
+ use crate :: core:: download:: is_download_ci_available;
25
27
use crate :: utils:: cache:: { INTERNER , Interned } ;
26
28
use crate :: utils:: channel:: { self , GitInfo } ;
27
29
use crate :: utils:: helpers:: { self , exe, output, t} ;
@@ -1627,9 +1629,11 @@ impl Config {
1627
1629
config. mandir = mandir. map ( PathBuf :: from) ;
1628
1630
}
1629
1631
1632
+ config. llvm_assertions =
1633
+ toml. llvm . as_ref ( ) . map_or ( false , |llvm| llvm. assertions . unwrap_or ( false ) ) ;
1634
+
1630
1635
// Store off these values as options because if they're not provided
1631
1636
// we'll infer default values for them later
1632
- let mut llvm_assertions = None ;
1633
1637
let mut llvm_tests = None ;
1634
1638
let mut llvm_enzyme = None ;
1635
1639
let mut llvm_plugins = None ;
@@ -1712,7 +1716,8 @@ impl Config {
1712
1716
is_user_configured_rust_channel = channel. is_some ( ) ;
1713
1717
set ( & mut config. channel , channel. clone ( ) ) ;
1714
1718
1715
- config. download_rustc_commit = config. download_ci_rustc_commit ( download_rustc) ;
1719
+ config. download_rustc_commit =
1720
+ config. download_ci_rustc_commit ( download_rustc, config. llvm_assertions ) ;
1716
1721
1717
1722
debug = debug_toml;
1718
1723
debug_assertions = debug_assertions_toml;
@@ -1848,7 +1853,7 @@ impl Config {
1848
1853
optimize : optimize_toml,
1849
1854
thin_lto,
1850
1855
release_debuginfo,
1851
- assertions,
1856
+ assertions : _ ,
1852
1857
tests,
1853
1858
enzyme,
1854
1859
plugins,
@@ -1882,7 +1887,6 @@ impl Config {
1882
1887
Some ( StringOrBool :: Bool ( false ) ) | None => { }
1883
1888
}
1884
1889
set ( & mut config. ninja_in_file , ninja) ;
1885
- llvm_assertions = assertions;
1886
1890
llvm_tests = tests;
1887
1891
llvm_enzyme = enzyme;
1888
1892
llvm_plugins = plugins;
@@ -1911,8 +1915,8 @@ impl Config {
1911
1915
config. llvm_enable_warnings = enable_warnings. unwrap_or ( false ) ;
1912
1916
config. llvm_build_config = build_config. clone ( ) . unwrap_or ( Default :: default ( ) ) ;
1913
1917
1914
- let asserts = llvm_assertions . unwrap_or ( false ) ;
1915
- config . llvm_from_ci = config. parse_download_ci_llvm ( download_ci_llvm, asserts ) ;
1918
+ config . llvm_from_ci =
1919
+ config. parse_download_ci_llvm ( download_ci_llvm, config . llvm_assertions ) ;
1916
1920
1917
1921
if config. llvm_from_ci {
1918
1922
let warn = |option : & str | {
@@ -2080,7 +2084,6 @@ impl Config {
2080
2084
// Now that we've reached the end of our configuration, infer the
2081
2085
// default values for all options that we haven't otherwise stored yet.
2082
2086
2083
- config. llvm_assertions = llvm_assertions. unwrap_or ( false ) ;
2084
2087
config. llvm_tests = llvm_tests. unwrap_or ( false ) ;
2085
2088
config. llvm_enzyme = llvm_enzyme. unwrap_or ( false ) ;
2086
2089
config. llvm_plugins = llvm_plugins. unwrap_or ( false ) ;
@@ -2419,8 +2422,9 @@ impl Config {
2419
2422
ci_config_toml,
2420
2423
) ;
2421
2424
2422
- let disable_ci_rustc_if_incompatible =
2423
- env:: var_os ( "DISABLE_CI_RUSTC_IF_INCOMPATIBLE" )
2425
+ // Primarily used by CI runners to avoid handling download-rustc incompatible
2426
+ // options one by one on shell scripts.
2427
+ let disable_ci_rustc_if_incompatible = env:: var_os ( "DISABLE_CI_RUSTC_IF_INCOMPATIBLE" )
2424
2428
. is_some_and ( |s| s == "1" || s == "true" ) ;
2425
2429
2426
2430
if disable_ci_rustc_if_incompatible && res. is_err ( ) {
@@ -2711,7 +2715,15 @@ impl Config {
2711
2715
}
2712
2716
2713
2717
/// Returns the commit to download, or `None` if we shouldn't download CI artifacts.
2714
- fn download_ci_rustc_commit ( & self , download_rustc : Option < StringOrBool > ) -> Option < String > {
2718
+ fn download_ci_rustc_commit (
2719
+ & self ,
2720
+ download_rustc : Option < StringOrBool > ,
2721
+ llvm_assertions : bool ,
2722
+ ) -> Option < String > {
2723
+ if !is_download_ci_available ( & self . build . triple , llvm_assertions) {
2724
+ return None ;
2725
+ }
2726
+
2715
2727
// If `download-rustc` is not set, default to rebuilding.
2716
2728
let if_unchanged = match download_rustc {
2717
2729
None | Some ( StringOrBool :: Bool ( false ) ) => return None ,
@@ -2724,7 +2736,11 @@ impl Config {
2724
2736
2725
2737
// Look for a version to compare to based on the current commit.
2726
2738
// Only commits merged by bors will have CI artifacts.
2727
- let commit = get_closest_merge_commit ( Some ( & self . src ) , & self . git_config ( ) , & [ ] ) . unwrap ( ) ;
2739
+ let commit = get_closest_merge_commit ( Some ( & self . src ) , & self . git_config ( ) , & [
2740
+ self . src . join ( "compiler" ) ,
2741
+ self . src . join ( "library" ) ,
2742
+ ] )
2743
+ . unwrap ( ) ;
2728
2744
if commit. is_empty ( ) {
2729
2745
println ! ( "ERROR: could not find commit hash for downloading rustc" ) ;
2730
2746
println ! ( "HELP: maybe your repository history is too shallow?" ) ;
@@ -2733,6 +2749,19 @@ impl Config {
2733
2749
crate :: exit!( 1 ) ;
2734
2750
}
2735
2751
2752
+ if CiEnv :: is_ci ( ) && {
2753
+ let head_sha =
2754
+ output ( helpers:: git ( Some ( & self . src ) ) . arg ( "rev-parse" ) . arg ( "HEAD" ) . as_command_mut ( ) ) ;
2755
+ let head_sha = head_sha. trim ( ) ;
2756
+ commit == head_sha
2757
+ } {
2758
+ eprintln ! ( "CI rustc commit matches with HEAD and we are in CI." ) ;
2759
+ eprintln ! (
2760
+ "`rustc.download-ci` functionality will be skipped as artifacts are not available."
2761
+ ) ;
2762
+ return None ;
2763
+ }
2764
+
2736
2765
// Warn if there were changes to the compiler or standard library since the ancestor commit.
2737
2766
let has_changes = !t ! ( helpers:: git( Some ( & self . src) )
2738
2767
. args( [ "diff-index" , "--quiet" , & commit] )
0 commit comments