Skip to content

Commit 5c4452a

Browse files
committed
rustc_llvm: Assume at least LLVM 3.9 in build.rs
1 parent 51342f1 commit 5c4452a

File tree

1 file changed

+12
-32
lines changed

1 file changed

+12
-32
lines changed

src/librustc_llvm/build.rs

+12-32
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,14 @@ use std::path::{PathBuf, Path};
1717

1818
use build_helper::output;
1919

20-
fn detect_llvm_link(major: u32, minor: u32, llvm_config: &Path)
21-
-> (&'static str, Option<&'static str>) {
22-
if major > 3 || (major == 3 && minor >= 9) {
23-
// Force the link mode we want, preferring static by default, but
24-
// possibly overridden by `configure --enable-llvm-link-shared`.
25-
if env::var_os("LLVM_LINK_SHARED").is_some() {
26-
return ("dylib", Some("--link-shared"));
27-
} else {
28-
return ("static", Some("--link-static"));
29-
}
30-
} else if major == 3 && minor == 8 {
31-
// Find out LLVM's default linking mode.
32-
let mut mode_cmd = Command::new(llvm_config);
33-
mode_cmd.arg("--shared-mode");
34-
if output(&mut mode_cmd).trim() == "shared" {
35-
return ("dylib", None);
36-
} else {
37-
return ("static", None);
38-
}
20+
fn detect_llvm_link() -> (&'static str, &'static str) {
21+
// Force the link mode we want, preferring static by default, but
22+
// possibly overridden by `configure --enable-llvm-link-shared`.
23+
if env::var_os("LLVM_LINK_SHARED").is_some() {
24+
("dylib", "--link-shared")
25+
} else {
26+
("static", "--link-static")
3927
}
40-
("static", None)
4128
}
4229

4330
fn main() {
@@ -96,11 +83,11 @@ fn main() {
9683
let version_output = output(&mut version_cmd);
9784
let mut parts = version_output.split('.').take(2)
9885
.filter_map(|s| s.parse::<u32>().ok());
99-
let (major, minor) =
86+
let (major, _minor) =
10087
if let (Some(major), Some(minor)) = (parts.next(), parts.next()) {
10188
(major, minor)
10289
} else {
103-
(3, 7)
90+
(3, 9)
10491
};
10592

10693
if major > 3 {
@@ -171,17 +158,13 @@ fn main() {
171158
.cpp_link_stdlib(None) // we handle this below
172159
.compile("librustllvm.a");
173160

174-
let (llvm_kind, llvm_link_arg) = detect_llvm_link(major, minor, &llvm_config);
161+
let (llvm_kind, llvm_link_arg) = detect_llvm_link();
175162

176163
// Link in all LLVM libraries, if we're uwring the "wrong" llvm-config then
177164
// we don't pick up system libs because unfortunately they're for the host
178165
// of llvm-config, not the target that we're attempting to link.
179166
let mut cmd = Command::new(&llvm_config);
180-
cmd.arg("--libs");
181-
182-
if let Some(link_arg) = llvm_link_arg {
183-
cmd.arg(link_arg);
184-
}
167+
cmd.arg(llvm_link_arg).arg("--libs");
185168

186169
if !is_crossed {
187170
cmd.arg("--system-libs");
@@ -230,10 +213,7 @@ fn main() {
230213
// hack around this by replacing the host triple with the target and pray
231214
// that those -L directories are the same!
232215
let mut cmd = Command::new(&llvm_config);
233-
if let Some(link_arg) = llvm_link_arg {
234-
cmd.arg(link_arg);
235-
}
236-
cmd.arg("--ldflags");
216+
cmd.arg(llvm_link_arg).arg("--ldflags");
237217
for lib in output(&mut cmd).split_whitespace() {
238218
if lib.starts_with("-LIBPATH:") {
239219
println!("cargo:rustc-link-search=native={}", &lib[9..]);

0 commit comments

Comments
 (0)