Auto merge of #128871 - onur-ozkan:128180, r=Kobzol

bypass linker configuration and cross target check for specific commands

Avoids configuring the linker and checking cross-target-specific tools unless necessary.

Resolves #128180

cc `@ChrisDenton`
This commit is contained in:
bors 2024-09-07 13:21:44 +00:00
commit 7468b6907c
2 changed files with 32 additions and 10 deletions

View File

@ -2463,7 +2463,15 @@ pub fn new(
cmd_kind: Kind, cmd_kind: Kind,
) -> Cargo { ) -> Cargo {
let mut cargo = builder.cargo(compiler, mode, source_type, target, cmd_kind); let mut cargo = builder.cargo(compiler, mode, source_type, target, cmd_kind);
cargo.configure_linker(builder);
match cmd_kind {
// No need to configure the target linker for these command types.
Kind::Clean | Kind::Check | Kind::Suggest | Kind::Format | Kind::Setup => {}
_ => {
cargo.configure_linker(builder);
}
}
cargo cargo
} }

View File

@ -87,15 +87,29 @@ fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build {
} }
pub fn find(build: &Build) { pub fn find(build: &Build) {
// For all targets we're going to need a C compiler for building some shims let targets: HashSet<_> = match build.config.cmd {
// and such as well as for being a linker for Rust code. // We don't need to check cross targets for these commands.
let targets = build crate::Subcommand::Clean { .. }
.targets | crate::Subcommand::Check { .. }
.iter() | crate::Subcommand::Suggest { .. }
.chain(&build.hosts) | crate::Subcommand::Format { .. }
.cloned() | crate::Subcommand::Setup { .. } => {
.chain(iter::once(build.build)) build.hosts.iter().cloned().chain(iter::once(build.build)).collect()
.collect::<HashSet<_>>(); }
_ => {
// For all targets we're going to need a C compiler for building some shims
// and such as well as for being a linker for Rust code.
build
.targets
.iter()
.chain(&build.hosts)
.cloned()
.chain(iter::once(build.build))
.collect()
}
};
for target in targets.into_iter() { for target in targets.into_iter() {
find_target(build, target); find_target(build, target);
} }