From 22730094535187527af573ad5f57acad2c900d1b Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Thu, 4 May 2023 13:02:47 +0000 Subject: [PATCH] format and call `merge_compile_kind` inside `collect_used_deps` --- src/cargo/core/package.rs | 20 ++++++++++++++++---- src/cargo/ops/resolve.rs | 2 +- tests/testsuite/artifact_dep.rs | 5 +++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index 5f88fdcf619..02dc6310747 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -494,7 +494,7 @@ impl<'cfg> PackageSet<'cfg> { root_ids: &[PackageId], has_dev_units: HasDevUnits, requested_kinds: &[CompileKind], - target_data: &RustcTargetData<'cfg>, + target_data: &mut RustcTargetData<'cfg>, force_all_targets: ForceAllTargets, ) -> CargoResult<()> { fn collect_used_deps( @@ -503,7 +503,7 @@ impl<'cfg> PackageSet<'cfg> { pkg_id: PackageId, has_dev_units: HasDevUnits, requested_kinds: &[CompileKind], - target_data: &RustcTargetData<'_>, + target_data: &mut RustcTargetData<'_>, force_all_targets: ForceAllTargets, additional_kinds: Vec, ) -> CargoResult<()> { @@ -515,11 +515,23 @@ impl<'cfg> PackageSet<'cfg> { resolve, has_dev_units, requested_kinds, - target_data, + &*target_data, force_all_targets, &additional_kinds, ); - for (pkg_id, _dep, additional_kinds) in filtered_deps { + + let deps = filtered_deps + .map(|(pkg_id, _dep, additional_kinds)| (pkg_id, additional_kinds)) + .collect::>(); + + for (pkg_id, additional_kinds) in deps { + // The dependency can specify additional targets through artifact dependencies. + // We need to run `rustc` to query the target specific configuration before we look + // at this dependency's dependencies. + for kind in &additional_kinds { + target_data.merge_compile_kind(*kind)?; + } + collect_used_deps( used, resolve, diff --git a/src/cargo/ops/resolve.rs b/src/cargo/ops/resolve.rs index b380ea83f16..650ef0ff4ba 100644 --- a/src/cargo/ops/resolve.rs +++ b/src/cargo/ops/resolve.rs @@ -198,7 +198,7 @@ pub fn resolve_ws_with_opts<'cfg>( &member_ids, has_dev_units, requested_targets, - &*target_data, + &mut *target_data, force_all_targets, )?; diff --git a/tests/testsuite/artifact_dep.rs b/tests/testsuite/artifact_dep.rs index 88bc8d9c135..20862875876 100644 --- a/tests/testsuite/artifact_dep.rs +++ b/tests/testsuite/artifact_dep.rs @@ -2905,9 +2905,10 @@ fn check_transitive_artifact_dependency_with_different_target() { .masquerade_as_nightly_cargo(&["bindeps"]) .with_stderr_contains( "error: failed to run `rustc` to learn about target-specific information", - ).with_stderr_contains( + ) + .with_stderr_contains( "[..] error: Error loading target specification: Could not find specification for \ - target \"custom-target\". [..]" + target \"custom-target\". [..]", ) .with_status(101) .run();