@@ -20,7 +20,6 @@ use crate::channel::GitInfo;
2020pub use crate :: flags:: Subcommand ;
2121use crate :: flags:: { Color , Flags } ;
2222use crate :: util:: { exe, output, program_out_of_date, t} ;
23- use crate :: RustfmtMetadata ;
2423use once_cell:: sync:: OnceCell ;
2524use serde:: { Deserialize , Deserializer } ;
2625
@@ -73,6 +72,7 @@ pub struct Config {
7372 pub test_compare_mode : bool ,
7473 pub color : Color ,
7574 pub patch_binaries_for_nix : bool ,
75+ pub stage0_metadata : Stage0Metadata ,
7676
7777 pub on_fail : Option < String > ,
7878 pub stage : u32 ,
@@ -720,6 +720,25 @@ define_config! {
720720 }
721721}
722722
723+ #[ derive( Default , Deserialize ) ]
724+ pub struct Stage0Metadata {
725+ pub config : Stage0Config ,
726+ pub checksums_sha256 : HashMap < String , String > ,
727+ pub rustfmt : Option < RustfmtMetadata > ,
728+ }
729+ #[ derive( Default , Deserialize ) ]
730+ pub struct Stage0Config {
731+ pub dist_server : String ,
732+ pub artifacts_server : String ,
733+ pub artifacts_with_llvm_assertions_server : String ,
734+ pub git_merge_commit_email : String ,
735+ }
736+ #[ derive( Default , Deserialize ) ]
737+ pub struct RustfmtMetadata {
738+ pub date : String ,
739+ pub version : String ,
740+ }
741+
723742impl Config {
724743 pub fn default_opts ( ) -> Config {
725744 let mut config = Config :: default ( ) ;
@@ -776,6 +795,9 @@ impl Config {
776795 config. llvm_profile_use = flags. llvm_profile_use ;
777796 config. llvm_profile_generate = flags. llvm_profile_generate ;
778797
798+ let stage0_json = t ! ( std:: fs:: read( & config. src. join( "src" ) . join( "stage0.json" ) ) ) ;
799+ config. stage0_metadata = t ! ( serde_json:: from_slice:: <Stage0Metadata >( & stage0_json) ) ;
800+
779801 #[ cfg( test) ]
780802 let get_toml = |_| TomlConfig :: default ( ) ;
781803 #[ cfg( not( test) ) ]
@@ -1103,8 +1125,11 @@ impl Config {
11031125 config. rust_codegen_units_std = rust. codegen_units_std . map ( threads_from_config) ;
11041126 config. rust_profile_use = flags. rust_profile_use . or ( rust. profile_use ) ;
11051127 config. rust_profile_generate = flags. rust_profile_generate . or ( rust. profile_generate ) ;
1106- config. download_rustc_commit =
1107- download_ci_rustc_commit ( rust. download_rustc , config. verbose > 0 ) ;
1128+ config. download_rustc_commit = download_ci_rustc_commit (
1129+ & config. stage0_metadata ,
1130+ rust. download_rustc ,
1131+ config. verbose > 0 ,
1132+ ) ;
11081133 } else {
11091134 config. rust_profile_use = flags. rust_profile_use ;
11101135 config. rust_profile_generate = flags. rust_profile_generate ;
@@ -1424,7 +1449,11 @@ fn threads_from_config(v: u32) -> u32 {
14241449}
14251450
14261451/// Returns the commit to download, or `None` if we shouldn't download CI artifacts.
1427- fn download_ci_rustc_commit ( download_rustc : Option < StringOrBool > , verbose : bool ) -> Option < String > {
1452+ fn download_ci_rustc_commit (
1453+ stage0_metadata : & Stage0Metadata ,
1454+ download_rustc : Option < StringOrBool > ,
1455+ verbose : bool ,
1456+ ) -> Option < String > {
14281457 // If `download-rustc` is not set, default to rebuilding.
14291458 let if_unchanged = match download_rustc {
14301459 None | Some ( StringOrBool :: Bool ( false ) ) => return None ,
@@ -1443,13 +1472,12 @@ fn download_ci_rustc_commit(download_rustc: Option<StringOrBool>, verbose: bool)
14431472
14441473 // Look for a version to compare to based on the current commit.
14451474 // Only commits merged by bors will have CI artifacts.
1446- let merge_base = output ( Command :: new ( "git" ) . args ( & [
1447- "rev-list" ,
1448- "--author=bors@rust-lang.org" ,
1449- "-n1" ,
1450- "--first-parent" ,
1451- "HEAD" ,
1452- ] ) ) ;
1475+ let merge_base = output (
1476+ Command :: new ( "git" )
1477+ . arg ( "rev-list" )
1478+ . arg ( format ! ( "--author={}" , stage0_metadata. config. git_merge_commit_email) )
1479+ . args ( & [ "-n1" , "--first-parent" , "HEAD" ] ) ,
1480+ ) ;
14531481 let commit = merge_base. trim_end ( ) ;
14541482 if commit. is_empty ( ) {
14551483 println ! ( "error: could not find commit hash for downloading rustc" ) ;
@@ -1484,7 +1512,7 @@ fn download_ci_rustc_commit(download_rustc: Option<StringOrBool>, verbose: bool)
14841512}
14851513
14861514fn maybe_download_rustfmt ( builder : & Builder < ' _ > ) -> Option < PathBuf > {
1487- let RustfmtMetadata { date, version } = builder. stage0_metadata . rustfmt . as_ref ( ) ?;
1515+ let RustfmtMetadata { date, version } = builder. config . stage0_metadata . rustfmt . as_ref ( ) ?;
14881516 let channel = format ! ( "{version}-{date}" ) ;
14891517
14901518 let host = builder. config . build ;
@@ -1568,13 +1596,13 @@ fn download_component(
15681596 let tarball = cache_dir. join ( & filename) ;
15691597 let ( base_url, url, should_verify) = match mode {
15701598 DownloadSource :: CI => (
1571- "https://ci-artifacts.rust-lang.org/rustc-builds" . to_string ( ) ,
1599+ builder . config . stage0_metadata . config . artifacts_server . clone ( ) ,
15721600 format ! ( "{key}/{filename}" ) ,
15731601 false ,
15741602 ) ,
15751603 DownloadSource :: Dist => {
15761604 let dist_server = env:: var ( "RUSTUP_DIST_SERVER" )
1577- . unwrap_or ( builder. stage0_metadata . dist_server . to_string ( ) ) ;
1605+ . unwrap_or ( builder. config . stage0_metadata . config . dist_server . to_string ( ) ) ;
15781606 // NOTE: make `dist` part of the URL because that's how it's stored in src/stage0.json
15791607 ( dist_server, format ! ( "dist/{key}/{filename}" ) , true )
15801608 }
@@ -1590,7 +1618,7 @@ fn download_component(
15901618 target at this time, see https://doc.rust-lang.org/nightly\
15911619 /rustc/platform-support.html for more information."
15921620 ) ;
1593- let sha256 = builder. stage0_metadata . checksums_sha256 . get ( & url) . expect ( & error) ;
1621+ let sha256 = builder. config . stage0_metadata . checksums_sha256 . get ( & url) . expect ( & error) ;
15941622 if tarball. exists ( ) {
15951623 if builder. verify ( & tarball, sha256) {
15961624 builder. unpack ( & tarball, & bin_root, prefix) ;
@@ -1610,7 +1638,7 @@ fn download_component(
16101638 None
16111639 } ;
16121640
1613- builder. download_component ( & base_url, & url, & tarball, "" ) ;
1641+ builder. download_component ( & format ! ( "{ base_url}/{ url}" ) , & tarball, "" ) ;
16141642 if let Some ( sha256) = checksum {
16151643 if !builder. verify ( & tarball, sha256) {
16161644 panic ! ( "failed to verify {}" , tarball. display( ) ) ;
0 commit comments