@@ -679,15 +679,11 @@ impl Config {
679679 . unwrap_or_else ( || vec ! [ host_target] ) ;
680680
681681 let llvm_assertions = llvm_assertions_. unwrap_or ( false ) ;
682-
683682 let mut target_config = HashMap :: new ( ) ;
684- let mut download_rustc_commit = None ;
685- let mut llvm_from_ci = false ;
686683 let mut channel = "dev" . to_string ( ) ;
687684 let mut out = flags_build_dir
688685 . or ( build_build_dir. map ( PathBuf :: from) )
689686 . unwrap_or_else ( || PathBuf :: from ( "build" ) ) ;
690- let mut rust_info = GitInfo :: Absent ;
691687
692688 if cfg ! ( test) {
693689 // Use the build directory of the original x.py invocation, so that we can set `initial_rustc` properly.
@@ -730,16 +726,11 @@ impl Config {
730726 ) ;
731727 }
732728
733- let mut dwn_ctx = DownloadContext {
729+ let dwn_ctx = DownloadContext {
734730 path_modification_cache : path_modification_cache. clone ( ) ,
735731 src : & src,
736- rust_info : rust_info. clone ( ) ,
737732 submodules : & build_submodules,
738- download_rustc_commit : download_rustc_commit. clone ( ) ,
739733 host_target,
740- llvm_from_ci,
741- target_config : target_config. clone ( ) ,
742- out : out. clone ( ) ,
743734 patch_binaries_for_nix : build_patch_binaries_for_nix,
744735 exec_ctx : & exec_ctx,
745736 stage0_metadata : & stage0_metadata,
@@ -749,7 +740,7 @@ impl Config {
749740 } ;
750741
751742 let initial_rustc = build_rustc. unwrap_or_else ( || {
752- download_beta_toolchain ( & dwn_ctx) ;
743+ download_beta_toolchain ( & dwn_ctx, & out ) ;
753744 out. join ( host_target) . join ( "stage0" ) . join ( "bin" ) . join ( exe ( "rustc" , host_target) )
754745 } ) ;
755746
@@ -763,15 +754,14 @@ impl Config {
763754 ) ) ;
764755
765756 let initial_cargo = build_cargo. unwrap_or_else ( || {
766- download_beta_toolchain ( & dwn_ctx) ;
757+ download_beta_toolchain ( & dwn_ctx, & out ) ;
767758 initial_sysroot. join ( "bin" ) . join ( exe ( "cargo" , host_target) )
768759 } ) ;
769760
770761 // NOTE: it's important this comes *after* we set `initial_rustc` just above.
771762 if exec_ctx. dry_run ( ) {
772763 out = out. join ( "tmp-dry-run" ) ;
773764 fs:: create_dir_all ( & out) . expect ( "Failed to create dry-run directory" ) ;
774- dwn_ctx. out = out. clone ( ) ;
775765 }
776766
777767 let file_content = t ! ( fs:: read_to_string( src. join( "src/ci/channel" ) ) ) ;
@@ -791,8 +781,7 @@ impl Config {
791781
792782 let omit_git_hash = rust_omit_git_hash. unwrap_or ( channel == "dev" ) ;
793783
794- rust_info = git_info ( & exec_ctx, omit_git_hash, & src) ;
795- dwn_ctx. rust_info = rust_info. clone ( ) ;
784+ let rust_info = git_info ( & exec_ctx, omit_git_hash, & src) ;
796785
797786 if !is_user_configured_rust_channel && rust_info. is_from_tarball ( ) {
798787 channel = ci_channel. into ( ) ;
@@ -823,9 +812,8 @@ impl Config {
823812 ) ;
824813 }
825814
826- download_rustc_commit =
827- download_ci_rustc_commit ( & dwn_ctx, rust_download_rustc, llvm_assertions) ;
828- dwn_ctx. download_rustc_commit = download_rustc_commit. clone ( ) ;
815+ let mut download_rustc_commit =
816+ download_ci_rustc_commit ( & dwn_ctx, & rust_info, rust_download_rustc, llvm_assertions) ;
829817
830818 if debug_assertions_requested && download_rustc_commit. is_some ( ) {
831819 eprintln ! (
@@ -834,7 +822,6 @@ impl Config {
834822 ) ;
835823 // We need to put this later down_ci_rustc_commit.
836824 download_rustc_commit = None ;
837- dwn_ctx. download_rustc_commit = None ;
838825 }
839826
840827 // We need to override `rust.channel` if it's manually specified when using the CI rustc.
@@ -847,9 +834,10 @@ impl Config {
847834 "WARNING: `rust.download-rustc` is enabled. The `rust.channel` option will be overridden by the CI rustc's channel."
848835 ) ;
849836
850- channel = read_file_by_commit ( & dwn_ctx, Path :: new ( "src/ci/channel" ) , commit)
851- . trim ( )
852- . to_owned ( ) ;
837+ channel =
838+ read_file_by_commit ( & dwn_ctx, & rust_info, Path :: new ( "src/ci/channel" ) , commit)
839+ . trim ( )
840+ . to_owned ( ) ;
853841 }
854842
855843 if let Some ( t) = toml. target {
@@ -911,11 +899,15 @@ impl Config {
911899
912900 target_config. insert ( TargetSelection :: from_user ( & triple) , target) ;
913901 }
914- dwn_ctx. target_config = target_config. clone ( ) ;
915902 }
916903
917- llvm_from_ci = parse_download_ci_llvm ( & dwn_ctx, llvm_download_ci_llvm, llvm_assertions) ;
918- dwn_ctx. llvm_from_ci = llvm_from_ci;
904+ let llvm_from_ci = parse_download_ci_llvm (
905+ & dwn_ctx,
906+ & rust_info,
907+ & download_rustc_commit,
908+ llvm_download_ci_llvm,
909+ llvm_assertions,
910+ ) ;
919911
920912 // We make `x86_64-unknown-linux-gnu` use the self-contained linker by default, so we will
921913 // build our internal lld and use it as the default linker, by setting the `rust.lld` config
@@ -976,18 +968,16 @@ impl Config {
976968
977969 if llvm_from_ci {
978970 let triple = & host_target. triple ;
979- let ci_llvm_bin = ci_llvm_root ( & dwn_ctx) . join ( "bin" ) ;
971+ let ci_llvm_bin = ci_llvm_root ( & dwn_ctx, llvm_from_ci , & out ) . join ( "bin" ) ;
980972 let build_target =
981973 target_config. entry ( host_target) . or_insert_with ( || Target :: from_triple ( triple) ) ;
982- dwn_ctx. target_config . entry ( host_target) . or_insert_with ( || Target :: from_triple ( triple) ) ;
983-
984974 check_ci_llvm ! ( build_target. llvm_config) ;
985975 check_ci_llvm ! ( build_target. llvm_filecheck) ;
986976 build_target. llvm_config = Some ( ci_llvm_bin. join ( exe ( "llvm-config" , host_target) ) ) ;
987977 build_target. llvm_filecheck = Some ( ci_llvm_bin. join ( exe ( "FileCheck" , host_target) ) ) ;
988978 }
989979
990- let initial_rustfmt = build_rustfmt. or_else ( || maybe_download_rustfmt ( & dwn_ctx) ) ;
980+ let initial_rustfmt = build_rustfmt. or_else ( || maybe_download_rustfmt ( & dwn_ctx, & out ) ) ;
991981
992982 if matches ! ( rust_lld_mode. unwrap_or_default( ) , LldMode :: SelfContained )
993983 && !lld_enabled
@@ -998,7 +988,7 @@ impl Config {
998988 ) ;
999989 }
1000990
1001- if lld_enabled && is_system_llvm ( & dwn_ctx, host_target) {
991+ if lld_enabled && is_system_llvm ( & dwn_ctx, & target_config , llvm_from_ci , host_target) {
1002992 panic ! ( "Cannot enable LLD with `rust.lld = true` when using external llvm-config." ) ;
1003993 }
1004994
@@ -1392,7 +1382,7 @@ impl Config {
13921382 /// Returns the content of the given file at a specific commit.
13931383 pub ( crate ) fn read_file_by_commit ( & self , file : & Path , commit : & str ) -> String {
13941384 let dwn_ctx = DownloadContext :: from ( self ) ;
1395- read_file_by_commit ( dwn_ctx, file, commit)
1385+ read_file_by_commit ( dwn_ctx, & self . rust_info , file, commit)
13961386 }
13971387
13981388 /// Bootstrap embeds a version number into the name of shared libraries it uploads in CI.
@@ -1464,7 +1454,7 @@ impl Config {
14641454 /// The absolute path to the downloaded LLVM artifacts.
14651455 pub ( crate ) fn ci_llvm_root ( & self ) -> PathBuf {
14661456 let dwn_ctx = DownloadContext :: from ( self ) ;
1467- ci_llvm_root ( dwn_ctx)
1457+ ci_llvm_root ( dwn_ctx, self . llvm_from_ci , & self . out )
14681458 }
14691459
14701460 /// Directory where the extracted `rustc-dev` component is stored.
@@ -1628,7 +1618,7 @@ impl Config {
16281618 ) ]
16291619 pub ( crate ) fn update_submodule ( & self , relative_path : & str ) {
16301620 let dwn_ctx = DownloadContext :: from ( self ) ;
1631- update_submodule ( dwn_ctx, relative_path) ;
1621+ update_submodule ( dwn_ctx, & self . rust_info , relative_path) ;
16321622 }
16331623
16341624 /// Returns true if any of the `paths` have been modified locally.
@@ -1744,7 +1734,7 @@ impl Config {
17441734 /// NOTE: this is not the same as `!is_rust_llvm` when `llvm_has_patches` is set.
17451735 pub fn is_system_llvm ( & self , target : TargetSelection ) -> bool {
17461736 let dwn_ctx = DownloadContext :: from ( self ) ;
1747- is_system_llvm ( dwn_ctx, target)
1737+ is_system_llvm ( dwn_ctx, & self . target_config , self . llvm_from_ci , target)
17481738 }
17491739
17501740 /// Returns `true` if this is our custom, patched, version of LLVM.
@@ -2038,6 +2028,7 @@ pub fn check_stage0_version(
20382028
20392029pub fn download_ci_rustc_commit < ' a > (
20402030 dwn_ctx : impl AsRef < DownloadContext < ' a > > ,
2031+ rust_info : & channel:: GitInfo ,
20412032 download_rustc : Option < StringOrBool > ,
20422033 llvm_assertions : bool ,
20432034) -> Option < String > {
@@ -2057,7 +2048,7 @@ pub fn download_ci_rustc_commit<'a>(
20572048 None | Some ( StringOrBool :: Bool ( false ) ) => return None ,
20582049 Some ( StringOrBool :: Bool ( true ) ) => false ,
20592050 Some ( StringOrBool :: String ( s) ) if s == "if-unchanged" => {
2060- if !dwn_ctx . rust_info . is_managed_git_subrepository ( ) {
2051+ if !rust_info. is_managed_git_subrepository ( ) {
20612052 println ! (
20622053 "ERROR: `download-rustc=if-unchanged` is only compatible with Git managed sources."
20632054 ) ;
@@ -2071,7 +2062,7 @@ pub fn download_ci_rustc_commit<'a>(
20712062 }
20722063 } ;
20732064
2074- let commit = if dwn_ctx . rust_info . is_managed_git_subrepository ( ) {
2065+ let commit = if rust_info. is_managed_git_subrepository ( ) {
20752066 // Look for a version to compare to based on the current commit.
20762067 // Only commits merged by bors will have CI artifacts.
20772068 let freshness = check_path_modifications_ ( dwn_ctx, RUSTC_IF_UNCHANGED_ALLOWED_PATHS ) ;
@@ -2145,6 +2136,8 @@ pub fn git_config(stage0_metadata: &build_helper::stage0_parser::Stage0) -> GitC
21452136
21462137pub fn parse_download_ci_llvm < ' a > (
21472138 dwn_ctx : impl AsRef < DownloadContext < ' a > > ,
2139+ rust_info : & channel:: GitInfo ,
2140+ download_rustc_commit : & Option < String > ,
21482141 download_ci_llvm : Option < StringOrBool > ,
21492142 asserts : bool ,
21502143) -> bool {
@@ -2160,15 +2153,15 @@ pub fn parse_download_ci_llvm<'a>(
21602153 let download_ci_llvm = download_ci_llvm. unwrap_or ( default) ;
21612154
21622155 let if_unchanged = || {
2163- if dwn_ctx . rust_info . is_from_tarball ( ) {
2156+ if rust_info. is_from_tarball ( ) {
21642157 // Git is needed for running "if-unchanged" logic.
21652158 println ! ( "ERROR: 'if-unchanged' is only compatible with Git managed sources." ) ;
21662159 crate :: exit!( 1 ) ;
21672160 }
21682161
21692162 // Fetching the LLVM submodule is unnecessary for self-tests.
21702163 #[ cfg( not( test) ) ]
2171- update_submodule ( dwn_ctx, "src/llvm-project" ) ;
2164+ update_submodule ( dwn_ctx, rust_info , "src/llvm-project" ) ;
21722165
21732166 // Check for untracked changes in `src/llvm-project` and other important places.
21742167 let has_changes = has_changes_from_upstream ( dwn_ctx, LLVM_INVALIDATION_PATHS ) ;
@@ -2183,7 +2176,7 @@ pub fn parse_download_ci_llvm<'a>(
21832176
21842177 match download_ci_llvm {
21852178 StringOrBool :: Bool ( b) => {
2186- if !b && dwn_ctx . download_rustc_commit . is_some ( ) {
2179+ if !b && download_rustc_commit. is_some ( ) {
21872180 panic ! (
21882181 "`llvm.download-ci-llvm` cannot be set to `false` if `rust.download-rustc` is set to `true` or `if-unchanged`."
21892182 ) ;
@@ -2226,9 +2219,13 @@ pub fn has_changes_from_upstream<'a>(
22262219 fields( relative_path = ?relative_path) ,
22272220 ) ,
22282221) ]
2229- pub ( crate ) fn update_submodule < ' a > ( dwn_ctx : impl AsRef < DownloadContext < ' a > > , relative_path : & str ) {
2222+ pub ( crate ) fn update_submodule < ' a > (
2223+ dwn_ctx : impl AsRef < DownloadContext < ' a > > ,
2224+ rust_info : & channel:: GitInfo ,
2225+ relative_path : & str ,
2226+ ) {
22302227 let dwn_ctx = dwn_ctx. as_ref ( ) ;
2231- if dwn_ctx . rust_info . is_from_tarball ( ) || !submodules_ ( dwn_ctx. submodules , & dwn_ctx . rust_info ) {
2228+ if rust_info. is_from_tarball ( ) || !submodules_ ( dwn_ctx. submodules , rust_info) {
22322229 return ;
22332230 }
22342231
@@ -2357,12 +2354,14 @@ pub fn submodules_(submodules: &Option<bool>, rust_info: &channel::GitInfo) -> b
23572354/// NOTE: this is not the same as `!is_rust_llvm` when `llvm_has_patches` is set.
23582355pub fn is_system_llvm < ' a > (
23592356 dwn_ctx : impl AsRef < DownloadContext < ' a > > ,
2357+ target_config : & HashMap < TargetSelection , Target > ,
2358+ llvm_from_ci : bool ,
23602359 target : TargetSelection ,
23612360) -> bool {
23622361 let dwn_ctx = dwn_ctx. as_ref ( ) ;
2363- match dwn_ctx . target_config . get ( & target) {
2362+ match target_config. get ( & target) {
23642363 Some ( Target { llvm_config : Some ( _) , .. } ) => {
2365- let ci_llvm = dwn_ctx . llvm_from_ci && is_host_target ( & dwn_ctx. host_target , & target) ;
2364+ let ci_llvm = llvm_from_ci && is_host_target ( & dwn_ctx. host_target , & target) ;
23662365 !ci_llvm
23672366 }
23682367 // We're building from the in-tree src/llvm-project sources.
@@ -2375,21 +2374,26 @@ pub fn is_host_target(host_target: &TargetSelection, target: &TargetSelection) -
23752374 host_target == target
23762375}
23772376
2378- pub ( crate ) fn ci_llvm_root < ' a > ( dwn_ctx : impl AsRef < DownloadContext < ' a > > ) -> PathBuf {
2377+ pub ( crate ) fn ci_llvm_root < ' a > (
2378+ dwn_ctx : impl AsRef < DownloadContext < ' a > > ,
2379+ llvm_from_ci : bool ,
2380+ out : & Path ,
2381+ ) -> PathBuf {
23792382 let dwn_ctx = dwn_ctx. as_ref ( ) ;
2380- assert ! ( dwn_ctx . llvm_from_ci) ;
2381- dwn_ctx . out . join ( dwn_ctx. host_target ) . join ( "ci-llvm" )
2383+ assert ! ( llvm_from_ci) ;
2384+ out. join ( dwn_ctx. host_target ) . join ( "ci-llvm" )
23822385}
23832386
23842387/// Returns the content of the given file at a specific commit.
23852388pub ( crate ) fn read_file_by_commit < ' a > (
23862389 dwn_ctx : impl AsRef < DownloadContext < ' a > > ,
2390+ rust_info : & channel:: GitInfo ,
23872391 file : & Path ,
23882392 commit : & str ,
23892393) -> String {
23902394 let dwn_ctx = dwn_ctx. as_ref ( ) ;
23912395 assert ! (
2392- dwn_ctx . rust_info. is_managed_git_subrepository( ) ,
2396+ rust_info. is_managed_git_subrepository( ) ,
23932397 "`Config::read_file_by_commit` is not supported in non-git sources."
23942398 ) ;
23952399
0 commit comments