Skip to content

Commit ba86600

Browse files
committed
Auto merge of rust-lang#109448 - ozkanonur:download-beta-compiler-toolchain, r=Mark-Simulacrum
Download beta compiler toolchain in bootstrap if it doesn't yet exist Blocker for rust-lang#107812 and rust-lang#99989 See: rust-lang#107812 (comment) r? `@jyn514`
2 parents 23ee2af + eeec732 commit ba86600

File tree

3 files changed

+70
-17
lines changed

3 files changed

+70
-17
lines changed

src/bootstrap/config.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -227,25 +227,34 @@ pub struct Config {
227227
pub reuse: Option<PathBuf>,
228228
pub cargo_native_static: bool,
229229
pub configure_args: Vec<String>,
230+
pub out: PathBuf,
231+
pub rust_info: channel::GitInfo,
230232

231233
// These are either the stage0 downloaded binaries or the locally installed ones.
232234
pub initial_cargo: PathBuf,
233235
pub initial_rustc: PathBuf,
236+
234237
#[cfg(not(test))]
235238
initial_rustfmt: RefCell<RustfmtState>,
236239
#[cfg(test)]
237240
pub initial_rustfmt: RefCell<RustfmtState>,
238-
pub out: PathBuf,
239-
pub rust_info: channel::GitInfo,
240241
}
241242

242243
#[derive(Default, Deserialize)]
243244
#[cfg_attr(test, derive(Clone))]
244245
pub struct Stage0Metadata {
246+
pub compiler: CompilerMetadata,
245247
pub config: Stage0Config,
246248
pub checksums_sha256: HashMap<String, String>,
247249
pub rustfmt: Option<RustfmtMetadata>,
248250
}
251+
#[derive(Default, Deserialize)]
252+
#[cfg_attr(test, derive(Clone))]
253+
pub struct CompilerMetadata {
254+
pub date: String,
255+
pub version: String,
256+
}
257+
249258
#[derive(Default, Deserialize)]
250259
#[cfg_attr(test, derive(Clone))]
251260
pub struct Stage0Config {
@@ -1000,10 +1009,10 @@ impl Config {
10001009
config.out = crate::util::absolute(&config.out);
10011010
}
10021011

1003-
config.initial_rustc = build
1004-
.rustc
1005-
.map(PathBuf::from)
1006-
.unwrap_or_else(|| config.out.join(config.build.triple).join("stage0/bin/rustc"));
1012+
config.initial_rustc = build.rustc.map(PathBuf::from).unwrap_or_else(|| {
1013+
config.download_beta_toolchain();
1014+
config.out.join(config.build.triple).join("stage0/bin/rustc")
1015+
});
10071016
config.initial_cargo = build
10081017
.cargo
10091018
.map(PathBuf::from)

src/bootstrap/download.rs

+54-10
Original file line numberDiff line numberDiff line change
@@ -367,26 +367,70 @@ impl Config {
367367

368368
pub(crate) fn download_ci_rustc(&self, commit: &str) {
369369
self.verbose(&format!("using downloaded stage2 artifacts from CI (commit {commit})"));
370+
370371
let version = self.artifact_version_part(commit);
372+
// download-rustc doesn't need its own cargo, it can just use beta's. But it does need the
373+
// `rustc_private` crates for tools.
374+
let extra_components = ["rustc-dev"];
375+
376+
self.download_toolchain(
377+
&version,
378+
"ci-rustc",
379+
commit,
380+
&extra_components,
381+
Self::download_ci_component,
382+
);
383+
}
384+
385+
pub(crate) fn download_beta_toolchain(&self) {
386+
self.verbose(&format!("downloading stage0 beta artifacts"));
387+
388+
let date = &self.stage0_metadata.compiler.date;
389+
let version = &self.stage0_metadata.compiler.version;
390+
let extra_components = ["cargo"];
391+
392+
let download_beta_component = |config: &Config, filename, prefix: &_, date: &_| {
393+
config.download_component(DownloadSource::Dist, filename, prefix, date, "stage0")
394+
};
395+
396+
self.download_toolchain(
397+
version,
398+
"stage0",
399+
date,
400+
&extra_components,
401+
download_beta_component,
402+
);
403+
}
404+
405+
fn download_toolchain(
406+
&self,
407+
// FIXME(ozkanonur) use CompilerMetadata instead of `version: &str`
408+
version: &str,
409+
sysroot: &str,
410+
stamp_key: &str,
411+
extra_components: &[&str],
412+
download_component: fn(&Config, String, &str, &str),
413+
) {
371414
let host = self.build.triple;
372-
let bin_root = self.out.join(host).join("ci-rustc");
415+
let bin_root = self.out.join(host).join(sysroot);
373416
let rustc_stamp = bin_root.join(".rustc-stamp");
374417

375-
if !bin_root.join("bin").join("rustc").exists() || program_out_of_date(&rustc_stamp, commit)
418+
if !bin_root.join("bin").join(exe("rustc", self.build)).exists()
419+
|| program_out_of_date(&rustc_stamp, stamp_key)
376420
{
377421
if bin_root.exists() {
378422
t!(fs::remove_dir_all(&bin_root));
379423
}
380424
let filename = format!("rust-std-{version}-{host}.tar.xz");
381425
let pattern = format!("rust-std-{host}");
382-
self.download_ci_component(filename, &pattern, commit);
426+
download_component(self, filename, &pattern, stamp_key);
383427
let filename = format!("rustc-{version}-{host}.tar.xz");
384-
self.download_ci_component(filename, "rustc", commit);
385-
// download-rustc doesn't need its own cargo, it can just use beta's.
386-
let filename = format!("rustc-dev-{version}-{host}.tar.xz");
387-
self.download_ci_component(filename, "rustc-dev", commit);
388-
let filename = format!("rust-src-{version}.tar.xz");
389-
self.download_ci_component(filename, "rust-src", commit);
428+
download_component(self, filename, "rustc", stamp_key);
429+
430+
for component in extra_components {
431+
let filename = format!("{component}-{version}-{host}.tar.xz");
432+
download_component(self, filename, component, stamp_key);
433+
}
390434

391435
if self.should_fix_bins_and_dylibs() {
392436
self.fix_bin_or_dylib(&bin_root.join("bin").join("rustc"));
@@ -403,7 +447,7 @@ impl Config {
403447
}
404448
}
405449

406-
t!(fs::write(rustc_stamp, commit));
450+
t!(fs::write(rustc_stamp, stamp_key));
407451
}
408452
}
409453

src/bootstrap/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ impl Step for Tidy {
11331133
if builder.config.channel == "dev" || builder.config.channel == "nightly" {
11341134
builder.info("fmt check");
11351135
if builder.initial_rustfmt().is_none() {
1136-
let inferred_rustfmt_dir = builder.config.initial_rustc.parent().unwrap();
1136+
let inferred_rustfmt_dir = builder.initial_rustc.parent().unwrap();
11371137
eprintln!(
11381138
"\
11391139
error: no `rustfmt` binary found in {PATH}

0 commit comments

Comments
 (0)