Skip to content

Commit 97f3ecd

Browse files
committed
load configuration for downloading artifacts from stage0.json
1 parent c1a0f49 commit 97f3ecd

File tree

6 files changed

+62
-50
lines changed

6 files changed

+62
-50
lines changed

src/bootstrap/builder.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -870,16 +870,10 @@ impl<'a> Builder<'a> {
870870
self.try_run(patchelf.arg(fname));
871871
}
872872

873-
pub(crate) fn download_component(
874-
&self,
875-
base: &str,
876-
url: &str,
877-
dest_path: &Path,
878-
help_on_error: &str,
879-
) {
873+
pub(crate) fn download_component(&self, url: &str, dest_path: &Path, help_on_error: &str) {
880874
// Use a temporary file in case we crash while downloading, to avoid a corrupt download in cache/.
881875
let tempfile = self.tempdir().join(dest_path.file_name().unwrap());
882-
self.download_with_retries(&tempfile, &format!("{}/{}", base, url), help_on_error);
876+
self.download_with_retries(&tempfile, url, help_on_error);
883877
t!(std::fs::rename(&tempfile, dest_path));
884878
}
885879

src/bootstrap/config.rs

+44-16
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use crate::channel::GitInfo;
2020
pub use crate::flags::Subcommand;
2121
use crate::flags::{Color, Flags};
2222
use crate::util::{exe, output, program_out_of_date, t};
23-
use crate::RustfmtMetadata;
2423
use once_cell::sync::OnceCell;
2524
use 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+
723742
impl 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-
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

14861514
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()?;
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());

src/bootstrap/lib.rs

-19
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ use std::os::windows::fs::symlink_file;
118118

119119
use filetime::FileTime;
120120
use once_cell::sync::OnceCell;
121-
use serde::Deserialize;
122121

123122
use crate::builder::Kind;
124123
use crate::config::{LlvmLibunwind, TargetSelection};
@@ -294,8 +293,6 @@ pub struct Build {
294293
hosts: Vec<TargetSelection>,
295294
targets: Vec<TargetSelection>,
296295

297-
// Stage 0 (downloaded) compiler, lld and cargo or their local rust equivalents
298-
stage0_metadata: Stage0Metadata,
299296
initial_rustc: PathBuf,
300297
initial_cargo: PathBuf,
301298
initial_lld: PathBuf,
@@ -322,18 +319,6 @@ pub struct Build {
322319
metrics: metrics::BuildMetrics,
323320
}
324321

325-
#[derive(Deserialize)]
326-
struct Stage0Metadata {
327-
dist_server: String,
328-
checksums_sha256: HashMap<String, String>,
329-
rustfmt: Option<RustfmtMetadata>,
330-
}
331-
#[derive(Deserialize)]
332-
struct RustfmtMetadata {
333-
date: String,
334-
version: String,
335-
}
336-
337322
#[derive(Debug)]
338323
struct Crate {
339324
name: Interned<String>,
@@ -482,11 +467,7 @@ impl Build {
482467
bootstrap_out
483468
};
484469

485-
let stage0_json = t!(std::fs::read_to_string(&src.join("src").join("stage0.json")));
486-
let stage0_metadata = t!(serde_json::from_str::<Stage0Metadata>(&stage0_json));
487-
488470
let mut build = Build {
489-
stage0_metadata,
490471
initial_rustc: config.initial_rustc.clone(),
491472
initial_cargo: config.initial_cargo.clone(),
492473
initial_lld,

src/bootstrap/native.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub(crate) fn maybe_download_ci_llvm(builder: &Builder<'_>) {
121121
let mut rev_list = Command::new("git");
122122
rev_list.args(&[
123123
PathBuf::from("rev-list"),
124-
"--author=[email protected]".into(),
124+
format!("--author={}", builder.config.stage0_metadata.config.git_merge_commit_email).into(),
125125
"-n1".into(),
126126
"--first-parent".into(),
127127
"HEAD".into(),
@@ -170,11 +170,10 @@ fn download_ci_llvm(builder: &Builder<'_>, llvm_sha: &str) {
170170
if !rustc_cache.exists() {
171171
t!(fs::create_dir_all(&rustc_cache));
172172
}
173-
let base = "https://ci-artifacts.rust-lang.org";
174-
let url = if llvm_assertions {
175-
format!("rustc-builds-alt/{}", llvm_sha)
173+
let base = if llvm_assertions {
174+
&builder.config.stage0_metadata.config.artifacts_with_llvm_assertions_server
176175
} else {
177-
format!("rustc-builds/{}", llvm_sha)
176+
&builder.config.stage0_metadata.config.artifacts_server
178177
};
179178
let filename = format!("rust-dev-nightly-{}.tar.xz", builder.build.build.triple);
180179
let tarball = rustc_cache.join(&filename);
@@ -187,7 +186,11 @@ fn download_ci_llvm(builder: &Builder<'_>, llvm_sha: &str) {
187186
\ndownload-ci-llvm = false
188187
\n
189188
";
190-
builder.download_component(base, &format!("{}/{}", url, filename), &tarball, help_on_error);
189+
builder.download_component(
190+
&format!("{base}/{llvm_sha}/{filename}"),
191+
&tarball,
192+
help_on_error,
193+
);
191194
}
192195
let llvm_root = builder.config.ci_llvm_root();
193196
builder.unpack(&tarball, &llvm_root, "rust-dev");

src/stage0.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{
22
"__comment": "Generated by `./x.py run src/tools/bump-stage0`. Run that command again to update the bootstrap compiler.",
33
"config": {
4-
"dist_server": "https://static.rust-lang.org"
4+
"dist_server": "https://static.rust-lang.org",
5+
"artifacts_server": "https://ci-artifacts.rust-lang.org/rustc-builds",
6+
"artifacts_with_llvm_assertions_server": "https://ci-artifacts.rust-lang.org/rustc-builds-alt",
7+
"git_merge_commit_email": "[email protected]"
58
},
69
"compiler": {
710
"date": "2022-05-20",

src/tools/bump-stage0/src/main.rs

+3
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ struct Stage0 {
183183
#[derive(Debug, serde::Serialize, serde::Deserialize)]
184184
struct Config {
185185
dist_server: String,
186+
artifacts_server: String,
187+
artifacts_with_llvm_assertions_server: String,
188+
git_merge_commit_email: String,
186189
}
187190

188191
#[derive(Debug, serde::Serialize, serde::Deserialize)]

0 commit comments

Comments
 (0)