@@ -21,10 +21,17 @@ use rustc_target::spec::{BinaryFormat, LinkSelfContainedComponents};
21
21
22
22
use crate :: { errors, fluent_generated} ;
23
23
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
+
24
32
pub fn walk_native_lib_search_dirs < R > (
25
33
sess : & Session ,
26
- self_contained_components : LinkSelfContainedComponents ,
27
- apple_sdk_root : Option < & Path > ,
34
+ fallback : Option < NativeLibSearchFallback < ' _ > > ,
28
35
mut f : impl FnMut ( & Path , bool /*is_framework*/ ) -> ControlFlow < R > ,
29
36
) -> ControlFlow < R > {
30
37
// Library search paths explicitly supplied by user (`-L` on the command line).
@@ -38,6 +45,11 @@ pub fn walk_native_lib_search_dirs<R>(
38
45
}
39
46
}
40
47
48
+ let Some ( NativeLibSearchFallback { self_contained_components, apple_sdk_root } ) = fallback
49
+ else {
50
+ return ControlFlow :: Continue ( ( ) ) ;
51
+ } ;
52
+
41
53
// The toolchain ships some native library components and self-contained linking was enabled.
42
54
// Add the self-contained library directory to search paths.
43
55
if self_contained_components. intersects (
@@ -93,23 +105,17 @@ pub fn try_find_native_static_library(
93
105
if os == unix { vec ! [ os] } else { vec ! [ os, unix] }
94
106
} ;
95
107
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) ;
108
114
}
109
115
}
110
- ControlFlow :: Continue ( ( ) )
111
- } ,
112
- )
116
+ }
117
+ ControlFlow :: Continue ( ( ) )
118
+ } )
113
119
. break_value ( )
114
120
}
115
121
@@ -132,22 +138,17 @@ pub fn try_find_native_dynamic_library(
132
138
vec ! [ os, meson, mingw]
133
139
} ;
134
140
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) ;
146
147
}
147
148
}
148
- ControlFlow :: Continue ( ( ) )
149
- } ,
150
- )
149
+ }
150
+ ControlFlow :: Continue ( ( ) )
151
+ } )
151
152
. break_value ( )
152
153
}
153
154
0 commit comments