@@ -918,7 +918,48 @@ pub fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLibrary
918
918
}
919
919
}
920
920
921
+ fn get_compiler_libs_path ( sess : & Session ) -> Option < PathBuf > {
922
+ use std:: sync:: Mutex ;
923
+
924
+ lazy_static:: lazy_static! {
925
+ static ref SYSTEM_LIBS : Mutex <Option <PathBuf >> = Mutex :: new( None ) ;
926
+ }
927
+
928
+ let system_libs = SYSTEM_LIBS . lock ( ) . unwrap ( ) . clone ( ) ;
929
+ if let Some ( compiler_libs_path) = system_libs {
930
+ println ! ( "cache: hit" ) ;
931
+ return Some ( compiler_libs_path) ;
932
+ } else {
933
+ println ! ( "cache: miss" ) ;
934
+ let compiler = if let Some ( linker) = & sess. opts . cg . linker {
935
+ linker. clone ( ) . into_os_string ( )
936
+ } else if let Some ( linker) = & sess. target . target . options . linker {
937
+ linker. into ( )
938
+ } else {
939
+ return None ;
940
+ } ;
941
+ if let Ok ( output) = Command :: new ( compiler) . arg ( "-print-file-name=crt2.o" ) . output ( ) {
942
+ if let Some ( compiler_libs_path) =
943
+ PathBuf :: from ( std:: str:: from_utf8 ( & output. stdout ) . unwrap ( ) ) . parent ( )
944
+ {
945
+ let compiler_libs_path = fix_windows_verbatim_for_gcc ( compiler_libs_path) ;
946
+ * SYSTEM_LIBS . lock ( ) . unwrap ( ) = Some ( compiler_libs_path. clone ( ) ) ;
947
+ return Some ( compiler_libs_path) ;
948
+ }
949
+ }
950
+ }
951
+ None
952
+ }
953
+
921
954
pub fn get_file_path ( sess : & Session , name : & str ) -> PathBuf {
955
+ if sess. target . target . llvm_target . contains ( "windows-gnu" ) {
956
+ if let Some ( compiler_libs_path) = get_compiler_libs_path ( sess) {
957
+ let file_path = compiler_libs_path. join ( name) ;
958
+ if file_path. exists ( ) {
959
+ return file_path;
960
+ }
961
+ }
962
+ }
922
963
let fs = sess. target_filesearch ( PathKind :: Native ) ;
923
964
let file_path = fs. get_lib_path ( ) . join ( name) ;
924
965
if file_path. exists ( ) {
@@ -1100,6 +1141,12 @@ fn link_args<'a, B: ArchiveBuilder<'a>>(
1100
1141
// target descriptor
1101
1142
let t = & sess. target . target ;
1102
1143
1144
+ if sess. target . target . llvm_target . contains ( "windows-gnu" ) {
1145
+ if let Some ( compiler_libs_path) = get_compiler_libs_path ( sess) {
1146
+ cmd. include_path ( & compiler_libs_path) ;
1147
+ }
1148
+ }
1149
+
1103
1150
cmd. include_path ( & fix_windows_verbatim_for_gcc ( & lib_path) ) ;
1104
1151
1105
1152
for obj in codegen_results. modules . iter ( ) . filter_map ( |m| m. object . as_ref ( ) ) {
0 commit comments