@@ -162,6 +162,7 @@ use std::borrow::Cow;
162
162
use std:: collections:: BTreeMap ;
163
163
use std:: fs:: File ;
164
164
use std:: path:: { Path , PathBuf } ;
165
+ use std:: collections:: HashMap ;
165
166
166
167
use flate2:: read:: GzDecoder ;
167
168
use log:: debug;
@@ -184,12 +185,60 @@ pub const CRATES_IO_REGISTRY: &str = "crates-io";
184
185
const CRATE_TEMPLATE : & str = "{crate}" ;
185
186
const VERSION_TEMPLATE : & str = "{version}" ;
186
187
188
+ pub struct MsrvInfos {
189
+ msrv_infos : HashMap < ( String , Version ) , Version > ,
190
+ local_msrv : Option < Version > ,
191
+ }
192
+
193
+ fn get_local_msrv ( config : & Config ) -> Option < Version > {
194
+ let values = config. values ( ) . ok ( ) ?;
195
+ let msrv = values. get ( "msrv" ) ?;
196
+ let msrv_str = msrv. string ( "" ) . ok ( ) ?. 0 ;
197
+ Version :: parse ( msrv_str) . ok ( )
198
+ }
199
+ fn get_msrv_infos ( config : & Config ) -> Option < HashMap < ( String , Version ) , Version > > {
200
+ let values = config. values ( ) . ok ( ) ?;
201
+ let path_value = values. get ( "msrv_infos" ) ?;
202
+ let path = path_value. string ( "" ) . ok ( ) ?. 0 ;
203
+ let msrv_infos_str = std:: fs:: read_to_string ( path) . ok ( ) ?;
204
+ #[ derive( Deserialize ) ]
205
+ struct MsrvInfo {
206
+ name : String ,
207
+ vers : Version ,
208
+ msrv : Version ,
209
+ }
210
+ let msrv_infos: Vec < MsrvInfo > = serde_json:: from_str ( & msrv_infos_str) . ok ( ) ?;
211
+ let msrv_infos = msrv_infos. into_iter ( )
212
+ . map ( |MsrvInfo { name, vers, msrv } | ( ( name, vers) , msrv) )
213
+ . collect :: < HashMap < ( String , Version ) , Version > > ( ) ;
214
+
215
+ Some ( msrv_infos)
216
+ }
217
+
218
+ impl MsrvInfos {
219
+ pub fn new ( config : & Config ) -> Self {
220
+ Self {
221
+ msrv_infos : get_msrv_infos ( config) . unwrap_or_else ( HashMap :: new) ,
222
+ local_msrv : get_local_msrv ( config) ,
223
+ }
224
+ }
225
+
226
+ fn get ( & self , name : & str , v : & Version ) -> Option < & Version > {
227
+ self . msrv_infos . get ( & ( name. to_string ( ) , v. clone ( ) ) )
228
+ }
229
+ /// Obtains the msrv used for resolution
230
+ fn local_msrv ( & self ) -> Option < & Version > {
231
+ self . local_msrv . as_ref ( )
232
+ }
233
+ }
234
+
187
235
pub struct RegistrySource < ' cfg > {
188
236
source_id : SourceId ,
189
237
src_path : Filesystem ,
190
238
config : & ' cfg Config ,
191
239
updated : bool ,
192
240
ops : Box < dyn RegistryData + ' cfg > ,
241
+ msrv_infos : MsrvInfos ,
193
242
index : index:: RegistryIndex < ' cfg > ,
194
243
index_locked : bool ,
195
244
}
@@ -408,6 +457,7 @@ impl<'cfg> RegistrySource<'cfg> {
408
457
config,
409
458
source_id,
410
459
updated : false ,
460
+ msrv_infos : MsrvInfos :: new ( config) ,
411
461
index : index:: RegistryIndex :: new ( source_id, ops. index_path ( ) , config, index_locked) ,
412
462
index_locked,
413
463
ops,
@@ -505,7 +555,7 @@ impl<'cfg> Source for RegistrySource<'cfg> {
505
555
if dep. source_id ( ) . precise ( ) . is_some ( ) && !self . updated {
506
556
debug ! ( "attempting query without update" ) ;
507
557
let mut called = false ;
508
- self . index . query_inner ( dep, & mut * self . ops , & mut |s| {
558
+ self . index . query_inner ( dep, & mut * self . ops , & mut self . msrv_infos , & mut |s| {
509
559
if dep. matches ( & s) {
510
560
called = true ;
511
561
f ( s) ;
@@ -519,15 +569,15 @@ impl<'cfg> Source for RegistrySource<'cfg> {
519
569
}
520
570
}
521
571
522
- self . index . query_inner ( dep, & mut * self . ops , & mut |s| {
572
+ self . index . query_inner ( dep, & mut * self . ops , & mut self . msrv_infos , & mut |s| {
523
573
if dep. matches ( & s) {
524
574
f ( s) ;
525
575
}
526
576
} )
527
577
}
528
578
529
579
fn fuzzy_query ( & mut self , dep : & Dependency , f : & mut dyn FnMut ( Summary ) ) -> CargoResult < ( ) > {
530
- self . index . query_inner ( dep, & mut * self . ops , f)
580
+ self . index . query_inner ( dep, & mut * self . ops , & mut self . msrv_infos , f)
531
581
}
532
582
533
583
fn supports_checksums ( & self ) -> bool {
0 commit comments