@@ -56,12 +56,11 @@ type ActivateMap = HashMap<PackageFeaturesKey, BTreeSet<InternedString>>;
5656
5757/// Set of all activated features for all packages in the resolve graph.
5858pub struct ResolvedFeatures {
59- /// Map of features activated for each package.
60- ///
61- /// The presence of each key also means the package itself is activated,
62- /// even its associated set contains no features.
6359 activated_features : ActivateMap ,
64- /// Options that change how the feature resolver operates.
60+ /// Optional dependencies that should be built.
61+ ///
62+ /// The value is the `name_in_toml` of the dependencies.
63+ activated_dependencies : ActivateMap ,
6564 opts : FeatureOpts ,
6665}
6766
@@ -322,14 +321,21 @@ impl ResolvedFeatures {
322321 . expect ( "activated_features for invalid package" )
323322 }
324323
325- /// Asks the resolved features if the given package should be included.
324+ /// Returns if the given dependency should be included.
326325 ///
327- /// One scenario to use this function is to deteremine a optional dependency
328- /// should be built or not.
329- pub fn is_activated ( & self , pkg_id : PackageId , features_for : FeaturesFor ) -> bool {
330- log:: trace!( "is_activated {} {features_for}" , pkg_id. name( ) ) ;
331- self . activated_features_unverified ( pkg_id, features_for. apply_opts ( & self . opts ) )
332- . is_some ( )
326+ /// This handles dependencies disabled via `cfg` expressions and optional
327+ /// dependencies which are not enabled.
328+ pub fn is_dep_activated (
329+ & self ,
330+ pkg_id : PackageId ,
331+ features_for : FeaturesFor ,
332+ dep_name : InternedString ,
333+ ) -> bool {
334+ let key = features_for. apply_opts ( & self . opts ) ;
335+ self . activated_dependencies
336+ . get ( & ( pkg_id, key) )
337+ . map ( |deps| deps. contains ( & dep_name) )
338+ . unwrap_or ( false )
333339 }
334340
335341 /// Variant of `activated_features` that returns `None` if this is
@@ -409,14 +415,8 @@ pub struct FeatureResolver<'a, 'cfg> {
409415 /// Options that change how the feature resolver operates.
410416 opts : FeatureOpts ,
411417 /// Map of features activated for each package.
412- ///
413- /// The presence of each key also means the package itself is activated,
414- /// even its associated set contains no features.
415418 activated_features : ActivateMap ,
416419 /// Map of optional dependencies activated for each package.
417- ///
418- /// The key is the package having their dependencies activated.
419- /// The value comes from `dep_name` part of the feature syntax `dep:dep_name`.
420420 activated_dependencies : ActivateMap ,
421421 /// Keeps track of which packages have had its dependencies processed.
422422 /// Used to avoid cycles, and to speed up processing.
@@ -475,6 +475,7 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
475475 }
476476 Ok ( ResolvedFeatures {
477477 activated_features : r. activated_features ,
478+ activated_dependencies : r. activated_dependencies ,
478479 opts : r. opts ,
479480 } )
480481 }
@@ -506,24 +507,20 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
506507 Ok ( ( ) )
507508 }
508509
509- /// Activates a list of [`FeatureValue`] for a given package.
510+ /// Activates [`FeatureValue`]s on the given package.
510511 ///
511- /// This is the main entrance into the recursion of feature activation for a package.
512- /// Other `activate_*` functions would be called inside this function accordingly .
512+ /// This is the main entrance into the recursion of feature activation
513+ /// for a package .
513514 fn activate_pkg (
514515 & mut self ,
515516 pkg_id : PackageId ,
516517 fk : FeaturesFor ,
517518 fvs : & [ FeatureValue ] ,
518519 ) -> CargoResult < ( ) > {
519520 log:: trace!( "activate_pkg {} {}" , pkg_id. name( ) , fk) ;
520- // Cargo must insert an empty set here as the presence of an (empty) set
521- // also means that the dependency is activated.
522- // This `is_activated` behavior for dependencies was previously depends on field
523- // `activated_dependencies`, which is less useful after rust-lang/cargo#11183.
524- //
525- // That is, we may keep or remove `activated_dependencies` in the future
526- // if figuring out it can completely be replaced with `activated_features`.
521+ // Add an empty entry to ensure everything is covered. This is intended for
522+ // finding bugs where the resolver missed something it should have visited.
523+ // Remove this in the future if `activated_features` uses an empty default.
527524 self . activated_features
528525 . entry ( ( pkg_id, fk. apply_opts ( & self . opts ) ) )
529526 . or_insert_with ( BTreeSet :: new) ;
0 commit comments