Skip to content

Commit 32aeb22

Browse files
committed
Avoid the hexagon backend on old versions of LLVM
1 parent c558a2a commit 32aeb22

File tree

1 file changed

+38
-28
lines changed

1 file changed

+38
-28
lines changed

src/librustc_llvm/build.rs

+38-28
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,24 @@ use std::path::{PathBuf, Path};
1717

1818
use build_helper::output;
1919

20-
fn detect_llvm_link(llvm_config: &Path) -> (&'static str, Option<&'static str>) {
21-
let mut version_cmd = Command::new(llvm_config);
22-
version_cmd.arg("--version");
23-
let version_output = output(&mut version_cmd);
24-
let mut parts = version_output.split('.').take(2)
25-
.filter_map(|s| s.parse::<u32>().ok());
26-
if let (Some(major), Some(minor)) = (parts.next(), parts.next()) {
27-
if major > 3 || (major == 3 && minor >= 9) {
28-
// Force the link mode we want, preferring static by default, but
29-
// possibly overridden by `configure --enable-llvm-link-shared`.
30-
if env::var_os("LLVM_LINK_SHARED").is_some() {
31-
return ("dylib", Some("--link-shared"));
32-
} else {
33-
return ("static", Some("--link-static"));
34-
}
35-
} else if major == 3 && minor == 8 {
36-
// Find out LLVM's default linking mode.
37-
let mut mode_cmd = Command::new(llvm_config);
38-
mode_cmd.arg("--shared-mode");
39-
if output(&mut mode_cmd).trim() == "shared" {
40-
return ("dylib", None);
41-
} else {
42-
return ("static", None);
43-
}
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);
4438
}
4539
}
4640
("static", None)
@@ -92,9 +86,25 @@ fn main() {
9286
let host = env::var("HOST").expect("HOST was not set");
9387
let is_crossed = target != host;
9488

95-
let optional_components =
96-
["x86", "arm", "aarch64", "mips", "powerpc", "pnacl", "systemz", "jsbackend", "msp430",
97-
"sparc", "nvptx", "hexagon"];
89+
let mut optional_components =
90+
vec!["x86", "arm", "aarch64", "mips", "powerpc", "pnacl",
91+
"systemz", "jsbackend", "msp430", "sparc", "nvptx"];
92+
93+
let mut version_cmd = Command::new(&llvm_config);
94+
version_cmd.arg("--version");
95+
let version_output = output(&mut version_cmd);
96+
let mut parts = version_output.split('.').take(2)
97+
.filter_map(|s| s.parse::<u32>().ok());
98+
let (major, minor) =
99+
if let (Some(major), Some(minor)) = (parts.next(), parts.next()) {
100+
(major, minor)
101+
} else {
102+
(3, 7)
103+
};
104+
105+
if major > 3 {
106+
optional_components.push("hexagon");
107+
}
98108

99109
// FIXME: surely we don't need all these components, right? Stuff like mcjit
100110
// or interpreter the compiler itself never uses.
@@ -158,7 +168,7 @@ fn main() {
158168
.cpp_link_stdlib(None) // we handle this below
159169
.compile("librustllvm.a");
160170

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

163173
// Link in all LLVM libraries, if we're uwring the "wrong" llvm-config then
164174
// we don't pick up system libs because unfortunately they're for the host

0 commit comments

Comments
 (0)