aboutsummaryrefslogtreecommitdiffstats
path: root/community/rust/musl-fix-static-linking.patch
blob: 820aa52cb38fc02520d99259e04d317de70e8ced (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
From: Shiz <hi@shiz.me>
Date: Fri, 21 Apr 2017 01:04:46 +0200
Last-Updated: Sat, 19 May 2018 23:54:30 +0200
Subject: [PATCH] Support fully static linking on *nix targets

It adds the proper linker argument for static result objects to `Linker`
and implements them for `GnuLinker` and `MsvcLinker`.

Finally, if no linking preference is given for native libraries
(`NativeLibraryKind::NativeUnknown`), they are linked statically if full
static linking is requested, instead of dynamically as before.

--- a/src/librustc_codegen_ssa/back/link.rs
+++ b/src/librustc_codegen_ssa/back/link.rs
@@ -1218,13 +1218,13 @@ fn add_local_native_libraries(cmd: &mut dyn Linker,
     let search_path = archive_search_paths(sess);
     for lib in relevant_libs {
         let name = match lib.name {
             Some(ref l) => l,
             None => continue,
         };
         match lib.kind {
-            NativeLibraryKind::NativeUnknown => cmd.link_dylib(&name.as_str()),
+            NativeLibraryKind::NativeUnknown => if sess.crt_static() { cmd.link_staticlib(&name.as_str()) } else { cmd.link_dylib(&name.as_str()) },
             NativeLibraryKind::NativeFramework => cmd.link_framework(&name.as_str()),
             NativeLibraryKind::NativeStaticNobundle => cmd.link_staticlib(&name.as_str()),
             NativeLibraryKind::NativeStatic => cmd.link_whole_staticlib(&name.as_str(),
                                                                         &search_path)
         }