@@ -317,35 +317,41 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
317
317
// loaded from the libraries found here and then encode that into the
318
318
// metadata of the rlib we're generating somehow.
319
319
for lib in codegen_results. crate_info . used_libraries . iter ( ) {
320
- if !sess. opts . unstable_opts . split_bundled_libs {
321
- match lib. kind {
322
- NativeLibKind :: Static { bundle : None | Some ( true ) , whole_archive : Some ( true ) }
323
- if flavor == RlibFlavor :: Normal =>
324
- {
325
- // Don't allow mixing +bundle with +whole_archive since an rlib may contain
326
- // multiple native libs, some of which are +whole-archive and some of which are
327
- // -whole-archive and it isn't clear how we can currently handle such a
328
- // situation correctly.
329
- // See https://github.com/rust-lang/rust/issues/88085#issuecomment-901050897
330
- sess. err (
331
- "the linking modifiers `+bundle` and `+whole-archive` are not compatible \
332
- with each other when generating rlibs",
333
- ) ;
334
- }
335
- NativeLibKind :: Static { bundle : None | Some ( true ) , .. } => { }
336
- NativeLibKind :: Static { bundle : Some ( false ) , .. }
337
- | NativeLibKind :: Dylib { .. }
338
- | NativeLibKind :: Framework { .. }
339
- | NativeLibKind :: RawDylib
340
- | NativeLibKind :: Unspecified => continue ,
341
- }
342
- if let Some ( name) = lib. name {
320
+ match lib. kind {
321
+ NativeLibKind :: Static { bundle : None | Some ( true ) , whole_archive } => {
322
+ let Some ( name) = lib. name else {
323
+ continue ;
324
+ } ;
325
+
343
326
let location = find_library (
344
327
name. as_str ( ) ,
345
328
lib. verbatim . unwrap_or ( false ) ,
346
329
& lib_search_paths,
347
330
sess,
348
331
) ;
332
+ if flavor == RlibFlavor :: Normal {
333
+ if whole_archive == Some ( true ) && !sess. opts . unstable_opts . split_bundled_libs {
334
+ // Don't allow mixing +bundle with +whole_archive since an rlib may contain
335
+ // multiple native libs, some of which are +whole-archive and some of which are
336
+ // -whole-archive and it isn't clear how we can currently handle such a
337
+ // situation correctly.
338
+ // See https://github.com/rust-lang/rust/issues/88085#issuecomment-901050897
339
+ sess. err (
340
+ "the linking modifiers `+bundle` and `+whole-archive` are not compatible \
341
+ with each other when generating rlibs",
342
+ ) ;
343
+ }
344
+
345
+ if sess. opts . unstable_opts . split_bundled_libs {
346
+ let suffix = & sess. target . staticlib_suffix ;
347
+ let crate_name = out_filename. to_str ( ) . unwrap ( ) ;
348
+ let bundle_lib =
349
+ PathBuf :: from ( & format ! ( "{crate_name}.bundle.{name}{suffix}" ) ) ;
350
+ fs:: copy ( location, bundle_lib) . unwrap ( ) ;
351
+ continue ;
352
+ }
353
+ }
354
+
349
355
ab. add_archive ( & location, |_| false ) . unwrap_or_else ( |e| {
350
356
sess. fatal ( & format ! (
351
357
"failed to add native library {}: {}" ,
@@ -354,29 +360,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
354
360
) ) ;
355
361
} ) ;
356
362
}
357
- } else {
358
- match lib. kind {
359
- NativeLibKind :: Static { bundle : None | Some ( true ) , .. }
360
- if flavor == RlibFlavor :: Normal =>
361
- {
362
- let Some ( name) = lib. name else {
363
- continue ;
364
- } ;
365
-
366
- let location = find_library (
367
- name. as_str ( ) ,
368
- lib. verbatim . unwrap_or ( false ) ,
369
- & lib_search_paths,
370
- sess,
371
- ) ;
372
-
373
- let suffix = & sess. target . staticlib_suffix ;
374
- let crate_name = out_filename. to_str ( ) . unwrap ( ) ;
375
- let bundle_lib = PathBuf :: from ( & format ! ( "{crate_name}.bundle.{name}{suffix}" ) ) ;
376
- fs:: copy ( location, bundle_lib) . unwrap ( ) ;
377
- }
378
- _ => { }
379
- }
363
+ _ => { }
380
364
}
381
365
}
382
366
@@ -2409,20 +2393,20 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
2409
2393
}
2410
2394
} else {
2411
2395
if let NativeLibKind :: Static { bundle : Some ( false ) , whole_archive } =
2412
- lib. kind
2413
- {
2414
- let verbatim = lib. verbatim . unwrap_or ( false ) ;
2415
- if whole_archive == Some ( true ) {
2416
- cmd. link_whole_staticlib (
2417
- name,
2418
- verbatim,
2419
- search_path. get_or_init ( || archive_search_paths ( sess) ) ,
2420
- ) ;
2421
- } else {
2422
- cmd. link_staticlib ( name, verbatim) ;
2396
+ lib. kind
2397
+ {
2398
+ let verbatim = lib. verbatim . unwrap_or ( false ) ;
2399
+ if whole_archive == Some ( true ) {
2400
+ cmd. link_whole_staticlib (
2401
+ name,
2402
+ verbatim,
2403
+ search_path. get_or_init ( || archive_search_paths ( sess) ) ,
2404
+ ) ;
2405
+ } else {
2406
+ cmd. link_staticlib ( name, verbatim) ;
2407
+ }
2423
2408
}
2424
2409
}
2425
- }
2426
2410
}
2427
2411
}
2428
2412
}
0 commit comments