@@ -36,6 +36,7 @@ use regex::Regex;
36
36
use tempfile:: Builder as TempFileBuilder ;
37
37
38
38
use std:: ffi:: OsString ;
39
+ use std:: lazy:: OnceCell ;
39
40
use std:: path:: { Path , PathBuf } ;
40
41
use std:: process:: { ExitStatus , Output , Stdio } ;
41
42
use std:: { ascii, char, env, fmt, fs, io, mem, str} ;
@@ -2328,6 +2329,7 @@ fn add_upstream_native_libraries(
2328
2329
. find ( |( ty, _) | * ty == crate_type)
2329
2330
. expect ( "failed to find crate type in dependency format list" ) ;
2330
2331
2332
+ let search_path = OnceCell :: new ( ) ;
2331
2333
let crates = & codegen_results. crate_info . used_crates ;
2332
2334
let mut last = ( NativeLibKind :: Unspecified , None ) ;
2333
2335
for & cnum in crates {
@@ -2352,19 +2354,34 @@ fn add_upstream_native_libraries(
2352
2354
NativeLibKind :: Framework { as_needed } => {
2353
2355
cmd. link_framework ( name, as_needed. unwrap_or ( true ) )
2354
2356
}
2355
- NativeLibKind :: Static { bundle : Some ( false ) , .. } => {
2357
+ NativeLibKind :: Static { bundle : Some ( false ) , whole_archive } => {
2356
2358
// Link "static-nobundle" native libs only if the crate they originate from
2357
2359
// is being linked statically to the current crate. If it's linked dynamically
2358
2360
// or is an rlib already included via some other dylib crate, the symbols from
2359
2361
// native libs will have already been included in that dylib.
2360
2362
if data[ cnum. as_usize ( ) - 1 ] == Linkage :: Static {
2361
- cmd. link_staticlib ( name, verbatim)
2363
+ if whole_archive == Some ( true ) {
2364
+ cmd. link_whole_staticlib (
2365
+ name,
2366
+ verbatim,
2367
+ search_path. get_or_init ( || archive_search_paths ( sess) ) ,
2368
+ ) ;
2369
+ } else {
2370
+ cmd. link_staticlib ( name, verbatim)
2371
+ }
2362
2372
}
2363
2373
}
2364
2374
// ignore statically included native libraries here as we've
2365
2375
// already included them when we included the rust library
2366
2376
// previously
2367
- NativeLibKind :: Static { bundle : None | Some ( true ) , .. } => { }
2377
+ NativeLibKind :: Static { bundle : None | Some ( true ) , whole_archive } => {
2378
+ if whole_archive == Some ( true ) {
2379
+ bug ! (
2380
+ "Combining `+bundle` with `+whole-archive` is not allowed. \
2381
+ This should have been caught by an earlier validation step already."
2382
+ )
2383
+ }
2384
+ }
2368
2385
NativeLibKind :: RawDylib => { }
2369
2386
}
2370
2387
}
0 commit comments