Skip to content

Commit 9307bb2

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
1 parent 8789e53 commit 9307bb2

File tree

4 files changed

+76
-31
lines changed

4 files changed

+76
-31
lines changed

src/bootstrap/config.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ pub enum DryRun {
5555
/// filled out from the decoded forms of the structs below. For documentation
5656
/// each field, see the corresponding fields in
5757
/// `config.toml.example`.
58-
#[derive(Default)]
59-
#[cfg_attr(test, derive(Clone))]
58+
#[derive(Clone, Default)]
6059
pub struct Config {
6160
pub changelog_seen: Option<usize>,
6261
pub ccache: Option<String>,
@@ -217,36 +216,41 @@ pub struct Config {
217216
pub reuse: Option<PathBuf>,
218217
pub cargo_native_static: bool,
219218
pub configure_args: Vec<String>,
219+
pub out: PathBuf,
220+
pub rust_info: channel::GitInfo,
220221

221222
// These are either the stage0 downloaded binaries or the locally installed ones.
222223
pub initial_cargo: PathBuf,
223224
pub initial_rustc: PathBuf,
225+
224226
#[cfg(not(test))]
225227
initial_rustfmt: RefCell<RustfmtState>,
226228
#[cfg(test)]
227229
pub initial_rustfmt: RefCell<RustfmtState>,
228-
pub out: PathBuf,
229-
pub rust_info: channel::GitInfo,
230230
}
231231

232-
#[derive(Default, Deserialize)]
233-
#[cfg_attr(test, derive(Clone))]
232+
#[derive(Clone, Default, Deserialize)]
234233
pub struct Stage0Metadata {
234+
pub compiler: CompilerMetadata,
235235
pub config: Stage0Config,
236236
pub checksums_sha256: HashMap<String, String>,
237237
pub rustfmt: Option<RustfmtMetadata>,
238238
}
239-
#[derive(Default, Deserialize)]
240-
#[cfg_attr(test, derive(Clone))]
239+
#[derive(Clone, Default, Deserialize)]
240+
pub struct CompilerMetadata {
241+
pub date: String,
242+
pub version: String,
243+
}
244+
245+
#[derive(Clone, Default, Deserialize)]
241246
pub struct Stage0Config {
242247
pub dist_server: String,
243248
pub artifacts_server: String,
244249
pub artifacts_with_llvm_assertions_server: String,
245250
pub git_merge_commit_email: String,
246251
pub nightly_branch: String,
247252
}
248-
#[derive(Default, Deserialize)]
249-
#[cfg_attr(test, derive(Clone))]
253+
#[derive(Clone, Default, Deserialize)]
250254
pub struct RustfmtMetadata {
251255
pub date: String,
252256
pub version: String,
@@ -422,8 +426,7 @@ impl PartialEq<&str> for TargetSelection {
422426
}
423427

424428
/// Per-target configuration stored in the global configuration structure.
425-
#[derive(Default)]
426-
#[cfg_attr(test, derive(Clone))]
429+
#[derive(Clone, Default)]
427430
pub struct Target {
428431
/// Some(path to llvm-config) if using an external LLVM.
429432
pub llvm_config: Option<PathBuf>,
@@ -979,10 +982,10 @@ impl Config {
979982
config.out = crate::util::absolute(&config.out);
980983
}
981984

982-
config.initial_rustc = build
983-
.rustc
984-
.map(PathBuf::from)
985-
.unwrap_or_else(|| config.out.join(config.build.triple).join("stage0/bin/rustc"));
985+
config.initial_rustc = build.rustc.map(PathBuf::from).unwrap_or_else(|| {
986+
config.download_beta_toolchain();
987+
config.out.join(config.build.triple).join("stage0/bin/rustc")
988+
});
986989
config.initial_cargo = build
987990
.cargo
988991
.map(PathBuf::from)

src/bootstrap/download.rs

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -361,26 +361,69 @@ impl Config {
361361

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

369-
if !bin_root.join("bin").join("rustc").exists() || program_out_of_date(&rustc_stamp, commit)
411+
if !bin_root.join("bin").join("rustc").exists()
412+
|| program_out_of_date(&rustc_stamp, stamp_key)
370413
{
371414
if bin_root.exists() {
372415
t!(fs::remove_dir_all(&bin_root));
373416
}
374-
let filename = format!("rust-std-{version}-{host}.tar.xz");
417+
let filename = format!("rust-std-{channel}-{host}.tar.xz");
375418
let pattern = format!("rust-std-{host}");
376-
self.download_ci_component(filename, &pattern, commit);
377-
let filename = format!("rustc-{version}-{host}.tar.xz");
378-
self.download_ci_component(filename, "rustc", commit);
379-
// download-rustc doesn't need its own cargo, it can just use beta's.
380-
let filename = format!("rustc-dev-{version}-{host}.tar.xz");
381-
self.download_ci_component(filename, "rustc-dev", commit);
382-
let filename = format!("rust-src-{version}.tar.xz");
383-
self.download_ci_component(filename, "rust-src", commit);
419+
download_component(self, filename, &pattern, stamp_key);
420+
let filename = format!("rustc-{channel}-{host}.tar.xz");
421+
download_component(self, filename, "rustc", stamp_key);
422+
423+
for component in extra_components {
424+
let filename = format!("{component}-{channel}-{host}.tar.xz");
425+
download_component(self, filename, component, stamp_key);
426+
}
384427

385428
if self.should_fix_bins_and_dylibs() {
386429
self.fix_bin_or_dylib(&bin_root.join("bin").join("rustc"));
@@ -397,7 +440,7 @@ impl Config {
397440
}
398441
}
399442

400-
t!(fs::write(rustc_stamp, commit));
443+
t!(fs::write(rustc_stamp, stamp_key));
401444
}
402445
}
403446

src/bootstrap/flags.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ pub struct Flags {
8282
pub llvm_bolt_profile_use: Option<String>,
8383
}
8484

85-
#[derive(Debug)]
86-
#[cfg_attr(test, derive(Clone))]
85+
#[derive(Clone, Debug)]
8786
pub enum Subcommand {
8887
Build {
8988
paths: Vec<PathBuf>,

src/bootstrap/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ impl Step for Tidy {
11201120
if builder.config.channel == "dev" || builder.config.channel == "nightly" {
11211121
builder.info("fmt check");
11221122
if builder.initial_rustfmt().is_none() {
1123-
let inferred_rustfmt_dir = builder.config.initial_rustc.parent().unwrap();
1123+
let inferred_rustfmt_dir = builder.initial_rustc.parent().unwrap();
11241124
eprintln!(
11251125
"\
11261126
error: no `rustfmt` binary found in {PATH}

0 commit comments

Comments
 (0)