diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 635e4f3703b..3b2b507b062 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -1043,7 +1043,7 @@ def bootstrap(help_triggered): build.checksums_sha256 = data["checksums_sha256"] build.stage0_compiler = Stage0Toolchain(data["compiler"]) - build.set_dist_environment(data["dist_server"]) + build.set_dist_environment(data["config"]["dist_server"]) build.build = args.build or build.build_triple() diff --git a/src/stage0.json b/src/stage0.json index 6371b9eae59..5af6d7d824f 100644 --- a/src/stage0.json +++ b/src/stage0.json @@ -1,6 +1,8 @@ { "__comment": "Generated by `./x.py run src/tools/bump-stage0`. Run that command again to update the bootstrap compiler.", - "dist_server": "https://static.rust-lang.org", + "config": { + "dist_server": "https://static.rust-lang.org" + }, "compiler": { "date": "2022-05-20", "version": "beta" diff --git a/src/tools/bump-stage0/src/main.rs b/src/tools/bump-stage0/src/main.rs index d6364e28fef..e9ae1fe272f 100644 --- a/src/tools/bump-stage0/src/main.rs +++ b/src/tools/bump-stage0/src/main.rs @@ -4,11 +4,12 @@ use indexmap::IndexMap; use std::collections::HashMap; use std::convert::TryInto; -const DIST_SERVER: &str = "https://static.rust-lang.org"; +const PATH: &str = "src/stage0.json"; const COMPILER_COMPONENTS: &[&str] = &["rustc", "rust-std", "cargo"]; const RUSTFMT_COMPONENTS: &[&str] = &["rustfmt-preview"]; struct Tool { + config: Config, channel: Channel, version: [u16; 3], checksums: IndexMap, @@ -32,18 +33,20 @@ impl Tool { .try_into() .map_err(|_| anyhow::anyhow!("failed to parse version"))?; - Ok(Self { channel, version, checksums: IndexMap::new() }) + let existing: Stage0 = serde_json::from_slice(&std::fs::read(PATH)?)?; + + Ok(Self { channel, version, config: existing.config, checksums: IndexMap::new() }) } fn update_json(mut self) -> Result<(), Error> { std::fs::write( - "src/stage0.json", + PATH, format!( "{}\n", serde_json::to_string_pretty(&Stage0 { comment: "Generated by `./x.py run src/tools/bump-stage0`. \ - Run that command again to update the bootstrap compiler.", - dist_server: DIST_SERVER.into(), + Run that command again to update the bootstrap compiler." + .into(), compiler: self.detect_compiler()?, rustfmt: self.detect_rustfmt()?, checksums_sha256: { @@ -51,7 +54,8 @@ impl Tool { // are added while filling the other struct fields just above this block. self.checksums.sort_keys(); self.checksums - } + }, + config: self.config, })? ), )?; @@ -74,7 +78,7 @@ impl Tool { Channel::Nightly => "beta".to_string(), }; - let manifest = fetch_manifest(&channel)?; + let manifest = fetch_manifest(&self.config, &channel)?; self.collect_checksums(&manifest, COMPILER_COMPONENTS)?; Ok(Stage0Toolchain { date: manifest.date, @@ -100,13 +104,13 @@ impl Tool { return Ok(None); } - let manifest = fetch_manifest("nightly")?; + let manifest = fetch_manifest(&self.config, "nightly")?; self.collect_checksums(&manifest, RUSTFMT_COMPONENTS)?; Ok(Some(Stage0Toolchain { date: manifest.date, version: "nightly".into() })) } fn collect_checksums(&mut self, manifest: &Manifest, components: &[&str]) -> Result<(), Error> { - let prefix = format!("{}/", DIST_SERVER); + let prefix = format!("{}/", self.config.dist_server); for component in components { let pkg = manifest .pkg @@ -136,10 +140,10 @@ fn main() -> Result<(), Error> { Ok(()) } -fn fetch_manifest(channel: &str) -> Result { +fn fetch_manifest(config: &Config, channel: &str) -> Result { Ok(toml::from_slice(&http_get(&format!( "{}/dist/channel-rust-{}.toml", - DIST_SERVER, channel + config.dist_server, channel ))?)?) } @@ -166,35 +170,40 @@ enum Channel { Nightly, } -#[derive(Debug, serde::Serialize)] +#[derive(Debug, serde::Serialize, serde::Deserialize)] struct Stage0 { #[serde(rename = "__comment")] - comment: &'static str, - dist_server: String, + comment: String, + config: Config, compiler: Stage0Toolchain, rustfmt: Option, checksums_sha256: IndexMap, } -#[derive(Debug, serde::Serialize)] +#[derive(Debug, serde::Serialize, serde::Deserialize)] +struct Config { + dist_server: String, +} + +#[derive(Debug, serde::Serialize, serde::Deserialize)] struct Stage0Toolchain { date: String, version: String, } -#[derive(Debug, serde::Deserialize)] +#[derive(Debug, serde::Serialize, serde::Deserialize)] struct Manifest { date: String, pkg: HashMap, } -#[derive(Debug, serde::Deserialize)] +#[derive(Debug, serde::Serialize, serde::Deserialize)] struct ManifestPackage { version: String, target: HashMap, } -#[derive(Debug, serde::Deserialize)] +#[derive(Debug, serde::Serialize, serde::Deserialize)] struct ManifestTargetPackage { url: Option, hash: Option,