@@ -274,10 +274,9 @@ pub fn each_linked_rlib(
274
274
275
275
/// Create an 'rlib'.
276
276
///
277
- /// An rlib in its current incarnation is essentially a renamed .a file. The rlib primarily contains
278
- /// the object file of the crate, but it also contains all of the object files from native
279
- /// libraries. This is done by unzipping native libraries and inserting all of the contents into
280
- /// this archive.
277
+ /// An rlib in its current incarnation is essentially a renamed .a file (with "dummy" object files).
278
+ /// The rlib primarily contains the object file of the crate, but it also some of the object files
279
+ /// from native libraries.
281
280
fn link_rlib < ' a > (
282
281
sess : & ' a Session ,
283
282
archive_builder_builder : & dyn ArchiveBuilderBuilder ,
@@ -351,43 +350,24 @@ fn link_rlib<'a>(
351
350
// loaded from the libraries found here and then encode that into the
352
351
// metadata of the rlib we're generating somehow.
353
352
for lib in codegen_results. crate_info . used_libraries . iter ( ) {
354
- match lib. kind {
355
- NativeLibKind :: Static { bundle : None | Some ( true ) , whole_archive : Some ( true ) }
356
- if flavor == RlibFlavor :: Normal && sess. opts . unstable_opts . packed_bundled_libs => { }
357
- NativeLibKind :: Static { bundle : None | Some ( true ) , whole_archive : Some ( true ) }
358
- if flavor == RlibFlavor :: Normal =>
359
- {
360
- // Don't allow mixing +bundle with +whole_archive since an rlib may contain
361
- // multiple native libs, some of which are +whole-archive and some of which are
362
- // -whole-archive and it isn't clear how we can currently handle such a
363
- // situation correctly.
364
- // See https://github.com/rust-lang/rust/issues/88085#issuecomment-901050897
365
- sess. emit_err ( errors:: IncompatibleLinkingModifiers ) ;
366
- }
367
- NativeLibKind :: Static { bundle : None | Some ( true ) , .. } => { }
368
- NativeLibKind :: Static { bundle : Some ( false ) , .. }
369
- | NativeLibKind :: Dylib { .. }
370
- | NativeLibKind :: Framework { .. }
371
- | NativeLibKind :: RawDylib
372
- | NativeLibKind :: LinkArg
373
- | NativeLibKind :: Unspecified => continue ,
374
- }
375
- if let Some ( name) = lib. name {
376
- let location =
353
+ let NativeLibKind :: Static { bundle : None | Some ( true ) , whole_archive } = lib. kind else {
354
+ continue ;
355
+ } ;
356
+ if flavor == RlibFlavor :: Normal
357
+ && ( sess. opts . unstable_opts . packed_bundled_libs || whole_archive == Some ( true ) )
358
+ {
359
+ let name = lib. filename . unwrap ( ) ;
360
+ let path = find_native_static_library ( name. as_str ( ) , true , & lib_search_paths, sess) ;
361
+ let src =
362
+ read ( path) . map_err ( |e| sess. emit_fatal ( errors:: ReadFileError { message : e } ) ) ?;
363
+ let ( data, _) = create_wrapper_file ( sess, b".bundled_lib" . to_vec ( ) , & src) ;
364
+ let wrapper_file = emit_wrapper_file ( sess, & data, tmpdir, name. as_str ( ) ) ;
365
+ packed_bundled_libs. push ( wrapper_file) ;
366
+ } else if let Some ( name) = lib. name {
367
+ let path =
377
368
find_native_static_library ( name. as_str ( ) , lib. verbatim , & lib_search_paths, sess) ;
378
- if sess. opts . unstable_opts . packed_bundled_libs && flavor == RlibFlavor :: Normal {
379
- let filename = lib. filename . unwrap ( ) ;
380
- let lib_path =
381
- find_native_static_library ( filename. as_str ( ) , true , & lib_search_paths, sess) ;
382
- let src = read ( lib_path)
383
- . map_err ( |e| sess. emit_fatal ( errors:: ReadFileError { message : e } ) ) ?;
384
- let ( data, _) = create_wrapper_file ( sess, b".bundled_lib" . to_vec ( ) , & src) ;
385
- let wrapper_file = emit_wrapper_file ( sess, & data, tmpdir, filename. as_str ( ) ) ;
386
- packed_bundled_libs. push ( wrapper_file) ;
387
- continue ;
388
- }
389
- ab. add_archive ( & location, Box :: new ( |_| false ) ) . unwrap_or_else ( |error| {
390
- sess. emit_fatal ( errors:: AddNativeLibrary { library_path : location, error } ) ;
369
+ ab. add_archive ( & path, Box :: new ( |_| false ) ) . unwrap_or_else ( |error| {
370
+ sess. emit_fatal ( errors:: AddNativeLibrary { library_path : path, error } ) ;
391
371
} ) ;
392
372
}
393
373
}
0 commit comments