@@ -20,7 +20,6 @@ use crate::channel::GitInfo;
20
20
pub use crate :: flags:: Subcommand ;
21
21
use crate :: flags:: { Color , Flags } ;
22
22
use crate :: util:: { exe, output, program_out_of_date, t} ;
23
- use crate :: RustfmtMetadata ;
24
23
use once_cell:: sync:: OnceCell ;
25
24
use serde:: { Deserialize , Deserializer } ;
26
25
@@ -73,6 +72,7 @@ pub struct Config {
73
72
pub test_compare_mode : bool ,
74
73
pub color : Color ,
75
74
pub patch_binaries_for_nix : bool ,
75
+ pub stage0_metadata : Stage0Metadata ,
76
76
77
77
pub on_fail : Option < String > ,
78
78
pub stage : u32 ,
@@ -720,6 +720,25 @@ define_config! {
720
720
}
721
721
}
722
722
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
+
723
742
impl Config {
724
743
pub fn default_opts ( ) -> Config {
725
744
let mut config = Config :: default ( ) ;
@@ -776,6 +795,9 @@ impl Config {
776
795
config. llvm_profile_use = flags. llvm_profile_use ;
777
796
config. llvm_profile_generate = flags. llvm_profile_generate ;
778
797
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
+
779
801
#[ cfg( test) ]
780
802
let get_toml = |_| TomlConfig :: default ( ) ;
781
803
#[ cfg( not( test) ) ]
@@ -1103,8 +1125,11 @@ impl Config {
1103
1125
config. rust_codegen_units_std = rust. codegen_units_std . map ( threads_from_config) ;
1104
1126
config. rust_profile_use = flags. rust_profile_use . or ( rust. profile_use ) ;
1105
1127
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
+ ) ;
1108
1133
} else {
1109
1134
config. rust_profile_use = flags. rust_profile_use ;
1110
1135
config. rust_profile_generate = flags. rust_profile_generate ;
@@ -1424,7 +1449,11 @@ fn threads_from_config(v: u32) -> u32 {
1424
1449
}
1425
1450
1426
1451
/// 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 > {
1428
1457
// If `download-rustc` is not set, default to rebuilding.
1429
1458
let if_unchanged = match download_rustc {
1430
1459
None | Some ( StringOrBool :: Bool ( false ) ) => return None ,
@@ -1443,13 +1472,12 @@ fn download_ci_rustc_commit(download_rustc: Option<StringOrBool>, verbose: bool)
1443
1472
1444
1473
// Look for a version to compare to based on the current commit.
1445
1474
// Only commits merged by bors will have CI artifacts.
1446
- let merge_base = output ( Command :: new ( "git" ) . args ( & [
1447
- "rev-list" ,
1448
-
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
+ ) ;
1453
1481
let commit = merge_base. trim_end ( ) ;
1454
1482
if commit. is_empty ( ) {
1455
1483
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)
1484
1512
}
1485
1513
1486
1514
fn 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 ( ) ?;
1488
1516
let channel = format ! ( "{version}-{date}" ) ;
1489
1517
1490
1518
let host = builder. config . build ;
@@ -1568,13 +1596,13 @@ fn download_component(
1568
1596
let tarball = cache_dir. join ( & filename) ;
1569
1597
let ( base_url, url, should_verify) = match mode {
1570
1598
DownloadSource :: CI => (
1571
- "https://ci-artifacts.rust-lang.org/rustc-builds" . to_string ( ) ,
1599
+ builder . config . stage0_metadata . config . artifacts_server . clone ( ) ,
1572
1600
format ! ( "{key}/{filename}" ) ,
1573
1601
false ,
1574
1602
) ,
1575
1603
DownloadSource :: Dist => {
1576
1604
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 ( ) ) ;
1578
1606
// NOTE: make `dist` part of the URL because that's how it's stored in src/stage0.json
1579
1607
( dist_server, format ! ( "dist/{key}/{filename}" ) , true )
1580
1608
}
@@ -1590,7 +1618,7 @@ fn download_component(
1590
1618
target at this time, see https://doc.rust-lang.org/nightly\
1591
1619
/rustc/platform-support.html for more information."
1592
1620
) ;
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) ;
1594
1622
if tarball. exists ( ) {
1595
1623
if builder. verify ( & tarball, sha256) {
1596
1624
builder. unpack ( & tarball, & bin_root, prefix) ;
@@ -1610,7 +1638,7 @@ fn download_component(
1610
1638
None
1611
1639
} ;
1612
1640
1613
- builder. download_component ( & base_url, & url, & tarball, "" ) ;
1641
+ builder. download_component ( & format ! ( "{ base_url}/{ url}" ) , & tarball, "" ) ;
1614
1642
if let Some ( sha256) = checksum {
1615
1643
if !builder. verify ( & tarball, sha256) {
1616
1644
panic ! ( "failed to verify {}" , tarball. display( ) ) ;
0 commit comments