about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-11-06 12:47:14 -0800
committerGitHub <noreply@github.com>2016-11-06 12:47:14 -0800
commit4742008742dda55377fd92058f96e36a01f0ce77 (patch)
treeb884341a420bceef74661acd29d88b293b66d121
parent2a44315fc72d2ab123344dd65b6b2129dff30aaa (diff)
parentbcfbbd864561a9aa64b9e5908a62eaa2123c5764 (diff)
downloadrust-4742008742dda55377fd92058f96e36a01f0ce77.tar.gz
rust-4742008742dda55377fd92058f96e36a01f0ce77.zip
Auto merge of #37617 - pweyck:force-static-llvm-linking, r=alexcrichton
Force static linking of LLVM

Run `llvm-config` with `--link-static` if available, to force static linking of LLVM.
This option was added in LLVM 3.8.

This is my first pull request, any feedback is welcome!

Fixes #36854
See also: #36996
-rw-r--r--src/librustc_llvm/build.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/librustc_llvm/build.rs b/src/librustc_llvm/build.rs
index 35140d5ab4a..4d3a4d09dce 100644
--- a/src/librustc_llvm/build.rs
+++ b/src/librustc_llvm/build.rs
@@ -128,6 +128,19 @@ fn main() {
     // of llvm-config, not the target that we're attempting to link.
     let mut cmd = Command::new(&llvm_config);
     cmd.arg("--libs");
+
+    // Force static linking with "--link-static" if available.
+    let mut version_cmd = Command::new(&llvm_config);
+    version_cmd.arg("--version");
+    let version_output = output(&mut version_cmd);
+    let mut parts = version_output.split('.');
+    if let (Some(major), Some(minor)) = (parts.next().and_then(|s| s.parse::<u32>().ok()),
+                                         parts.next().and_then(|s| s.parse::<u32>().ok())) {
+        if major > 3 || (major == 3 && minor >= 8) {
+            cmd.arg("--link-static");
+        }
+    }
+
     if !is_crossed {
         cmd.arg("--system-libs");
     }