@@ -450,14 +450,10 @@ mod impl_ {
450
450
451
451
fn vs15plus_vc_paths (
452
452
target : & str ,
453
- instance_path : & PathBuf ,
453
+ instance_path : & Path ,
454
454
) -> Option < ( PathBuf , PathBuf , PathBuf , PathBuf , PathBuf ) > {
455
- let version_path =
456
- instance_path. join ( r"VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" ) ;
457
- let mut version_file = File :: open ( version_path) . ok ( ) ?;
458
- let mut version = String :: new ( ) ;
459
- version_file. read_to_string ( & mut version) . ok ( ) ?;
460
- let version = version. trim ( ) ;
455
+ let version = vs15plus_vc_read_version ( instance_path) ?;
456
+
461
457
let host = match host_arch ( ) {
462
458
X86 => "X86" ,
463
459
X86_64 => "X64" ,
@@ -487,6 +483,43 @@ mod impl_ {
487
483
Some ( ( path, bin_path, host_dylib_path, lib_path, include_path) )
488
484
}
489
485
486
+ fn vs15plus_vc_read_version ( dir : & Path ) -> Option < String > {
487
+ // Try to open the default version file.
488
+ let mut version_path: PathBuf =
489
+ dir. join ( r"VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" ) ;
490
+ let mut version_file = if let Ok ( f) = File :: open ( & version_path) {
491
+ f
492
+ } else {
493
+ // If the default doesn't exist, search for other version files.
494
+ // These are in the form Microsoft.VCToolsVersion.v143.default.txt
495
+ // where `143` is any three decimal digit version number.
496
+ // This sorts versions by lexical order and selects the highest version.
497
+ let mut version_file = String :: new ( ) ;
498
+ version_path. pop ( ) ;
499
+ for file in version_path. read_dir ( ) . ok ( ) ? {
500
+ let name = file. ok ( ) ?. file_name ( ) ;
501
+ let name = name. to_str ( ) ?;
502
+ if name. starts_with ( "Microsoft.VCToolsVersion.v" )
503
+ && name. ends_with ( ".default.txt" )
504
+ && name > & version_file
505
+ {
506
+ version_file. replace_range ( .., name) ;
507
+ }
508
+ }
509
+ if version_file. is_empty ( ) {
510
+ return None ;
511
+ }
512
+ version_path. push ( version_file) ;
513
+ File :: open ( version_path) . ok ( ) ?
514
+ } ;
515
+
516
+ // Get the version string from the file we found.
517
+ let mut version = String :: new ( ) ;
518
+ version_file. read_to_string ( & mut version) . ok ( ) ?;
519
+ version. truncate ( version. trim_end ( ) . len ( ) ) ;
520
+ Some ( version)
521
+ }
522
+
490
523
fn atl_paths ( target : & str , path : & Path ) -> Option < ( PathBuf , PathBuf ) > {
491
524
let atl_path = path. join ( "atlmfc" ) ;
492
525
let sub = lib_subdir ( target) ?;
0 commit comments