Skip to content

Commit 9d1f94a

Browse files
committed
Handle external LLVM config
1 parent e7c9e12 commit 9d1f94a

File tree

1 file changed

+41
-38
lines changed

1 file changed

+41
-38
lines changed

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

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -954,45 +954,15 @@ impl Config {
954954
}
955955
}
956956

957-
for (target, linker_override) in default_linux_linker_overrides() {
958-
// If the user overrode the default Linux linker, do not apply bootstrap defaults
959-
if targets_with_user_linker_override.contains(&target) {
960-
continue;
961-
}
962-
let default_linux_linker_override = match linker_override {
963-
DefaultLinuxLinkerOverride::Off => continue,
964-
DefaultLinuxLinkerOverride::SelfContainedLldCc => {
965-
// If we automatically default to the self-contained LLD linker,
966-
// we also need to handle the rust.lld option.
967-
match rust_lld_enabled {
968-
// If LLD was not enabled explicitly, we enable it
969-
None => {
970-
lld_enabled = true;
971-
Some(DefaultLinuxLinkerOverride::SelfContainedLldCc)
972-
}
973-
// If it was enabled already, we don't need to do anything
974-
Some(true) => Some(DefaultLinuxLinkerOverride::SelfContainedLldCc),
975-
// If it was explicitly disabled, we do not apply the
976-
// linker override
977-
Some(false) => None,
978-
}
979-
}
980-
};
981-
if let Some(linker_override) = default_linux_linker_override {
982-
target_config
983-
.entry(TargetSelection::from_user(&target))
984-
.or_default()
985-
.default_linker_linux_override = linker_override;
986-
}
987-
}
988-
989957
let llvm_from_ci = parse_download_ci_llvm(
990958
&dwn_ctx,
991959
&rust_info,
992960
&download_rustc_commit,
993961
llvm_download_ci_llvm,
994962
llvm_assertions,
995963
);
964+
let is_host_system_llvm =
965+
is_system_llvm(&target_config, llvm_from_ci, host_target, host_target);
996966

997967
if llvm_from_ci {
998968
let warn = |option: &str| {
@@ -1040,6 +1010,41 @@ impl Config {
10401010
build_target.llvm_filecheck = Some(ci_llvm_bin.join(exe("FileCheck", host_target)));
10411011
}
10421012

1013+
for (target, linker_override) in default_linux_linker_overrides() {
1014+
// If the user overrode the default Linux linker, do not apply bootstrap defaults
1015+
if targets_with_user_linker_override.contains(&target) {
1016+
continue;
1017+
}
1018+
1019+
let default_linux_linker_override = match linker_override {
1020+
DefaultLinuxLinkerOverride::Off => continue,
1021+
DefaultLinuxLinkerOverride::SelfContainedLldCc => {
1022+
// If we automatically default to the self-contained LLD linker,
1023+
// we also need to handle the rust.lld option.
1024+
match rust_lld_enabled {
1025+
// If LLD was not enabled explicitly, we enable it, unless LLVM config has
1026+
// been set
1027+
None if !is_host_system_llvm => {
1028+
lld_enabled = true;
1029+
Some(DefaultLinuxLinkerOverride::SelfContainedLldCc)
1030+
}
1031+
None => None,
1032+
// If it was enabled already, we don't need to do anything
1033+
Some(true) => Some(DefaultLinuxLinkerOverride::SelfContainedLldCc),
1034+
// If it was explicitly disabled, we do not apply the
1035+
// linker override
1036+
Some(false) => None,
1037+
}
1038+
}
1039+
};
1040+
if let Some(linker_override) = default_linux_linker_override {
1041+
target_config
1042+
.entry(TargetSelection::from_user(&target))
1043+
.or_default()
1044+
.default_linker_linux_override = linker_override;
1045+
}
1046+
}
1047+
10431048
let initial_rustfmt = build_rustfmt.or_else(|| maybe_download_rustfmt(&dwn_ctx, &out));
10441049

10451050
if matches!(bootstrap_override_lld, BootstrapOverrideLld::SelfContained)
@@ -1051,7 +1056,7 @@ impl Config {
10511056
);
10521057
}
10531058

1054-
if lld_enabled && is_system_llvm(&dwn_ctx, &target_config, llvm_from_ci, host_target) {
1059+
if lld_enabled && is_host_system_llvm {
10551060
panic!("Cannot enable LLD with `rust.lld = true` when using external llvm-config.");
10561061
}
10571062

@@ -1845,8 +1850,7 @@ impl Config {
18451850
///
18461851
/// NOTE: this is not the same as `!is_rust_llvm` when `llvm_has_patches` is set.
18471852
pub fn is_system_llvm(&self, target: TargetSelection) -> bool {
1848-
let dwn_ctx = DownloadContext::from(self);
1849-
is_system_llvm(dwn_ctx, &self.target_config, self.llvm_from_ci, target)
1853+
is_system_llvm(&self.target_config, self.llvm_from_ci, self.host_target, target)
18501854
}
18511855

18521856
/// Returns `true` if this is our custom, patched, version of LLVM.
@@ -2450,15 +2454,14 @@ pub fn submodules_(submodules: &Option<bool>, rust_info: &channel::GitInfo) -> b
24502454
///
24512455
/// NOTE: this is not the same as `!is_rust_llvm` when `llvm_has_patches` is set.
24522456
pub fn is_system_llvm<'a>(
2453-
dwn_ctx: impl AsRef<DownloadContext<'a>>,
24542457
target_config: &HashMap<TargetSelection, Target>,
24552458
llvm_from_ci: bool,
2459+
host_target: TargetSelection,
24562460
target: TargetSelection,
24572461
) -> bool {
2458-
let dwn_ctx = dwn_ctx.as_ref();
24592462
match target_config.get(&target) {
24602463
Some(Target { llvm_config: Some(_), .. }) => {
2461-
let ci_llvm = llvm_from_ci && is_host_target(&dwn_ctx.host_target, &target);
2464+
let ci_llvm = llvm_from_ci && is_host_target(&host_target, &target);
24622465
!ci_llvm
24632466
}
24642467
// We're building from the in-tree src/llvm-project sources.

0 commit comments

Comments
 (0)