@@ -20,6 +20,7 @@ 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 ;
23
24
use once_cell:: sync:: OnceCell ;
24
25
use serde:: { Deserialize , Deserializer } ;
25
26
@@ -1483,25 +1484,8 @@ fn download_ci_rustc_commit(download_rustc: Option<StringOrBool>, verbose: bool)
1483
1484
}
1484
1485
1485
1486
fn maybe_download_rustfmt ( builder : & Builder < ' _ > ) -> Option < PathBuf > {
1486
- #[ derive( Deserialize ) ]
1487
- struct Stage0Metadata {
1488
- dist_server : String ,
1489
- checksums_sha256 : HashMap < String , String > ,
1490
- rustfmt : Option < RustfmtMetadata > ,
1491
- }
1492
- #[ derive( Deserialize ) ]
1493
- struct RustfmtMetadata {
1494
- date : String ,
1495
- version : String ,
1496
- }
1497
-
1498
- let stage0_json = builder. read ( & builder. src . join ( "src" ) . join ( "stage0.json" ) ) ;
1499
- let Stage0Metadata { dist_server, checksums_sha256, rustfmt } =
1500
- t ! ( serde_json:: from_str:: <Stage0Metadata >( & stage0_json) ) ;
1501
- let RustfmtMetadata { date, version } = rustfmt?;
1487
+ let RustfmtMetadata { date, version } = builder. stage0_metadata . rustfmt . as_ref ( ) ?;
1502
1488
let channel = format ! ( "{version}-{date}" ) ;
1503
- let mut dist_server = env:: var ( "RUSTUP_DIST_SERVER" ) . unwrap_or ( dist_server) ;
1504
- dist_server. push_str ( "/dist" ) ;
1505
1489
1506
1490
let host = builder. config . build ;
1507
1491
let rustfmt_path = builder. config . initial_rustc . with_file_name ( exe ( "rustfmt" , host) ) ;
@@ -1512,15 +1496,7 @@ fn maybe_download_rustfmt(builder: &Builder<'_>) -> Option<PathBuf> {
1512
1496
}
1513
1497
1514
1498
let filename = format ! ( "rustfmt-{version}-{build}.tar.xz" , build = host. triple) ;
1515
- download_component (
1516
- builder,
1517
- & dist_server,
1518
- filename,
1519
- "rustfmt-preview" ,
1520
- & date,
1521
- "stage0" ,
1522
- Some ( checksums_sha256) ,
1523
- ) ;
1499
+ download_component ( builder, DownloadSource :: Dist , filename, "rustfmt-preview" , & date, "stage0" ) ;
1524
1500
1525
1501
builder. fix_bin_or_dylib ( & bin_root. join ( "bin" ) . join ( "rustfmt" ) ) ;
1526
1502
builder. fix_bin_or_dylib ( & bin_root. join ( "bin" ) . join ( "cargo-fmt" ) ) ;
@@ -1563,28 +1539,24 @@ fn download_ci_rustc(builder: &Builder<'_>, commit: &str) {
1563
1539
}
1564
1540
}
1565
1541
1542
+ pub ( crate ) enum DownloadSource {
1543
+ CI ,
1544
+ Dist ,
1545
+ }
1546
+
1566
1547
/// Download a single component of a CI-built toolchain (not necessarily a published nightly).
1567
1548
// NOTE: intentionally takes an owned string to avoid downloading multiple times by accident
1568
1549
fn download_ci_component ( builder : & Builder < ' _ > , filename : String , prefix : & str , commit : & str ) {
1569
- download_component (
1570
- builder,
1571
- "https://ci-artifacts.rust-lang.org/rustc-builds" ,
1572
- filename,
1573
- prefix,
1574
- commit,
1575
- "ci-rustc" ,
1576
- None ,
1577
- )
1550
+ download_component ( builder, DownloadSource :: CI , filename, prefix, commit, "ci-rustc" )
1578
1551
}
1579
1552
1580
1553
fn download_component (
1581
1554
builder : & Builder < ' _ > ,
1582
- base_url : & str ,
1555
+ mode : DownloadSource ,
1583
1556
filename : String ,
1584
1557
prefix : & str ,
1585
1558
key : & str ,
1586
1559
destination : & str ,
1587
- checksums : Option < HashMap < String , String > > ,
1588
1560
) {
1589
1561
let cache_dst = builder. out . join ( "cache" ) ;
1590
1562
let cache_dir = cache_dst. join ( key) ;
@@ -1594,20 +1566,31 @@ fn download_component(
1594
1566
1595
1567
let bin_root = builder. out . join ( builder. config . build . triple ) . join ( destination) ;
1596
1568
let tarball = cache_dir. join ( & filename) ;
1597
- let url = format ! ( "{key}/{filename}" ) ;
1569
+ let ( base_url, url, should_verify) = match mode {
1570
+ DownloadSource :: CI => (
1571
+ "https://ci-artifacts.rust-lang.org/rustc-builds" . to_string ( ) ,
1572
+ format ! ( "{key}/{filename}" ) ,
1573
+ false ,
1574
+ ) ,
1575
+ DownloadSource :: Dist => {
1576
+ let dist_server = env:: var ( "RUSTUP_DIST_SERVER" )
1577
+ . unwrap_or ( builder. stage0_metadata . dist_server . to_string ( ) ) ;
1578
+ // NOTE: make `dist` part of the URL because that's how it's stored in src/stage0.json
1579
+ ( dist_server, format ! ( "dist/{key}/{filename}" ) , true )
1580
+ }
1581
+ } ;
1598
1582
1599
1583
// For the beta compiler, put special effort into ensuring the checksums are valid.
1600
1584
// FIXME: maybe we should do this for download-rustc as well? but it would be a pain to update
1601
1585
// this on each and every nightly ...
1602
- let checksum = if let Some ( checksums ) = & checksums {
1586
+ let checksum = if should_verify {
1603
1587
let error = format ! (
1604
1588
"src/stage0.json doesn't contain a checksum for {url}. \
1605
1589
Pre-built artifacts might not be available for this \
1606
1590
target at this time, see https://doc.rust-lang.org/nightly\
1607
1591
/rustc/platform-support.html for more information."
1608
1592
) ;
1609
- // TODO: add an enum { Commit, Published } so we don't have to hardcode `dist` in two places
1610
- let sha256 = checksums. get ( & format ! ( "dist/{url}" ) ) . expect ( & error) ;
1593
+ let sha256 = builder. stage0_metadata . checksums_sha256 . get ( & url) . expect ( & error) ;
1611
1594
if tarball. exists ( ) {
1612
1595
if builder. verify ( & tarball, sha256) {
1613
1596
builder. unpack ( & tarball, & bin_root, prefix) ;
@@ -1627,7 +1610,7 @@ fn download_component(
1627
1610
None
1628
1611
} ;
1629
1612
1630
- builder. download_component ( base_url, & url, & tarball, "" ) ;
1613
+ builder. download_component ( & base_url, & url, & tarball, "" ) ;
1631
1614
if let Some ( sha256) = checksum {
1632
1615
if !builder. verify ( & tarball, sha256) {
1633
1616
panic ! ( "failed to verify {}" , tarball. display( ) ) ;
0 commit comments