@@ -107,13 +107,25 @@ mod types;
107
107
///
108
108
/// * `print_warnings` - whether or not to print backwards-compatibility
109
109
/// warnings and such
110
+ ///
111
+ /// * `check_public_visible_dependencies` - a flag for whether to enforce the restrictions
112
+ /// introduced in the "public & private dependencies" RFC (1977). The current implementation
113
+ /// makes sure that there is only one version of each name visible to each package.
114
+ ///
115
+ /// But there are 2 stable ways to directly depend on different versions of the same name.
116
+ /// 1. Use the renamed dependencies functionality
117
+ /// 2. Use 'cfg({})' dependencies functionality
118
+ ///
119
+ /// When we have a decision for how to implement is without breaking existing functionality
120
+ /// this flag can be removed.
110
121
pub fn resolve (
111
122
summaries : & [ ( Summary , Method < ' _ > ) ] ,
112
123
replacements : & [ ( PackageIdSpec , Dependency ) ] ,
113
124
registry : & mut dyn Registry ,
114
125
try_to_use : & HashSet < PackageId > ,
115
126
config : Option < & Config > ,
116
127
print_warnings : bool ,
128
+ check_public_visible_dependencies : bool ,
117
129
) -> CargoResult < Resolve > {
118
130
let cx = Context :: new ( ) ;
119
131
let _p = profile:: start ( "resolving" ) ;
@@ -122,7 +134,13 @@ pub fn resolve(
122
134
None => false ,
123
135
} ;
124
136
let mut registry = RegistryQueryer :: new ( registry, replacements, try_to_use, minimal_versions) ;
125
- let cx = activate_deps_loop ( cx, & mut registry, summaries, config) ?;
137
+ let cx = activate_deps_loop (
138
+ cx,
139
+ & mut registry,
140
+ summaries,
141
+ config,
142
+ check_public_visible_dependencies,
143
+ ) ?;
126
144
127
145
let mut cksums = HashMap :: new ( ) ;
128
146
for summary in cx. activations . values ( ) . flat_map ( |v| v. iter ( ) ) {
@@ -170,6 +188,7 @@ fn activate_deps_loop(
170
188
registry : & mut RegistryQueryer < ' _ > ,
171
189
summaries : & [ ( Summary , Method < ' _ > ) ] ,
172
190
config : Option < & Config > ,
191
+ check_public_visible_dependencies : bool ,
173
192
) -> CargoResult < Context > {
174
193
let mut backtrack_stack = Vec :: new ( ) ;
175
194
let mut remaining_deps = RemainingDeps :: new ( ) ;
@@ -185,7 +204,14 @@ fn activate_deps_loop(
185
204
summary : summary. clone ( ) ,
186
205
replace : None ,
187
206
} ;
188
- let res = activate ( & mut cx, registry, None , candidate, method) ;
207
+ let res = activate (
208
+ & mut cx,
209
+ registry,
210
+ None ,
211
+ candidate,
212
+ method,
213
+ check_public_visible_dependencies,
214
+ ) ;
189
215
match res {
190
216
Ok ( Some ( ( frame, _) ) ) => remaining_deps. push ( frame) ,
191
217
Ok ( None ) => ( ) ,
@@ -262,6 +288,7 @@ fn activate_deps_loop(
262
288
& cx,
263
289
& dep,
264
290
parent. package_id ( ) ,
291
+ check_public_visible_dependencies,
265
292
) ;
266
293
267
294
let ( candidate, has_another) = next. ok_or ( ( ) ) . or_else ( |_| {
@@ -301,6 +328,7 @@ fn activate_deps_loop(
301
328
& parent,
302
329
backtracked,
303
330
& conflicting_activations,
331
+ check_public_visible_dependencies,
304
332
) {
305
333
Some ( ( candidate, has_another, frame) ) => {
306
334
// Reset all of our local variables used with the
@@ -377,7 +405,14 @@ fn activate_deps_loop(
377
405
dep. package_name( ) ,
378
406
candidate. summary. version( )
379
407
) ;
380
- let res = activate ( & mut cx, registry, Some ( ( & parent, & dep) ) , candidate, & method) ;
408
+ let res = activate (
409
+ & mut cx,
410
+ registry,
411
+ Some ( ( & parent, & dep) ) ,
412
+ candidate,
413
+ & method,
414
+ check_public_visible_dependencies,
415
+ ) ;
381
416
382
417
let successfully_activated = match res {
383
418
// Success! We've now activated our `candidate` in our context
@@ -492,6 +527,7 @@ fn activate_deps_loop(
492
527
& parent,
493
528
backtracked,
494
529
& conflicting_activations,
530
+ check_public_visible_dependencies,
495
531
)
496
532
. is_none ( )
497
533
}
@@ -589,6 +625,7 @@ fn activate(
589
625
parent : Option < ( & Summary , & Dependency ) > ,
590
626
candidate : Candidate ,
591
627
method : & Method < ' _ > ,
628
+ check_public_visible_dependencies : bool ,
592
629
) -> ActivateResult < Option < ( DepsFrame , Duration ) > > {
593
630
let candidate_pid = candidate. summary . package_id ( ) ;
594
631
if let Some ( ( parent, dep) ) = parent {
@@ -601,12 +638,7 @@ fn activate(
601
638
)
602
639
// and associate dep with that edge
603
640
. push ( dep. clone ( ) ) ;
604
- // For now the interaction of public dependency conflicts with renamed and
605
- // 'cfg({})' dependencies is not clear. So we disable public checks if the
606
- // other functionality is used.
607
- // TODO: this disable is not a long term solution.
608
- // This needs to be removed before public dependencies are stabilized!
609
- if dep. platform ( ) . is_none ( ) && dep. explicit_name_in_toml ( ) . is_none ( ) {
641
+ if check_public_visible_dependencies {
610
642
// one tricky part is that `candidate_pid` may already be active and
611
643
// have public dependencies of its own. So we not only need to mark
612
644
// `candidate_pid` as visible to its parents but also all of its existing
@@ -752,6 +784,7 @@ impl RemainingCandidates {
752
784
cx : & Context ,
753
785
dep : & Dependency ,
754
786
parent : PackageId ,
787
+ check_public_visible_dependencies : bool ,
755
788
) -> Option < ( Candidate , bool ) > {
756
789
let prev_active = cx. prev_active ( dep) ;
757
790
@@ -795,13 +828,7 @@ impl RemainingCandidates {
795
828
// we have to reject this candidate. Additionally this candidate may already have been
796
829
// activated and have public dependants of its own,
797
830
// all of witch also need to be checked the same way.
798
-
799
- // For now the interaction of public dependency conflicts with renamed and
800
- // 'cfg({})' dependencies is not clear. So we disable public checks if the
801
- // other functionality is used.
802
- // TODO: this disable is not a long term solution.
803
- // This needs to be removed before public dependencies are stabilized!
804
- if dep. platform ( ) . is_none ( ) && dep. explicit_name_in_toml ( ) . is_none ( ) {
831
+ if check_public_visible_dependencies {
805
832
let existing_public_deps: Vec < PackageId > = cx
806
833
. public_dependency
807
834
. get ( & b. summary . package_id ( ) )
@@ -888,13 +915,15 @@ fn find_candidate(
888
915
parent : & Summary ,
889
916
backtracked : bool ,
890
917
conflicting_activations : & ConflictMap ,
918
+ check_public_visible_dependencies : bool ,
891
919
) -> Option < ( Candidate , bool , BacktrackFrame ) > {
892
920
while let Some ( mut frame) = backtrack_stack. pop ( ) {
893
921
let next = frame. remaining_candidates . next (
894
922
& mut frame. conflicting_activations ,
895
923
& frame. context ,
896
924
& frame. dep ,
897
925
frame. parent . package_id ( ) ,
926
+ check_public_visible_dependencies,
898
927
) ;
899
928
let ( candidate, has_another) = match next {
900
929
Some ( pair) => pair,
0 commit comments