Skip to content

Commit d5289d7

Browse files
committed
initialize single download context and later mut
1 parent d22b2a4 commit d5289d7

File tree

2 files changed

+57
-170
lines changed

2 files changed

+57
-170
lines changed

src/bootstrap/src/core/config/config.rs

Lines changed: 37 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -738,27 +738,28 @@ impl Config {
738738
);
739739
}
740740

741+
let mut dwn_ctx = DownloadContext::new(
742+
path_modification_cache.clone(),
743+
&src,
744+
rust_info.clone(),
745+
&submodules,
746+
download_rustc_commit.clone(),
747+
host_target,
748+
llvm_from_ci,
749+
target_config.clone(),
750+
out.clone(),
751+
patch_binaries_for_nix,
752+
&exec_ctx,
753+
&stage0_metadata,
754+
llvm_assertions,
755+
&bootstrap_cache_path,
756+
is_running_on_ci,
757+
);
758+
741759
let initial_rustc = if let Some(rustc) = build_rustc {
742760
rustc
743761
} else {
744-
let dwn_ctx = DownloadContext::new(
745-
path_modification_cache.clone(),
746-
&src,
747-
&rust_info,
748-
&submodules,
749-
&download_rustc_commit,
750-
host_target,
751-
llvm_from_ci,
752-
&target_config,
753-
&out,
754-
patch_binaries_for_nix,
755-
&exec_ctx,
756-
&stage0_metadata,
757-
llvm_assertions,
758-
&bootstrap_cache_path,
759-
is_running_on_ci,
760-
);
761-
download_beta_toolchain(dwn_ctx);
762+
download_beta_toolchain(&dwn_ctx);
762763
out.join(host_target).join("stage0").join("bin").join(exe("rustc", host_target))
763764
};
764765

@@ -776,24 +777,7 @@ impl Config {
776777
let initial_cargo = if let Some(cargo) = build_cargo {
777778
cargo
778779
} else {
779-
let dwn_ctx = DownloadContext::new(
780-
path_modification_cache.clone(),
781-
&src,
782-
&rust_info,
783-
&submodules,
784-
&download_rustc_commit,
785-
host_target,
786-
llvm_from_ci,
787-
&target_config,
788-
&out,
789-
patch_binaries_for_nix,
790-
&exec_ctx,
791-
&stage0_metadata,
792-
llvm_assertions,
793-
&bootstrap_cache_path,
794-
is_running_on_ci,
795-
);
796-
download_beta_toolchain(dwn_ctx);
780+
download_beta_toolchain(&dwn_ctx);
797781
initial_sysroot.join("bin").join(exe("cargo", host_target))
798782
};
799783

@@ -802,6 +786,7 @@ impl Config {
802786
let dir = out.join("tmp-dry-run");
803787
t!(fs::create_dir_all(&dir));
804788
out = dir;
789+
dwn_ctx.out = out.clone();
805790
}
806791

807792
let file_content = t!(fs::read_to_string(src.join("src/ci/channel")));
@@ -822,6 +807,7 @@ impl Config {
822807
let omit_git_hash = rust_omit_git_hash.unwrap_or(channel == "dev");
823808

824809
rust_info = git_info(&exec_ctx, omit_git_hash, &src);
810+
dwn_ctx.rust_info = rust_info.clone();
825811

826812
let vendor = build_vendor.unwrap_or(
827813
rust_info.is_from_tarball()
@@ -858,25 +844,9 @@ impl Config {
858844
);
859845
}
860846

861-
let dwn_ctx = DownloadContext::new(
862-
path_modification_cache.clone(),
863-
&src,
864-
&rust_info,
865-
&submodules,
866-
&download_rustc_commit,
867-
host_target,
868-
llvm_from_ci,
869-
&target_config,
870-
&out,
871-
patch_binaries_for_nix,
872-
&exec_ctx,
873-
&stage0_metadata,
874-
llvm_assertions,
875-
&bootstrap_cache_path,
876-
is_running_on_ci,
877-
);
878847
download_rustc_commit =
879-
download_ci_rustc_commit(dwn_ctx, rust_download_rustc, llvm_assertions);
848+
download_ci_rustc_commit(&dwn_ctx, rust_download_rustc, llvm_assertions);
849+
dwn_ctx.download_rustc_commit = download_rustc_commit.clone();
880850

881851
if debug_assertions_requested {
882852
eprintln!(
@@ -885,6 +855,7 @@ impl Config {
885855
);
886856
// We need to put this later down_ci_rustc_commit.
887857
download_rustc_commit = None;
858+
dwn_ctx.download_rustc_commit = None;
888859
}
889860

890861
if let Some(t) = toml.target {
@@ -946,6 +917,7 @@ impl Config {
946917

947918
target_config.insert(TargetSelection::from_user(&triple), target);
948919
}
920+
dwn_ctx.target_config = target_config.clone();
949921
}
950922

951923
// We make `x86_64-unknown-linux-gnu` use the self-contained linker by default, so we will
@@ -983,25 +955,9 @@ impl Config {
983955
"WARNING: `rust.download-rustc` is enabled. The `rust.channel` option will be overridden by the CI rustc's channel."
984956
);
985957

986-
let dwn_ctx = DownloadContext::new(
987-
path_modification_cache.clone(),
988-
&src,
989-
&rust_info,
990-
&submodules,
991-
&download_rustc_commit,
992-
host_target,
993-
llvm_from_ci,
994-
&target_config,
995-
&out,
996-
patch_binaries_for_nix,
997-
&exec_ctx,
998-
&stage0_metadata,
999-
llvm_assertions,
1000-
&bootstrap_cache_path,
1001-
is_running_on_ci,
1002-
);
1003-
let channel_ =
1004-
read_file_by_commit(dwn_ctx, Path::new("src/ci/channel"), commit).trim().to_owned();
958+
let channel_ = read_file_by_commit(&dwn_ctx, Path::new("src/ci/channel"), commit)
959+
.trim()
960+
.to_owned();
1005961

1006962
channel = channel_;
1007963
}
@@ -1010,24 +966,8 @@ impl Config {
1010966
llvm_link_shared.set(Some(v));
1011967
}
1012968

1013-
let dwn_ctx = DownloadContext::new(
1014-
path_modification_cache.clone(),
1015-
&src,
1016-
&rust_info,
1017-
&submodules,
1018-
&download_rustc_commit,
1019-
host_target,
1020-
llvm_from_ci,
1021-
&target_config,
1022-
&out,
1023-
patch_binaries_for_nix,
1024-
&exec_ctx,
1025-
&stage0_metadata,
1026-
llvm_assertions,
1027-
&bootstrap_cache_path,
1028-
is_running_on_ci,
1029-
);
1030-
llvm_from_ci = parse_download_ci_llvm(dwn_ctx, llvm_download_ci_llvm, llvm_assertions);
969+
llvm_from_ci = parse_download_ci_llvm(&dwn_ctx, llvm_download_ci_llvm, llvm_assertions);
970+
dwn_ctx.llvm_from_ci = llvm_from_ci;
1031971

1032972
if llvm_from_ci {
1033973
let warn = |option: &str| {
@@ -1073,55 +1013,19 @@ impl Config {
10731013

10741014
if llvm_from_ci {
10751015
let triple = &host_target.triple;
1076-
let dwn_ctx = DownloadContext::new(
1077-
path_modification_cache.clone(),
1078-
&src,
1079-
&rust_info,
1080-
&submodules,
1081-
&download_rustc_commit,
1082-
host_target,
1083-
llvm_from_ci,
1084-
&target_config,
1085-
&out,
1086-
patch_binaries_for_nix,
1087-
&exec_ctx,
1088-
&stage0_metadata,
1089-
llvm_assertions,
1090-
&bootstrap_cache_path,
1091-
is_running_on_ci,
1092-
);
1093-
let ci_llvm_bin = ci_llvm_root(dwn_ctx).join("bin");
1016+
let ci_llvm_bin = ci_llvm_root(&dwn_ctx).join("bin");
10941017
let build_target =
10951018
target_config.entry(host_target).or_insert_with(|| Target::from_triple(triple));
1019+
dwn_ctx.target_config.entry(host_target).or_insert_with(|| Target::from_triple(triple));
10961020

10971021
check_ci_llvm!(build_target.llvm_config);
10981022
check_ci_llvm!(build_target.llvm_filecheck);
10991023
build_target.llvm_config = Some(ci_llvm_bin.join(exe("llvm-config", host_target)));
11001024
build_target.llvm_filecheck = Some(ci_llvm_bin.join(exe("FileCheck", host_target)));
11011025
}
11021026

1103-
let initial_rustfmt = if let Some(r) = build_rustfmt {
1104-
Some(r)
1105-
} else {
1106-
let dwn_ctx = DownloadContext::new(
1107-
path_modification_cache.clone(),
1108-
&src,
1109-
&rust_info,
1110-
&submodules,
1111-
&download_rustc_commit,
1112-
host_target,
1113-
llvm_from_ci,
1114-
&target_config,
1115-
&out,
1116-
patch_binaries_for_nix,
1117-
&exec_ctx,
1118-
&stage0_metadata,
1119-
llvm_assertions,
1120-
&bootstrap_cache_path,
1121-
is_running_on_ci,
1122-
);
1123-
maybe_download_rustfmt(dwn_ctx)
1124-
};
1027+
let initial_rustfmt =
1028+
if let Some(r) = build_rustfmt { Some(r) } else { maybe_download_rustfmt(&dwn_ctx) };
11251029

11261030
if matches!(rust_lld_mode.unwrap_or_default(), LldMode::SelfContained)
11271031
&& !lld_enabled
@@ -1132,24 +1036,7 @@ impl Config {
11321036
);
11331037
}
11341038

1135-
let dwn_ctx = DownloadContext::new(
1136-
path_modification_cache.clone(),
1137-
&src,
1138-
&rust_info,
1139-
&submodules,
1140-
&download_rustc_commit,
1141-
host_target,
1142-
llvm_from_ci,
1143-
&target_config,
1144-
&out,
1145-
patch_binaries_for_nix,
1146-
&exec_ctx,
1147-
&stage0_metadata,
1148-
llvm_assertions,
1149-
&bootstrap_cache_path,
1150-
is_running_on_ci,
1151-
);
1152-
if lld_enabled && is_system_llvm(dwn_ctx, host_target) {
1039+
if lld_enabled && is_system_llvm(&dwn_ctx, host_target) {
11531040
panic!("Cannot enable LLD with `rust.lld = true` when using external llvm-config.");
11541041
}
11551042

@@ -2365,7 +2252,7 @@ pub fn has_changes_from_upstream<'a>(
23652252
)]
23662253
pub(crate) fn update_submodule<'a>(dwn_ctx: impl AsRef<DownloadContext<'a>>, relative_path: &str) {
23672254
let dwn_ctx = dwn_ctx.as_ref();
2368-
if dwn_ctx.rust_info.is_from_tarball() || !submodules_(dwn_ctx.submodules, dwn_ctx.rust_info) {
2255+
if dwn_ctx.rust_info.is_from_tarball() || !submodules_(dwn_ctx.submodules, &dwn_ctx.rust_info) {
23692256
return;
23702257
}
23712258

src/bootstrap/src/core/download.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,13 @@ impl Config {
403403
pub(crate) struct DownloadContext<'a> {
404404
pub path_modification_cache: Arc<Mutex<HashMap<Vec<&'static str>, PathFreshness>>>,
405405
pub src: &'a Path,
406-
pub rust_info: &'a channel::GitInfo,
406+
pub rust_info: channel::GitInfo,
407407
pub submodules: &'a Option<bool>,
408-
pub download_rustc_commit: &'a Option<String>,
408+
pub download_rustc_commit: Option<String>,
409409
pub host_target: TargetSelection,
410410
pub llvm_from_ci: bool,
411-
pub target_config: &'a HashMap<TargetSelection, Target>,
412-
pub out: &'a Path,
411+
pub target_config: HashMap<TargetSelection, Target>,
412+
pub out: PathBuf,
413413
pub patch_binaries_for_nix: Option<bool>,
414414
pub exec_ctx: &'a ExecutionContext,
415415
pub stage0_metadata: &'a build_helper::stage0_parser::Stage0,
@@ -423,13 +423,13 @@ impl<'a> DownloadContext<'a> {
423423
pub fn new(
424424
path_modification_cache: Arc<Mutex<HashMap<Vec<&'static str>, PathFreshness>>>,
425425
src: &'a Path,
426-
rust_info: &'a channel::GitInfo,
426+
rust_info: channel::GitInfo,
427427
submodules: &'a Option<bool>,
428-
download_rustc_commit: &'a Option<String>,
428+
download_rustc_commit: Option<String>,
429429
host_target: TargetSelection,
430430
llvm_from_ci: bool,
431-
target_config: &'a HashMap<TargetSelection, Target>,
432-
out: &'a Path,
431+
target_config: HashMap<TargetSelection, Target>,
432+
out: PathBuf,
433433
patch_binaries_for_nix: Option<bool>,
434434
exec_ctx: &'a ExecutionContext,
435435
stage0_metadata: &'a build_helper::stage0_parser::Stage0,
@@ -469,12 +469,12 @@ impl<'a> From<&'a Config> for DownloadContext<'a> {
469469
path_modification_cache: value.path_modification_cache.clone(),
470470
src: &value.src,
471471
host_target: value.host_target,
472-
rust_info: &value.rust_info,
473-
download_rustc_commit: &value.download_rustc_commit,
472+
rust_info: value.rust_info.clone(),
473+
download_rustc_commit: value.download_rustc_commit.clone(),
474474
submodules: &value.submodules,
475475
llvm_from_ci: value.llvm_from_ci,
476-
target_config: &value.target_config,
477-
out: &value.out,
476+
target_config: value.target_config.clone(),
477+
out: value.out.clone(),
478478
patch_binaries_for_nix: value.patch_binaries_for_nix,
479479
exec_ctx: &value.exec_ctx,
480480
stage0_metadata: &value.stage0_metadata,
@@ -582,13 +582,13 @@ pub(crate) fn maybe_download_rustfmt<'a>(
582582
);
583583

584584
if should_fix_bins_and_dylibs(dwn_ctx.patch_binaries_for_nix, dwn_ctx.exec_ctx) {
585-
fix_bin_or_dylib(dwn_ctx.out, &bin_root.join("bin").join("rustfmt"), dwn_ctx.exec_ctx);
586-
fix_bin_or_dylib(dwn_ctx.out, &bin_root.join("bin").join("cargo-fmt"), dwn_ctx.exec_ctx);
585+
fix_bin_or_dylib(&dwn_ctx.out, &bin_root.join("bin").join("rustfmt"), dwn_ctx.exec_ctx);
586+
fix_bin_or_dylib(&dwn_ctx.out, &bin_root.join("bin").join("cargo-fmt"), dwn_ctx.exec_ctx);
587587
let lib_dir = bin_root.join("lib");
588588
for lib in t!(fs::read_dir(&lib_dir), lib_dir.display().to_string()) {
589589
let lib = t!(lib);
590590
if path_is_dylib(&lib.path()) {
591-
fix_bin_or_dylib(dwn_ctx.out, &lib.path(), dwn_ctx.exec_ctx);
591+
fix_bin_or_dylib(&dwn_ctx.out, &lib.path(), dwn_ctx.exec_ctx);
592592
}
593593
}
594594
}
@@ -654,18 +654,18 @@ fn download_toolchain<'a>(
654654
}
655655

656656
if should_fix_bins_and_dylibs(dwn_ctx.patch_binaries_for_nix, dwn_ctx.exec_ctx) {
657-
fix_bin_or_dylib(dwn_ctx.out, &bin_root.join("bin").join("rustc"), dwn_ctx.exec_ctx);
658-
fix_bin_or_dylib(dwn_ctx.out, &bin_root.join("bin").join("rustdoc"), dwn_ctx.exec_ctx);
657+
fix_bin_or_dylib(&dwn_ctx.out, &bin_root.join("bin").join("rustc"), dwn_ctx.exec_ctx);
658+
fix_bin_or_dylib(&dwn_ctx.out, &bin_root.join("bin").join("rustdoc"), dwn_ctx.exec_ctx);
659659
fix_bin_or_dylib(
660-
dwn_ctx.out,
660+
&dwn_ctx.out,
661661
&bin_root.join("libexec").join("rust-analyzer-proc-macro-srv"),
662662
dwn_ctx.exec_ctx,
663663
);
664664
let lib_dir = bin_root.join("lib");
665665
for lib in t!(fs::read_dir(&lib_dir), lib_dir.display().to_string()) {
666666
let lib = t!(lib);
667667
if path_is_dylib(&lib.path()) {
668-
fix_bin_or_dylib(dwn_ctx.out, &lib.path(), dwn_ctx.exec_ctx);
668+
fix_bin_or_dylib(&dwn_ctx.out, &lib.path(), dwn_ctx.exec_ctx);
669669
}
670670
}
671671
}
@@ -1002,7 +1002,7 @@ fn download_file<'a>(
10021002
println!("download {url}");
10031003
});
10041004
// Use a temporary file in case we crash while downloading, to avoid a corrupt download in cache/.
1005-
let tempfile = tempdir(dwn_ctx.out).join(dest_path.file_name().unwrap());
1005+
let tempfile = tempdir(&dwn_ctx.out).join(dest_path.file_name().unwrap());
10061006
// While bootstrap itself only supports http and https downloads, downstream forks might
10071007
// need to download components from other protocols. The match allows them adding more
10081008
// protocols without worrying about merge conflicts if we change the HTTP implementation.

0 commit comments

Comments
 (0)