@@ -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 ,
@@ -212,6 +212,28 @@ pub struct Config {
212212 pub out : PathBuf ,
213213}
214214
215+ #[ derive( Default , Deserialize ) ]
216+ #[ cfg_attr( test, derive( Clone ) ) ]
217+ pub struct Stage0Metadata {
218+ pub config : Stage0Config ,
219+ pub checksums_sha256 : HashMap < String , String > ,
220+ pub rustfmt : Option < RustfmtMetadata > ,
221+ }
222+ #[ derive( Default , Deserialize ) ]
223+ #[ cfg_attr( test, derive( Clone ) ) ]
224+ pub struct Stage0Config {
225+ pub dist_server : String ,
226+ pub artifacts_server : String ,
227+ pub artifacts_with_llvm_assertions_server : String ,
228+ pub git_merge_commit_email : String ,
229+ }
230+ #[ derive( Default , Deserialize ) ]
231+ #[ cfg_attr( test, derive( Clone ) ) ]
232+ pub struct RustfmtMetadata {
233+ pub date : String ,
234+ pub version : String ,
235+ }
236+
215237#[ derive( Clone , Debug ) ]
216238pub enum RustfmtState {
217239 SystemToolchain ( PathBuf ) ,
@@ -776,6 +798,9 @@ impl Config {
776798 config. llvm_profile_use = flags. llvm_profile_use ;
777799 config. llvm_profile_generate = flags. llvm_profile_generate ;
778800
801+ let stage0_json = t ! ( std:: fs:: read( & config. src. join( "src" ) . join( "stage0.json" ) ) ) ;
802+ config. stage0_metadata = t ! ( serde_json:: from_slice:: <Stage0Metadata >( & stage0_json) ) ;
803+
779804 #[ cfg( test) ]
780805 let get_toml = |_| TomlConfig :: default ( ) ;
781806 #[ cfg( not( test) ) ]
@@ -1103,8 +1128,11 @@ impl Config {
11031128 config. rust_codegen_units_std = rust. codegen_units_std . map ( threads_from_config) ;
11041129 config. rust_profile_use = flags. rust_profile_use . or ( rust. profile_use ) ;
11051130 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 ) ;
1131+ config. download_rustc_commit = download_ci_rustc_commit (
1132+ & config. stage0_metadata ,
1133+ rust. download_rustc ,
1134+ config. verbose > 0 ,
1135+ ) ;
11081136 } else {
11091137 config. rust_profile_use = flags. rust_profile_use ;
11101138 config. rust_profile_generate = flags. rust_profile_generate ;
@@ -1424,7 +1452,11 @@ fn threads_from_config(v: u32) -> u32 {
14241452}
14251453
14261454/// 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 > {
1455+ fn download_ci_rustc_commit (
1456+ stage0_metadata : & Stage0Metadata ,
1457+ download_rustc : Option < StringOrBool > ,
1458+ verbose : bool ,
1459+ ) -> Option < String > {
14281460 // If `download-rustc` is not set, default to rebuilding.
14291461 let if_unchanged = match download_rustc {
14301462 None | Some ( StringOrBool :: Bool ( false ) ) => return None ,
@@ -1443,13 +1475,12 @@ fn download_ci_rustc_commit(download_rustc: Option<StringOrBool>, verbose: bool)
14431475
14441476 // Look for a version to compare to based on the current commit.
14451477 // 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- ] ) ) ;
1478+ let merge_base = output (
1479+ Command :: new ( "git" )
1480+ . arg ( "rev-list" )
1481+ . arg ( format ! ( "--author={}" , stage0_metadata. config. git_merge_commit_email) )
1482+ . args ( & [ "-n1" , "--first-parent" , "HEAD" ] ) ,
1483+ ) ;
14531484 let commit = merge_base. trim_end ( ) ;
14541485 if commit. is_empty ( ) {
14551486 println ! ( "error: could not find commit hash for downloading rustc" ) ;
@@ -1484,7 +1515,7 @@ fn download_ci_rustc_commit(download_rustc: Option<StringOrBool>, verbose: bool)
14841515}
14851516
14861517fn maybe_download_rustfmt ( builder : & Builder < ' _ > ) -> Option < PathBuf > {
1487- let RustfmtMetadata { date, version } = builder. stage0_metadata . rustfmt . as_ref ( ) ?;
1518+ let RustfmtMetadata { date, version } = builder. config . stage0_metadata . rustfmt . as_ref ( ) ?;
14881519 let channel = format ! ( "{version}-{date}" ) ;
14891520
14901521 let host = builder. config . build ;
@@ -1568,13 +1599,13 @@ fn download_component(
15681599 let tarball = cache_dir. join ( & filename) ;
15691600 let ( base_url, url, should_verify) = match mode {
15701601 DownloadSource :: CI => (
1571- "https://ci-artifacts.rust-lang.org/rustc-builds" . to_string ( ) ,
1602+ builder . config . stage0_metadata . config . artifacts_server . clone ( ) ,
15721603 format ! ( "{key}/{filename}" ) ,
15731604 false ,
15741605 ) ,
15751606 DownloadSource :: Dist => {
15761607 let dist_server = env:: var ( "RUSTUP_DIST_SERVER" )
1577- . unwrap_or ( builder. stage0_metadata . dist_server . to_string ( ) ) ;
1608+ . unwrap_or ( builder. config . stage0_metadata . config . dist_server . to_string ( ) ) ;
15781609 // NOTE: make `dist` part of the URL because that's how it's stored in src/stage0.json
15791610 ( dist_server, format ! ( "dist/{key}/{filename}" ) , true )
15801611 }
@@ -1590,7 +1621,7 @@ fn download_component(
15901621 target at this time, see https://doc.rust-lang.org/nightly\
15911622 /rustc/platform-support.html for more information."
15921623 ) ;
1593- let sha256 = builder. stage0_metadata . checksums_sha256 . get ( & url) . expect ( & error) ;
1624+ let sha256 = builder. config . stage0_metadata . checksums_sha256 . get ( & url) . expect ( & error) ;
15941625 if tarball. exists ( ) {
15951626 if builder. verify ( & tarball, sha256) {
15961627 builder. unpack ( & tarball, & bin_root, prefix) ;
@@ -1610,7 +1641,7 @@ fn download_component(
16101641 None
16111642 } ;
16121643
1613- builder. download_component ( & base_url, & url, & tarball, "" ) ;
1644+ builder. download_component ( & format ! ( "{ base_url}/{ url}" ) , & tarball, "" ) ;
16141645 if let Some ( sha256) = checksum {
16151646 if !builder. verify ( & tarball, sha256) {
16161647 panic ! ( "failed to verify {}" , tarball. display( ) ) ;
0 commit comments