@@ -6,8 +6,9 @@ use crate::core::dependency::DepKind;
66use crate :: core:: resolver:: Resolve ;
77use crate :: core:: resolver:: features:: { CliFeatures , FeaturesFor , ResolvedFeatures } ;
88use crate :: core:: { FeatureMap , FeatureValue , Package , PackageId , PackageIdSpec , Workspace } ;
9- use crate :: util:: CargoResult ;
109use crate :: util:: interning:: { INTERNED_DEFAULT , InternedString } ;
10+ use crate :: util:: { CargoResult , OptVersionReq } ;
11+ use std:: cmp:: Ordering ;
1112use std:: collections:: { HashMap , HashSet } ;
1213
1314#[ derive( Debug , Copy , Clone ) ]
@@ -49,14 +50,34 @@ impl std::hash::Hash for NodeId {
4950 }
5051}
5152
53+ #[ derive( Debug , Clone , Eq , PartialEq , Hash ) ]
54+ pub struct NodePackage {
55+ pub package_id : PackageId ,
56+ /// Features that are enabled on this package.
57+ pub features : Vec < InternedString > ,
58+ pub kind : CompileKind ,
59+ pub version_req : OptVersionReq ,
60+ }
61+
62+ impl PartialOrd for NodePackage {
63+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
64+ Some ( self . cmp ( other) )
65+ }
66+ }
67+
68+ impl Ord for NodePackage {
69+ fn cmp ( & self , other : & Self ) -> Ordering {
70+ self . package_id
71+ . cmp ( & other. package_id )
72+ . then_with ( || self . features . cmp ( & other. features ) )
73+ . then_with ( || self . kind . cmp ( & other. kind ) )
74+ // version_req is not orderable
75+ }
76+ }
77+
5278#[ derive( Debug , Clone , Eq , PartialEq , Hash , Ord , PartialOrd ) ]
5379pub enum Node {
54- Package {
55- package_id : PackageId ,
56- /// Features that are enabled on this package.
57- features : Vec < InternedString > ,
58- kind : CompileKind ,
59- } ,
80+ Package ( NodePackage ) ,
6081 Feature {
6182 /// Index of the package node this feature is for.
6283 node_index : NodeId ,
@@ -68,7 +89,7 @@ pub enum Node {
6889impl Node {
6990 fn name ( & self ) -> InternedString {
7091 match self {
71- Self :: Package { package_id, .. } => package_id. name ( ) ,
92+ Self :: Package ( NodePackage { package_id, .. } ) => package_id. name ( ) ,
7293 Self :: Feature { name, .. } => * name,
7394 }
7495 }
@@ -218,7 +239,7 @@ impl<'a> Graph<'a> {
218239 . iter ( )
219240 . enumerate ( )
220241 . filter ( |( _i, node) | match node {
221- Node :: Package { package_id, .. } => package_ids. contains ( package_id) ,
242+ Node :: Package ( NodePackage { package_id, .. } ) => package_ids. contains ( package_id) ,
222243 _ => false ,
223244 } )
224245 . map ( |( i, node) | ( node, NodeId :: new ( i, node. name ( ) ) ) )
@@ -235,7 +256,7 @@ impl<'a> Graph<'a> {
235256
236257 fn package_id_for_index ( & self , index : NodeId ) -> PackageId {
237258 match self . node ( index) {
238- Node :: Package { package_id, .. } => * package_id,
259+ Node :: Package ( NodePackage { package_id, .. } ) => * package_id,
239260 Node :: Feature { .. } => panic ! ( "unexpected feature node" ) ,
240261 }
241262 }
@@ -314,7 +335,7 @@ impl<'a> Graph<'a> {
314335 // Collect a map of package name to Vec<(&Node, NodeId)>.
315336 let mut packages = HashMap :: new ( ) ;
316337 for ( i, node) in self . nodes . iter ( ) . enumerate ( ) {
317- if let Node :: Package { package_id, .. } = node {
338+ if let Node :: Package ( NodePackage { package_id, .. } ) = node {
318339 packages
319340 . entry ( package_id. name ( ) )
320341 . or_insert_with ( Vec :: new)
@@ -329,17 +350,19 @@ impl<'a> Graph<'a> {
329350 . into_iter ( )
330351 . map ( |( node, _) | {
331352 match node {
332- Node :: Package {
353+ Node :: Package ( NodePackage {
333354 package_id,
334355 features,
356+ version_req,
335357 ..
336- } => {
358+ } ) => {
337359 // Do not treat duplicates on the host or target as duplicates.
338- Node :: Package {
360+ Node :: Package ( NodePackage {
339361 package_id : package_id. clone ( ) ,
340362 features : features. clone ( ) ,
341363 kind : CompileKind :: Host ,
342- }
364+ version_req : version_req. clone ( ) ,
365+ } )
343366 }
344367 _ => unreachable ! ( ) ,
345368 }
@@ -376,12 +399,14 @@ pub fn build<'a>(
376399 let member_id = member. package_id ( ) ;
377400 let features_for = FeaturesFor :: from_for_host ( member. proc_macro ( ) ) ;
378401 for kind in requested_kinds {
402+ let version_req = OptVersionReq :: Any ;
379403 let member_index = add_pkg (
380404 & mut graph,
381405 resolve,
382406 resolved_features,
383407 member_id,
384408 features_for,
409+ version_req,
385410 target_data,
386411 * kind,
387412 opts,
@@ -409,6 +434,7 @@ fn add_pkg(
409434 resolved_features : & ResolvedFeatures ,
410435 package_id : PackageId ,
411436 features_for : FeaturesFor ,
437+ version_req : OptVersionReq ,
412438 target_data : & RustcTargetData < ' _ > ,
413439 requested_kind : CompileKind ,
414440 opts : & TreeOptions ,
@@ -419,11 +445,12 @@ fn add_pkg(
419445 FeaturesFor :: ArtifactDep ( target) => CompileKind :: Target ( target) ,
420446 FeaturesFor :: NormalOrDev => requested_kind,
421447 } ;
422- let node = Node :: Package {
448+ let node = Node :: Package ( NodePackage {
423449 package_id,
424450 features : node_features,
425451 kind : node_kind,
426- } ;
452+ version_req : version_req,
453+ } ) ;
427454 if let Some ( idx) = graph. index . get ( & node) {
428455 return * idx;
429456 }
@@ -513,12 +540,14 @@ fn add_pkg(
513540 }
514541 }
515542 } ;
543+ let dep_version_req = dep. version_req ( ) . clone ( ) ;
516544 let dep_index = add_pkg (
517545 graph,
518546 resolve,
519547 resolved_features,
520548 dep_id,
521549 dep_features_for,
550+ dep_version_req,
522551 target_data,
523552 requested_kind,
524553 opts,
0 commit comments