Skip to content

Commit 2907ab5

Browse files
committed
Move is_builder_target, is_system_llvm and is_rust_llvm from Builder to Config
1 parent f433fa4 commit 2907ab5

File tree

7 files changed

+57
-53
lines changed

7 files changed

+57
-53
lines changed

Diff for: src/bootstrap/src/core/build_steps/compile.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl Step for Std {
155155

156156
// When using `download-rustc`, we already have artifacts for the host available. Don't
157157
// recompile them.
158-
if builder.download_rustc() && builder.is_builder_target(target)
158+
if builder.download_rustc() && builder.config.is_builder_target(target)
159159
// NOTE: the beta compiler may generate different artifacts than the downloaded compiler, so
160160
// its artifacts can't be reused.
161161
&& compiler.stage != 0
@@ -229,7 +229,7 @@ impl Step for Std {
229229
// The LLD wrappers and `rust-lld` are self-contained linking components that can be
230230
// necessary to link the stdlib on some targets. We'll also need to copy these binaries to
231231
// the `stage0-sysroot` to ensure the linker is found when bootstrapping on such a target.
232-
if compiler.stage == 0 && builder.is_builder_target(compiler.host) {
232+
if compiler.stage == 0 && builder.config.is_builder_target(compiler.host) {
233233
trace!(
234234
"(build == host) copying linking components to `stage0-sysroot` for bootstrapping"
235235
);
@@ -1374,7 +1374,7 @@ pub fn rustc_cargo_env(
13741374
/// Pass down configuration from the LLVM build into the build of
13751375
/// rustc_llvm and rustc_codegen_llvm.
13761376
fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelection) {
1377-
if builder.is_rust_llvm(target) {
1377+
if builder.config.is_rust_llvm(target) {
13781378
cargo.env("LLVM_RUSTLLVM", "1");
13791379
}
13801380
if builder.config.llvm_enzyme {
@@ -2532,7 +2532,9 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
25322532
// FIXME: to make things simpler for now, limit this to the host and target where we know
25332533
// `strip -g` is both available and will fix the issue, i.e. on a x64 linux host that is not
25342534
// cross-compiling. Expand this to other appropriate targets in the future.
2535-
if target != "x86_64-unknown-linux-gnu" || !builder.is_builder_target(target) || !path.exists()
2535+
if target != "x86_64-unknown-linux-gnu"
2536+
|| !builder.config.is_builder_target(target)
2537+
|| !path.exists()
25362538
{
25372539
return;
25382540
}

Diff for: src/bootstrap/src/core/build_steps/dist.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ impl Step for DebuggerScripts {
612612
fn skip_host_target_lib(builder: &Builder<'_>, compiler: Compiler) -> bool {
613613
// The only true set of target libraries came from the build triple, so
614614
// let's reduce redundant work by only producing archives from that host.
615-
if !builder.is_builder_target(compiler.host) {
615+
if !builder.config.is_builder_target(compiler.host) {
616616
builder.info("\tskipping, not a build host");
617617
true
618618
} else {
@@ -671,7 +671,9 @@ fn copy_target_libs(
671671
&self_contained_dst.join(path.file_name().unwrap()),
672672
FileType::NativeLibrary,
673673
);
674-
} else if dependency_type == DependencyType::Target || builder.is_builder_target(target) {
674+
} else if dependency_type == DependencyType::Target
675+
|| builder.config.is_builder_target(target)
676+
{
675677
builder.copy_link(&path, &dst.join(path.file_name().unwrap()), FileType::NativeLibrary);
676678
}
677679
}
@@ -824,7 +826,7 @@ impl Step for Analysis {
824826
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
825827
let compiler = self.compiler;
826828
let target = self.target;
827-
if !builder.is_builder_target(compiler.host) {
829+
if !builder.config.is_builder_target(compiler.host) {
828830
return None;
829831
}
830832

@@ -2118,7 +2120,7 @@ fn maybe_install_llvm(
21182120
//
21192121
// If the LLVM is coming from ourselves (just from CI) though, we
21202122
// still want to install it, as it otherwise won't be available.
2121-
if builder.is_system_llvm(target) {
2123+
if builder.config.is_system_llvm(target) {
21222124
trace!("system LLVM requested, no install");
21232125
return false;
21242126
}

Diff for: src/bootstrap/src/core/build_steps/llvm.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ impl Step for Llvm {
485485
}
486486

487487
// https://llvm.org/docs/HowToCrossCompileLLVM.html
488-
if !builder.is_builder_target(target) {
488+
if !builder.config.is_builder_target(target) {
489489
let LlvmResult { llvm_config, .. } =
490490
builder.ensure(Llvm { target: builder.config.build });
491491
if !builder.config.dry_run() {
@@ -637,7 +637,7 @@ fn configure_cmake(
637637
}
638638
cfg.target(&target.triple).host(&builder.config.build.triple);
639639

640-
if !builder.is_builder_target(target) {
640+
if !builder.config.is_builder_target(target) {
641641
cfg.define("CMAKE_CROSSCOMPILING", "True");
642642

643643
// NOTE: Ideally, we wouldn't have to do this, and `cmake-rs` would just handle it for us.
@@ -1098,7 +1098,7 @@ impl Step for Lld {
10981098
.define("LLVM_CMAKE_DIR", llvm_cmake_dir)
10991099
.define("LLVM_INCLUDE_TESTS", "OFF");
11001100

1101-
if !builder.is_builder_target(target) {
1101+
if !builder.config.is_builder_target(target) {
11021102
// Use the host llvm-tblgen binary.
11031103
cfg.define(
11041104
"LLVM_TABLEGEN_EXE",

Diff for: src/bootstrap/src/core/build_steps/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1894,7 +1894,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
18941894
.arg(llvm_components.trim());
18951895
llvm_components_passed = true;
18961896
}
1897-
if !builder.is_rust_llvm(target) {
1897+
if !builder.config.is_rust_llvm(target) {
18981898
cmd.arg("--system-llvm");
18991899
}
19001900

@@ -2668,7 +2668,7 @@ impl Step for Crate {
26682668
cargo
26692669
} else {
26702670
// Also prepare a sysroot for the target.
2671-
if !builder.is_builder_target(target) {
2671+
if !builder.config.is_builder_target(target) {
26722672
builder.ensure(compile::Std::new(compiler, target).force_recompile(true));
26732673
builder.ensure(RemoteCopyLibs { compiler, target });
26742674
}

Diff for: src/bootstrap/src/core/config/config.rs

+36
Original file line numberDiff line numberDiff line change
@@ -3233,6 +3233,42 @@ impl Config {
32333233

32343234
Some(commit.to_string())
32353235
}
3236+
3237+
/// Checks if the given target is the same as the builder target.
3238+
pub fn is_builder_target(&self, target: TargetSelection) -> bool {
3239+
self.build == target
3240+
}
3241+
3242+
/// Returns `true` if this is an external version of LLVM not managed by bootstrap.
3243+
/// In particular, we expect llvm sources to be available when this is false.
3244+
///
3245+
/// NOTE: this is not the same as `!is_rust_llvm` when `llvm_has_patches` is set.
3246+
pub fn is_system_llvm(&self, target: TargetSelection) -> bool {
3247+
match self.target_config.get(&target) {
3248+
Some(Target { llvm_config: Some(_), .. }) => {
3249+
let ci_llvm = self.llvm_from_ci && self.is_builder_target(target);
3250+
!ci_llvm
3251+
}
3252+
// We're building from the in-tree src/llvm-project sources.
3253+
Some(Target { llvm_config: None, .. }) => false,
3254+
None => false,
3255+
}
3256+
}
3257+
3258+
/// Returns `true` if this is our custom, patched, version of LLVM.
3259+
///
3260+
/// This does not necessarily imply that we're managing the `llvm-project` submodule.
3261+
pub fn is_rust_llvm(&self, target: TargetSelection) -> bool {
3262+
match self.target_config.get(&target) {
3263+
// We're using a user-controlled version of LLVM. The user has explicitly told us whether the version has our patches.
3264+
// (They might be wrong, but that's not a supported use-case.)
3265+
// In particular, this tries to support `submodules = false` and `patches = false`, for using a newer version of LLVM that's not through `rust-lang/llvm-project`.
3266+
Some(Target { llvm_has_rust_patches: Some(patched), .. }) => *patched,
3267+
// The user hasn't promised the patches match.
3268+
// This only has our patches if it's downloaded from CI or built from source.
3269+
_ => !self.is_system_llvm(target),
3270+
}
3271+
}
32363272
}
32373273

32383274
/// Compares the current `Llvm` options against those in the CI LLVM builder and detects any incompatible options.

Diff for: src/bootstrap/src/core/sanity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ than building it.
325325
if target.contains("musl") && !target.contains("unikraft") {
326326
// If this is a native target (host is also musl) and no musl-root is given,
327327
// fall back to the system toolchain in /usr before giving up
328-
if build.musl_root(*target).is_none() && build.is_builder_target(*target) {
328+
if build.musl_root(*target).is_none() && build.config.is_builder_target(*target) {
329329
let target = build.config.target_config.entry(*target).or_default();
330330
target.musl_root = Some("/usr".into());
331331
}

Diff for: src/bootstrap/src/lib.rs

+3-39
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use utils::channel::GitInfo;
3535

3636
use crate::core::builder;
3737
use crate::core::builder::Kind;
38-
use crate::core::config::{DryRun, LldMode, LlvmLibunwind, Target, TargetSelection, flags};
38+
use crate::core::config::{DryRun, LldMode, LlvmLibunwind, TargetSelection, flags};
3939
use crate::utils::exec::{BehaviorOnFailure, BootstrapCommand, CommandOutput, OutputMode, command};
4040
use crate::utils::helpers::{
4141
self, dir_is_empty, exe, libdir, output, set_file_times, split_debuginfo, symlink_dir,
@@ -803,7 +803,7 @@ impl Build {
803803
/// Note that if LLVM is configured externally then the directory returned
804804
/// will likely be empty.
805805
fn llvm_out(&self, target: TargetSelection) -> PathBuf {
806-
if self.config.llvm_from_ci && self.is_builder_target(target) {
806+
if self.config.llvm_from_ci && self.config.is_builder_target(target) {
807807
self.config.ci_llvm_root()
808808
} else {
809809
self.out.join(target).join("llvm")
@@ -851,37 +851,6 @@ impl Build {
851851
if self.config.vendor { Some(self.src.join(VENDOR_DIR)) } else { None }
852852
}
853853

854-
/// Returns `true` if this is an external version of LLVM not managed by bootstrap.
855-
/// In particular, we expect llvm sources to be available when this is false.
856-
///
857-
/// NOTE: this is not the same as `!is_rust_llvm` when `llvm_has_patches` is set.
858-
fn is_system_llvm(&self, target: TargetSelection) -> bool {
859-
match self.config.target_config.get(&target) {
860-
Some(Target { llvm_config: Some(_), .. }) => {
861-
let ci_llvm = self.config.llvm_from_ci && self.is_builder_target(target);
862-
!ci_llvm
863-
}
864-
// We're building from the in-tree src/llvm-project sources.
865-
Some(Target { llvm_config: None, .. }) => false,
866-
None => false,
867-
}
868-
}
869-
870-
/// Returns `true` if this is our custom, patched, version of LLVM.
871-
///
872-
/// This does not necessarily imply that we're managing the `llvm-project` submodule.
873-
fn is_rust_llvm(&self, target: TargetSelection) -> bool {
874-
match self.config.target_config.get(&target) {
875-
// We're using a user-controlled version of LLVM. The user has explicitly told us whether the version has our patches.
876-
// (They might be wrong, but that's not a supported use-case.)
877-
// In particular, this tries to support `submodules = false` and `patches = false`, for using a newer version of LLVM that's not through `rust-lang/llvm-project`.
878-
Some(Target { llvm_has_rust_patches: Some(patched), .. }) => *patched,
879-
// The user hasn't promised the patches match.
880-
// This only has our patches if it's downloaded from CI or built from source.
881-
_ => !self.is_system_llvm(target),
882-
}
883-
}
884-
885854
/// Returns the path to `FileCheck` binary for the specified target
886855
fn llvm_filecheck(&self, target: TargetSelection) -> PathBuf {
887856
let target_config = self.config.target_config.get(&target);
@@ -1356,7 +1325,7 @@ Executed at: {executed_at}"#,
13561325
// need to use CXX compiler as linker to resolve the exception functions
13571326
// that are only existed in CXX libraries
13581327
Some(self.cxx.borrow()[&target].path().into())
1359-
} else if !self.is_builder_target(target)
1328+
} else if !self.config.is_builder_target(target)
13601329
&& helpers::use_host_linker(target)
13611330
&& !target.is_msvc()
13621331
{
@@ -2025,11 +1994,6 @@ to download LLVM rather than building it.
20251994
stream.reset().unwrap();
20261995
result
20271996
}
2028-
2029-
/// Checks if the given target is the same as the builder target.
2030-
fn is_builder_target(&self, target: TargetSelection) -> bool {
2031-
self.config.build == target
2032-
}
20331997
}
20341998

20351999
#[cfg(unix)]

0 commit comments

Comments
 (0)