From bcfbbd864561a9aa64b9e5908a62eaa2123c5764 Mon Sep 17 00:00:00 2001 From: pweyck Date: Sun, 6 Nov 2016 11:45:21 +0100 Subject: [PATCH] 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. Fixes #36854 See also: #36996 --- src/librustc_llvm/build.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/librustc_llvm/build.rs b/src/librustc_llvm/build.rs index 35140d5ab4ae6..4d3a4d09dcea0 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::().ok()), + parts.next().and_then(|s| s.parse::().ok())) { + if major > 3 || (major == 3 && minor >= 8) { + cmd.arg("--link-static"); + } + } + if !is_crossed { cmd.arg("--system-libs"); }