Skip to content

Commit

Permalink
Only build the specified artifact library when multiple types are ava…
Browse files Browse the repository at this point in the history
…ilable
  • Loading branch information
skogseth committed May 2, 2024
1 parent e96424b commit a0e5a36
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/cargo/core/compiler/unit_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::core::compiler::unit_graph::{UnitDep, UnitGraph};
use crate::core::compiler::{
CompileKind, CompileMode, CrateType, RustcTargetData, Unit, UnitInterner,
};
use crate::core::dependency::{Artifact, ArtifactTarget, DepKind};
use crate::core::dependency::{Artifact, ArtifactKind, ArtifactTarget, DepKind};
use crate::core::profiles::{Profile, Profiles, UnitFor};
use crate::core::resolver::features::{FeaturesFor, ResolvedFeatures};
use crate::core::resolver::Resolve;
Expand Down Expand Up @@ -555,17 +555,20 @@ fn artifact_targets_to_unit_deps(
let ret =
match_artifacts_kind_with_targets(dep, artifact_pkg.targets(), parent.pkg.name().as_str())?
.into_iter()
.map(|(_artifact_kind, target)| target)
.flat_map(|target| {
.flat_map(|(artifact_kind, target)| {
// We split target libraries into individual units, even though rustc is able
// to produce multiple kinds in an single invocation for the sole reason that
// to produce multiple kinds in a single invocation for the sole reason that
// each artifact kind has its own output directory, something we can't easily
// teach rustc for now.
match target.kind() {
TargetKind::Lib(kinds) => Box::new(
kinds
.iter()
.filter(|tk| matches!(tk, CrateType::Cdylib | CrateType::Staticlib))
.filter(|tk| match tk {
CrateType::Cdylib => *artifact_kind == ArtifactKind::Cdylib,
CrateType::Staticlib => *artifact_kind == ArtifactKind::Staticlib,
_ => false,
})
.map(|target_kind| {
new_unit_dep(
state,
Expand Down

0 comments on commit a0e5a36

Please sign in to comment.