Skip to content

Commit 19dc195

Browse files
committed
move download_rustfmt out of impl as its used during config initialization
1 parent 8facd06 commit 19dc195

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

src/bootstrap/src/core/download.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,72 @@ pub(crate) fn is_download_ci_available(target_triple: &str, llvm_assertions: boo
491491
}
492492
}
493493

494+
#[cfg(test)]
495+
pub(crate) fn maybe_download_rustfmt<'a>(
496+
dwn_ctx: impl AsRef<DownloadContext<'a>>,
497+
) -> Option<PathBuf> {
498+
Some(PathBuf::new())
499+
}
500+
501+
/// NOTE: rustfmt is a completely different toolchain than the bootstrap compiler, so it can't
502+
/// reuse target directories or artifacts
503+
#[cfg(not(test))]
504+
pub(crate) fn maybe_download_rustfmt<'a>(
505+
dwn_ctx: impl AsRef<DownloadContext<'a>>,
506+
) -> Option<PathBuf> {
507+
use build_helper::stage0_parser::VersionMetadata;
508+
509+
let dwn_ctx = dwn_ctx.as_ref();
510+
511+
if dwn_ctx.dry_run {
512+
return Some(PathBuf::new());
513+
}
514+
515+
let VersionMetadata { date, version } = dwn_ctx.stage0_metadata.rustfmt.as_ref()?;
516+
let channel = format!("{version}-{date}");
517+
518+
let host = dwn_ctx.host_target;
519+
let bin_root = dwn_ctx.out.join(host).join("rustfmt");
520+
let rustfmt_path = bin_root.join("bin").join(exe("rustfmt", host));
521+
let rustfmt_stamp = BuildStamp::new(&bin_root).with_prefix("rustfmt").add_stamp(channel);
522+
if rustfmt_path.exists() && rustfmt_stamp.is_up_to_date() {
523+
return Some(rustfmt_path);
524+
}
525+
526+
download_component(
527+
dwn_ctx,
528+
DownloadSource::Dist,
529+
format!("rustfmt-{version}-{build}.tar.xz", build = host.triple),
530+
"rustfmt-preview",
531+
date,
532+
"rustfmt",
533+
);
534+
535+
download_component(
536+
dwn_ctx,
537+
DownloadSource::Dist,
538+
format!("rustc-{version}-{build}.tar.xz", build = host.triple),
539+
"rustc",
540+
date,
541+
"rustfmt",
542+
);
543+
544+
if should_fix_bins_and_dylibs(dwn_ctx.patch_binaries_for_nix, dwn_ctx.exec_ctx) {
545+
fix_bin_or_dylib(dwn_ctx.out, &bin_root.join("bin").join("rustfmt"), dwn_ctx.exec_ctx);
546+
fix_bin_or_dylib(dwn_ctx.out, &bin_root.join("bin").join("cargo-fmt"), dwn_ctx.exec_ctx);
547+
let lib_dir = bin_root.join("lib");
548+
for lib in t!(fs::read_dir(&lib_dir), lib_dir.display().to_string()) {
549+
let lib = t!(lib);
550+
if path_is_dylib(&lib.path()) {
551+
fix_bin_or_dylib(dwn_ctx.out, &lib.path(), dwn_ctx.exec_ctx);
552+
}
553+
}
554+
}
555+
556+
t!(rustfmt_stamp.write());
557+
Some(rustfmt_path)
558+
}
559+
494560
#[cfg(test)]
495561
pub(crate) fn download_beta_toolchain<'a>(dwn_ctx: impl AsRef<DownloadContext<'a>>) {}
496562

0 commit comments

Comments
 (0)