Rollup 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:
Michael Goulet 2024-09-07 14:21:18 +03:00 committed by GitHub
commit 5a2ebb58c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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);
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.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) {
let targets: HashSet<_> = match build.config.cmd {
// We don't need to check cross targets for these commands.
crate::Subcommand::Clean { .. }
| crate::Subcommand::Check { .. }
| crate::Subcommand::Suggest { .. }
| crate::Subcommand::Format { .. }
| crate::Subcommand::Setup { .. } => {
build.hosts.iter().cloned().chain(iter::once(build.build)).collect()
}
_ => {
// For all targets we're going to need a C compiler for building some shims // 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. // and such as well as for being a linker for Rust code.
let targets = build build
.targets .targets
.iter() .iter()
.chain(&build.hosts) .chain(&build.hosts)
.cloned() .cloned()
.chain(iter::once(build.build)) .chain(iter::once(build.build))
.collect::<HashSet<_>>(); .collect()
}
};
for target in targets.into_iter() { for target in targets.into_iter() {
find_target(build, target); find_target(build, target);
} }