Skip to content

Commit bcfbbd8

Browse files
committed
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
1 parent 161f262 commit bcfbbd8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/librustc_llvm/build.rs

+13
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ fn main() {
128128
// of llvm-config, not the target that we're attempting to link.
129129
let mut cmd = Command::new(&llvm_config);
130130
cmd.arg("--libs");
131+
132+
// Force static linking with "--link-static" if available.
133+
let mut version_cmd = Command::new(&llvm_config);
134+
version_cmd.arg("--version");
135+
let version_output = output(&mut version_cmd);
136+
let mut parts = version_output.split('.');
137+
if let (Some(major), Some(minor)) = (parts.next().and_then(|s| s.parse::<u32>().ok()),
138+
parts.next().and_then(|s| s.parse::<u32>().ok())) {
139+
if major > 3 || (major == 3 && minor >= 8) {
140+
cmd.arg("--link-static");
141+
}
142+
}
143+
131144
if !is_crossed {
132145
cmd.arg("--system-libs");
133146
}

0 commit comments

Comments
 (0)