@@ -505,6 +505,7 @@ impl<'cfg> PackageSet<'cfg> {
505505 requested_kinds : & [ CompileKind ] ,
506506 target_data : & RustcTargetData < ' _ > ,
507507 force_all_targets : ForceAllTargets ,
508+ additional_kinds : Vec < CompileKind > ,
508509 ) -> CargoResult < ( ) > {
509510 if !used. insert ( pkg_id) {
510511 return Ok ( ( ) ) ;
@@ -516,8 +517,9 @@ impl<'cfg> PackageSet<'cfg> {
516517 requested_kinds,
517518 target_data,
518519 force_all_targets,
520+ & additional_kinds,
519521 ) ;
520- for ( pkg_id, _dep) in filtered_deps {
522+ for ( pkg_id, _dep, additional_kinds ) in filtered_deps {
521523 collect_used_deps (
522524 used,
523525 resolve,
@@ -526,6 +528,7 @@ impl<'cfg> PackageSet<'cfg> {
526528 requested_kinds,
527529 target_data,
528530 force_all_targets,
531+ additional_kinds,
529532 ) ?;
530533 }
531534 Ok ( ( ) )
@@ -545,6 +548,7 @@ impl<'cfg> PackageSet<'cfg> {
545548 requested_kinds,
546549 target_data,
547550 force_all_targets,
551+ Vec :: new ( ) ,
548552 ) ?;
549553 }
550554 self . get_many ( to_download. into_iter ( ) ) ?;
@@ -573,13 +577,14 @@ impl<'cfg> PackageSet<'cfg> {
573577 requested_kinds,
574578 target_data,
575579 force_all_targets,
580+ & [ ] ,
576581 )
577582 . collect ( ) ;
578583
579584 let dep_pkgs_and_deps = dep_pkgs_to_deps
580585 . into_iter ( )
581- . filter ( |( _id, deps) | deps. iter ( ) . any ( |dep| dep. maybe_lib ( ) ) )
582- . filter_map ( |( dep_package_id, deps) | {
586+ . filter ( |( _id, deps, _additional_kinds ) | deps. iter ( ) . any ( |dep| dep. maybe_lib ( ) ) )
587+ . filter_map ( |( dep_package_id, deps, _additional_kinds ) | {
583588 self . get_one ( dep_package_id) . ok ( ) . and_then ( |dep_pkg| {
584589 ( !dep_pkg. targets ( ) . iter ( ) . any ( |t| t. is_lib ( ) ) ) . then ( || ( dep_pkg, deps) )
585590 } )
@@ -607,32 +612,53 @@ impl<'cfg> PackageSet<'cfg> {
607612 Ok ( ( ) )
608613 }
609614
615+ /// Returns an iterator over the dependencies of `pkg_id`, while filtering out target-specific
616+ /// dependencies that are not enabled. Additionally returns a list of additional targets
617+ /// specified through an artifact dependency.
610618 fn filter_deps < ' a > (
611619 pkg_id : PackageId ,
612620 resolve : & ' a Resolve ,
613621 has_dev_units : HasDevUnits ,
614622 requested_kinds : & ' a [ CompileKind ] ,
615623 target_data : & ' a RustcTargetData < ' _ > ,
616624 force_all_targets : ForceAllTargets ,
617- ) -> impl Iterator < Item = ( PackageId , & ' a HashSet < Dependency > ) > + ' a {
625+ additional_kinds : & ' a [ CompileKind ] ,
626+ ) -> impl Iterator < Item = ( PackageId , & ' a HashSet < Dependency > , Vec < CompileKind > ) > + ' a {
618627 resolve
619628 . deps ( pkg_id)
620- . filter ( move |& ( _id, deps) | {
621- deps. iter ( ) . any ( |dep| {
622- if dep. kind ( ) == DepKind :: Development && has_dev_units == HasDevUnits :: No {
623- return false ;
624- }
625- if force_all_targets == ForceAllTargets :: No {
626- let activated = requested_kinds
627- . iter ( )
628- . chain ( Some ( & CompileKind :: Host ) )
629- . any ( |kind| target_data. dep_platform_activated ( dep, * kind) ) ;
630- if !activated {
629+ . filter_map ( move |( id, deps) | {
630+ let mut deps_iter = deps
631+ . iter ( )
632+ . filter ( |dep| {
633+ if dep. kind ( ) == DepKind :: Development && has_dev_units == HasDevUnits :: No {
631634 return false ;
632635 }
633- }
634- true
635- } )
636+ if force_all_targets == ForceAllTargets :: No {
637+ let activated = requested_kinds
638+ . iter ( )
639+ . chain ( Some ( & CompileKind :: Host ) )
640+ . chain ( additional_kinds)
641+ . any ( |kind| target_data. dep_platform_activated ( dep, * kind) ) ;
642+ if !activated {
643+ return false ;
644+ }
645+ }
646+ true
647+ } )
648+ . peekable ( ) ;
649+
650+ if deps_iter. peek ( ) . is_some ( ) {
651+ Some ( (
652+ id,
653+ deps,
654+ deps_iter. filter_map ( |dep| dep. artifact ( ) )
655+ . filter_map ( |artifact| artifact. target ( ) )
656+ . filter_map ( |target| target. to_compile_kind ( ) )
657+ . collect ( ) ,
658+ ) )
659+ } else {
660+ None
661+ }
636662 } )
637663 . into_iter ( )
638664 }
0 commit comments