Skip to content

Commit 9a5cfbc

Browse files
committed
Only build the specified artifact library when multiple types are available
1 parent 845d376 commit 9a5cfbc

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/cargo/core/compiler/unit_dependencies.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::core::compiler::unit_graph::{UnitDep, UnitGraph};
2424
use crate::core::compiler::{
2525
CompileKind, CompileMode, CrateType, RustcTargetData, Unit, UnitInterner,
2626
};
27-
use crate::core::dependency::{Artifact, ArtifactTarget, DepKind};
27+
use crate::core::dependency::{Artifact, ArtifactKind, ArtifactTarget, DepKind};
2828
use crate::core::profiles::{Profile, Profiles, UnitFor};
2929
use crate::core::resolver::features::{FeaturesFor, ResolvedFeatures};
3030
use crate::core::resolver::Resolve;
@@ -555,17 +555,20 @@ fn artifact_targets_to_unit_deps(
555555
let ret =
556556
match_artifacts_kind_with_targets(dep, artifact_pkg.targets(), parent.pkg.name().as_str())?
557557
.into_iter()
558-
.map(|(_artifact_kind, target)| target)
559-
.flat_map(|target| {
558+
.flat_map(|(artifact_kind, target)| {
560559
// We split target libraries into individual units, even though rustc is able
561-
// to produce multiple kinds in an single invocation for the sole reason that
560+
// to produce multiple kinds in a single invocation for the sole reason that
562561
// each artifact kind has its own output directory, something we can't easily
563562
// teach rustc for now.
564563
match target.kind() {
565564
TargetKind::Lib(kinds) => Box::new(
566565
kinds
567566
.iter()
568-
.filter(|tk| matches!(tk, CrateType::Cdylib | CrateType::Staticlib))
567+
.filter(move |tk| match (tk, artifact_kind) {
568+
(CrateType::Cdylib, ArtifactKind::Cdylib) => true,
569+
(CrateType::Staticlib, ArtifactKind::Staticlib) => true,
570+
_ => false,
571+
})
569572
.map(|target_kind| {
570573
new_unit_dep(
571574
state,

tests/testsuite/artifact_dep.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3241,7 +3241,7 @@ fn build_only_specified_artifact_library() {
32413241
.masquerade_as_nightly_cargo(&["bindeps"])
32423242
.run();
32433243
match_exact(
3244-
"cdylib present: true\nstaticlib present: true",
3244+
"cdylib present: true\nstaticlib present: false",
32453245
&build_script_output_string(&cdylib, "foo"),
32463246
"build script output",
32473247
"",
@@ -3255,7 +3255,7 @@ fn build_only_specified_artifact_library() {
32553255
.masquerade_as_nightly_cargo(&["bindeps"])
32563256
.run();
32573257
match_exact(
3258-
"cdylib present: true\nstaticlib present: true",
3258+
"cdylib present: false\nstaticlib present: true",
32593259
&build_script_output_string(&staticlib, "foo"),
32603260
"build script output",
32613261
"",

0 commit comments

Comments
 (0)