Skip to content

Commit eeec732

Browse files
committed
download beta compiler toolchain in bootstrap if it doesn't yet exist
This is needed for when the shell scripts bypass python altogether and run the downloaded bootstrap directly. Changes are mainly provided from @jyn514, I just fixed the review notes. Signed-off-by: ozkanonur <[email protected]>
1 parent 356c651 commit eeec732

File tree

3 files changed

+70
-17
lines changed

3 files changed

+70
-17
lines changed

Diff for: src/bootstrap/config.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -223,25 +223,34 @@ pub struct Config {
223223
pub reuse: Option<PathBuf>,
224224
pub cargo_native_static: bool,
225225
pub configure_args: Vec<String>,
226+
pub out: PathBuf,
227+
pub rust_info: channel::GitInfo,
226228

227229
// These are either the stage0 downloaded binaries or the locally installed ones.
228230
pub initial_cargo: PathBuf,
229231
pub initial_rustc: PathBuf,
232+
230233
#[cfg(not(test))]
231234
initial_rustfmt: RefCell<RustfmtState>,
232235
#[cfg(test)]
233236
pub initial_rustfmt: RefCell<RustfmtState>,
234-
pub out: PathBuf,
235-
pub rust_info: channel::GitInfo,
236237
}
237238

238239
#[derive(Default, Deserialize)]
239240
#[cfg_attr(test, derive(Clone))]
240241
pub struct Stage0Metadata {
242+
pub compiler: CompilerMetadata,
241243
pub config: Stage0Config,
242244
pub checksums_sha256: HashMap<String, String>,
243245
pub rustfmt: Option<RustfmtMetadata>,
244246
}
247+
#[derive(Default, Deserialize)]
248+
#[cfg_attr(test, derive(Clone))]
249+
pub struct CompilerMetadata {
250+
pub date: String,
251+
pub version: String,
252+
}
253+
245254
#[derive(Default, Deserialize)]
246255
#[cfg_attr(test, derive(Clone))]
247256
pub struct Stage0Config {
@@ -989,10 +998,10 @@ impl Config {
989998
config.out = crate::util::absolute(&config.out);
990999
}
9911000

992-
config.initial_rustc = build
993-
.rustc
994-
.map(PathBuf::from)
995-
.unwrap_or_else(|| config.out.join(config.build.triple).join("stage0/bin/rustc"));
1001+
config.initial_rustc = build.rustc.map(PathBuf::from).unwrap_or_else(|| {
1002+
config.download_beta_toolchain();
1003+
config.out.join(config.build.triple).join("stage0/bin/rustc")
1004+
});
9961005
config.initial_cargo = build
9971006
.cargo
9981007
.map(PathBuf::from)

Diff for: 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

Diff for: 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)