@@ -462,6 +462,27 @@ fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLibrary]) {
462
462
}
463
463
}
464
464
465
+ fn get_file_path ( sess : & Session , name : & str ) -> PathBuf {
466
+ let fs = sess. target_filesearch ( PathKind :: Native ) ;
467
+ let search_path = |path : & PathBuf | -> Option < PathBuf > {
468
+ let file_path = path. join ( name) ;
469
+ if file_path. as_path ( ) . exists ( ) {
470
+ Some ( file_path)
471
+ } else {
472
+ None
473
+ }
474
+ } ;
475
+ let mut found_path = search_path ( & fs. get_lib_path ( ) ) ;
476
+ if found_path. is_none ( ) {
477
+ fs. for_each_lib_search_path ( |path, _| {
478
+ if found_path. is_none ( ) {
479
+ found_path = search_path ( & path. to_path_buf ( ) ) ;
480
+ }
481
+ } ) ;
482
+ }
483
+ found_path. unwrap_or_else ( || PathBuf :: from ( name) )
484
+ }
485
+
465
486
// Create a dynamic library or executable
466
487
//
467
488
// This will invoke the system linker/cc to create the resulting file. This
@@ -477,7 +498,6 @@ fn link_natively(sess: &Session,
477
498
// The invocations of cc share some flags across platforms
478
499
let ( pname, mut cmd) = get_linker ( sess, & linker, flavor) ;
479
500
480
- let root = sess. target_filesearch ( PathKind :: Native ) . get_lib_path ( ) ;
481
501
if let Some ( args) = sess. target . target . options . pre_link_args . get ( & flavor) {
482
502
cmd. args ( args) ;
483
503
}
@@ -505,12 +525,12 @@ fn link_natively(sess: &Session,
505
525
& sess. target . target . options . pre_link_objects_dll
506
526
} ;
507
527
for obj in pre_link_objects {
508
- cmd. arg ( root . join ( obj) ) ;
528
+ cmd. arg ( get_file_path ( sess , obj) ) ;
509
529
}
510
530
511
531
if crate_type == config:: CrateType :: Executable && sess. crt_static ( ) {
512
532
for obj in & sess. target . target . options . pre_link_objects_exe_crt {
513
- cmd. arg ( root . join ( obj) ) ;
533
+ cmd. arg ( get_file_path ( sess , obj) ) ;
514
534
}
515
535
}
516
536
@@ -534,11 +554,11 @@ fn link_natively(sess: &Session,
534
554
cmd. args ( args) ;
535
555
}
536
556
for obj in & sess. target . target . options . post_link_objects {
537
- cmd. arg ( root . join ( obj) ) ;
557
+ cmd. arg ( get_file_path ( sess , obj) ) ;
538
558
}
539
559
if sess. crt_static ( ) {
540
560
for obj in & sess. target . target . options . post_link_objects_crt {
541
- cmd. arg ( root . join ( obj) ) ;
561
+ cmd. arg ( get_file_path ( sess , obj) ) ;
542
562
}
543
563
}
544
564
if let Some ( args) = sess. target . target . options . post_link_args . get ( & flavor) {
0 commit comments