@@ -476,6 +476,7 @@ fn link_rlib<'a>(sess: &'a Session,
476
476
for lib in sess. cstore . used_libraries ( ) {
477
477
match lib. kind {
478
478
NativeLibraryKind :: NativeStatic => { }
479
+ NativeLibraryKind :: NativeStaticNobundle |
479
480
NativeLibraryKind :: NativeFramework |
480
481
NativeLibraryKind :: NativeUnknown => continue ,
481
482
}
@@ -674,6 +675,7 @@ fn link_staticlib(sess: &Session, objects: &[PathBuf], out_filename: &Path,
674
675
675
676
for lib in all_native_libs. iter ( ) . filter ( |l| relevant_lib ( sess, l) ) {
676
677
let name = match lib. kind {
678
+ NativeLibraryKind :: NativeStaticNobundle |
677
679
NativeLibraryKind :: NativeUnknown => "library" ,
678
680
NativeLibraryKind :: NativeFramework => "framework" ,
679
681
// These are included, no need to print them
@@ -894,7 +896,7 @@ fn link_args(cmd: &mut Linker,
894
896
// on other dylibs (e.g. other native deps).
895
897
add_local_native_libraries ( cmd, sess) ;
896
898
add_upstream_rust_crates ( cmd, sess, crate_type, tmpdir) ;
897
- add_upstream_native_libraries ( cmd, sess) ;
899
+ add_upstream_native_libraries ( cmd, sess, crate_type ) ;
898
900
899
901
// # Telling the linker what we're doing
900
902
@@ -985,6 +987,7 @@ fn add_local_native_libraries(cmd: &mut Linker, sess: &Session) {
985
987
match lib. kind {
986
988
NativeLibraryKind :: NativeUnknown => cmd. link_dylib ( & lib. name . as_str ( ) ) ,
987
989
NativeLibraryKind :: NativeFramework => cmd. link_framework ( & lib. name . as_str ( ) ) ,
990
+ NativeLibraryKind :: NativeStaticNobundle => cmd. link_staticlib ( & lib. name . as_str ( ) ) ,
988
991
NativeLibraryKind :: NativeStatic => bug ! ( ) ,
989
992
}
990
993
}
@@ -1210,7 +1213,7 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
1210
1213
// generic function calls a native function, then the generic function must
1211
1214
// be instantiated in the target crate, meaning that the native symbol must
1212
1215
// also be resolved in the target crate.
1213
- fn add_upstream_native_libraries ( cmd : & mut Linker , sess : & Session ) {
1216
+ fn add_upstream_native_libraries ( cmd : & mut Linker , sess : & Session , crate_type : config :: CrateType ) {
1214
1217
// Be sure to use a topological sorting of crates because there may be
1215
1218
// interdependencies between native libraries. When passing -nodefaultlibs,
1216
1219
// for example, almost all native libraries depend on libc, so we have to
@@ -1220,6 +1223,9 @@ fn add_upstream_native_libraries(cmd: &mut Linker, sess: &Session) {
1220
1223
// This passes RequireStatic, but the actual requirement doesn't matter,
1221
1224
// we're just getting an ordering of crate numbers, we're not worried about
1222
1225
// the paths.
1226
+ let formats = sess. dependency_formats . borrow ( ) ;
1227
+ let data = formats. get ( & crate_type) . unwrap ( ) ;
1228
+
1223
1229
let crates = sess. cstore . used_crates ( LinkagePreference :: RequireStatic ) ;
1224
1230
for ( cnum, _) in crates {
1225
1231
for lib in sess. cstore . native_libraries ( cnum) {
@@ -1229,7 +1235,15 @@ fn add_upstream_native_libraries(cmd: &mut Linker, sess: &Session) {
1229
1235
match lib. kind {
1230
1236
NativeLibraryKind :: NativeUnknown => cmd. link_dylib ( & lib. name . as_str ( ) ) ,
1231
1237
NativeLibraryKind :: NativeFramework => cmd. link_framework ( & lib. name . as_str ( ) ) ,
1232
-
1238
+ NativeLibraryKind :: NativeStaticNobundle => {
1239
+ // Link "static-nobundle" native libs only if the crate they originate from
1240
+ // is being linked statically to the current crate. If it's linked dynamically
1241
+ // or is an rlib already included via some other dylib crate, the symbols from
1242
+ // native libs will have already been included in that dylib.
1243
+ if data[ cnum. as_usize ( ) - 1 ] == Linkage :: Static {
1244
+ cmd. link_staticlib ( & lib. name . as_str ( ) )
1245
+ }
1246
+ } ,
1233
1247
// ignore statically included native libraries here as we've
1234
1248
// already included them when we included the rust library
1235
1249
// previously
0 commit comments