@@ -17,30 +17,24 @@ use std::path::{PathBuf, Path};
17
17
18
18
use build_helper:: output;
19
19
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 ) ;
44
38
}
45
39
}
46
40
( "static" , None )
@@ -92,9 +86,25 @@ fn main() {
92
86
let host = env:: var ( "HOST" ) . expect ( "HOST was not set" ) ;
93
87
let is_crossed = target != host;
94
88
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
+ }
98
108
99
109
// FIXME: surely we don't need all these components, right? Stuff like mcjit
100
110
// or interpreter the compiler itself never uses.
@@ -158,7 +168,7 @@ fn main() {
158
168
. cpp_link_stdlib ( None ) // we handle this below
159
169
. compile ( "librustllvm.a" ) ;
160
170
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) ;
162
172
163
173
// Link in all LLVM libraries, if we're uwring the "wrong" llvm-config then
164
174
// we don't pick up system libs because unfortunately they're for the host
0 commit comments