@@ -21,10 +21,17 @@ use rustc_target::spec::{BinaryFormat, LinkSelfContainedComponents};
2121
2222use crate :: { errors, fluent_generated} ;
2323
24+ /// The fallback directories are passed to linker, but not used when rustc does the search,
25+ /// because in the latter case the set of fallback directories cannot always be determined
26+ /// consistently at the moment.
27+ pub struct NativeLibSearchFallback < ' a > {
28+ pub self_contained_components : LinkSelfContainedComponents ,
29+ pub apple_sdk_root : Option < & ' a Path > ,
30+ }
31+
2432pub fn walk_native_lib_search_dirs < R > (
2533 sess : & Session ,
26- self_contained_components : LinkSelfContainedComponents ,
27- apple_sdk_root : Option < & Path > ,
34+ fallback : Option < NativeLibSearchFallback < ' _ > > ,
2835 mut f : impl FnMut ( & Path , bool /*is_framework*/ ) -> ControlFlow < R > ,
2936) -> ControlFlow < R > {
3037 // Library search paths explicitly supplied by user (`-L` on the command line).
@@ -38,6 +45,11 @@ pub fn walk_native_lib_search_dirs<R>(
3845 }
3946 }
4047
48+ let Some ( NativeLibSearchFallback { self_contained_components, apple_sdk_root } ) = fallback
49+ else {
50+ return ControlFlow :: Continue ( ( ) ) ;
51+ } ;
52+
4153 // The toolchain ships some native library components and self-contained linking was enabled.
4254 // Add the self-contained library directory to search paths.
4355 if self_contained_components. intersects (
@@ -93,23 +105,17 @@ pub fn try_find_native_static_library(
93105 if os == unix { vec ! [ os] } else { vec ! [ os, unix] }
94106 } ;
95107
96- // FIXME: Account for self-contained linking settings and Apple SDK.
97- walk_native_lib_search_dirs (
98- sess,
99- LinkSelfContainedComponents :: empty ( ) ,
100- None ,
101- |dir, is_framework| {
102- if !is_framework {
103- for ( prefix, suffix) in & formats {
104- let test = dir. join ( format ! ( "{prefix}{name}{suffix}" ) ) ;
105- if test. exists ( ) {
106- return ControlFlow :: Break ( test) ;
107- }
108+ walk_native_lib_search_dirs ( sess, None , |dir, is_framework| {
109+ if !is_framework {
110+ for ( prefix, suffix) in & formats {
111+ let test = dir. join ( format ! ( "{prefix}{name}{suffix}" ) ) ;
112+ if test. exists ( ) {
113+ return ControlFlow :: Break ( test) ;
108114 }
109115 }
110- ControlFlow :: Continue ( ( ) )
111- } ,
112- )
116+ }
117+ ControlFlow :: Continue ( ( ) )
118+ } )
113119 . break_value ( )
114120}
115121
@@ -132,22 +138,17 @@ pub fn try_find_native_dynamic_library(
132138 vec ! [ os, meson, mingw]
133139 } ;
134140
135- walk_native_lib_search_dirs (
136- sess,
137- LinkSelfContainedComponents :: empty ( ) ,
138- None ,
139- |dir, is_framework| {
140- if !is_framework {
141- for ( prefix, suffix) in & formats {
142- let test = dir. join ( format ! ( "{prefix}{name}{suffix}" ) ) ;
143- if test. exists ( ) {
144- return ControlFlow :: Break ( test) ;
145- }
141+ walk_native_lib_search_dirs ( sess, None , |dir, is_framework| {
142+ if !is_framework {
143+ for ( prefix, suffix) in & formats {
144+ let test = dir. join ( format ! ( "{prefix}{name}{suffix}" ) ) ;
145+ if test. exists ( ) {
146+ return ControlFlow :: Break ( test) ;
146147 }
147148 }
148- ControlFlow :: Continue ( ( ) )
149- } ,
150- )
149+ }
150+ ControlFlow :: Continue ( ( ) )
151+ } )
151152 . break_value ( )
152153}
153154
0 commit comments