Skip to content

Commit 4742008

Browse files
authored
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
2 parents 2a44315 + bcfbbd8 commit 4742008

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)