@@ -4,6 +4,29 @@ use std::fmt::Display;
44use std:: path:: { Path , PathBuf } ;
55use std:: process:: { Command , Stdio } ;
66
7+ const OPTIONAL_COMPONENTS : & [ & str ] = & [
8+ "x86" ,
9+ "arm" ,
10+ "aarch64" ,
11+ "amdgpu" ,
12+ "avr" ,
13+ "m68k" ,
14+ "mips" ,
15+ "powerpc" ,
16+ "systemz" ,
17+ "jsbackend" ,
18+ "webassembly" ,
19+ "msp430" ,
20+ "sparc" ,
21+ "nvptx" ,
22+ "hexagon" ,
23+ "riscv" ,
24+ "bpf" ,
25+ ] ;
26+
27+ const REQUIRED_COMPONENTS : & [ & str ] =
28+ & [ "ipo" , "bitreader" , "bitwriter" , "linker" , "asmparser" , "lto" , "coverage" , "instrumentation" ] ;
29+
730fn detect_llvm_link ( ) -> ( & ' static str , & ' static str ) {
831 // Force the link mode we want, preferring static by default, but
932 // possibly overridden by `configure --enable-llvm-link-shared`.
@@ -76,6 +99,10 @@ fn output(cmd: &mut Command) -> String {
7699}
77100
78101fn main ( ) {
102+ for component in REQUIRED_COMPONENTS . iter ( ) . chain ( OPTIONAL_COMPONENTS . iter ( ) ) {
103+ println ! ( "cargo:rustc-check-cfg=values(llvm_component,\" {}\" )" , component) ;
104+ }
105+
79106 if tracked_env_var_os ( "RUST_CHECK" ) . is_some ( ) {
80107 // If we're just running `check`, there's no need for LLVM to be built.
81108 return ;
@@ -131,42 +158,11 @@ fn main() {
131158 let host = env:: var ( "HOST" ) . expect ( "HOST was not set" ) ;
132159 let is_crossed = target != host;
133160
134- let optional_components = & [
135- "x86" ,
136- "arm" ,
137- "aarch64" ,
138- "amdgpu" ,
139- "avr" ,
140- "m68k" ,
141- "mips" ,
142- "powerpc" ,
143- "systemz" ,
144- "jsbackend" ,
145- "webassembly" ,
146- "msp430" ,
147- "sparc" ,
148- "nvptx" ,
149- "hexagon" ,
150- "riscv" ,
151- "bpf" ,
152- ] ;
153-
154- let required_components = & [
155- "ipo" ,
156- "bitreader" ,
157- "bitwriter" ,
158- "linker" ,
159- "asmparser" ,
160- "lto" ,
161- "coverage" ,
162- "instrumentation" ,
163- ] ;
164-
165161 let components = output ( Command :: new ( & llvm_config) . arg ( "--components" ) ) ;
166162 let mut components = components. split_whitespace ( ) . collect :: < Vec < _ > > ( ) ;
167- components. retain ( |c| optional_components . contains ( c) || required_components . contains ( c) ) ;
163+ components. retain ( |c| OPTIONAL_COMPONENTS . contains ( c) || REQUIRED_COMPONENTS . contains ( c) ) ;
168164
169- for component in required_components {
165+ for component in REQUIRED_COMPONENTS {
170166 if !components. contains ( component) {
171167 panic ! ( "require llvm component {} but wasn't found" , component) ;
172168 }
0 commit comments