@@ -2,13 +2,15 @@ use std::{collections::BTreeMap, env, path::PathBuf, sync::atomic::Ordering};
22
33fn main ( ) {
44 println ! ( "cargo:rerun-if-changed=build.rs" ) ;
5+ configure_check_cfg ( ) ;
56
67 let target = env:: var ( "TARGET" ) . unwrap ( ) ;
78 let cwd = env:: current_dir ( ) . unwrap ( ) ;
89
910 println ! ( "cargo:compiler-rt={}" , cwd. join( "compiler-rt" ) . display( ) ) ;
1011
1112 // Activate libm's unstable features to make full use of Nightly.
13+ println ! ( "cargo::rustc-check-cfg=cfg(feature, values(\" unstable\" ))" ) ;
1214 println ! ( "cargo:rustc-cfg=feature=\" unstable\" " ) ;
1315
1416 // Emscripten's runtime includes all the builtins
@@ -36,6 +38,7 @@ fn main() {
3638 }
3739
3840 // These targets have hardware unaligned access support.
41+ println ! ( "cargo::rustc-check-cfg=cfg(feature, values(\" mem-unaligned\" ))" ) ;
3942 if target. contains ( "x86_64" )
4043 || target. contains ( "i686" )
4144 || target. contains ( "aarch64" )
@@ -64,20 +67,23 @@ fn main() {
6467 }
6568
6669 // To compile intrinsics.rs for thumb targets, where there is no libc
70+ println ! ( "cargo::rustc-check-cfg=cfg(thumb)" ) ;
6771 if llvm_target[ 0 ] . starts_with ( "thumb" ) {
6872 println ! ( "cargo:rustc-cfg=thumb" )
6973 }
7074
7175 // compiler-rt `cfg`s away some intrinsics for thumbv6m and thumbv8m.base because
7276 // these targets do not have full Thumb-2 support but only original Thumb-1.
7377 // We have to cfg our code accordingly.
78+ println ! ( "cargo::rustc-check-cfg=cfg(thumb_1)" ) ;
7479 if llvm_target[ 0 ] == "thumbv6m" || llvm_target[ 0 ] == "thumbv8m.base" {
7580 println ! ( "cargo:rustc-cfg=thumb_1" )
7681 }
7782
7883 // Only emit the ARM Linux atomic emulation on pre-ARMv6 architectures. This
7984 // includes the old androideabi. It is deprecated but it is available as a
8085 // rustc target (arm-linux-androideabi).
86+ println ! ( "cargo::rustc-check-cfg=cfg(kernel_user_helpers)" ) ;
8187 if llvm_target[ 0 ] == "armv4t"
8288 || llvm_target[ 0 ] == "armv5te"
8389 || target == "arm-linux-androideabi"
@@ -145,6 +151,72 @@ fn generate_aarch64_outlined_atomics() {
145151 std:: fs:: write ( out_dir. join ( "outlined_atomics.rs" ) , buf) . unwrap ( ) ;
146152}
147153
154+ /// Emit directives for features we expect to support that aren't in `Cargo.toml`.
155+ ///
156+ /// These are mostly cfg elements emitted by this `build.rs`.
157+ fn configure_check_cfg ( ) {
158+ // Functions where we can set the "optimized-c" flag
159+ const HAS_OPTIMIZED_C : & [ & str ] = & [
160+ "__ashldi3" ,
161+ "__ashlsi3" ,
162+ "__ashrdi3" ,
163+ "__ashrsi3" ,
164+ "__clzsi2" ,
165+ "__divdi3" ,
166+ "__divsi3" ,
167+ "__divmoddi4" ,
168+ "__divmodsi4" ,
169+ "__divmodsi4" ,
170+ "__divmodti4" ,
171+ "__lshrdi3" ,
172+ "__lshrsi3" ,
173+ "__moddi3" ,
174+ "__modsi3" ,
175+ "__muldi3" ,
176+ "__udivdi3" ,
177+ "__udivmoddi4" ,
178+ "__udivmodsi4" ,
179+ "__udivsi3" ,
180+ "__umoddi3" ,
181+ "__umodsi3" ,
182+ ] ;
183+
184+ // Build a list of all aarch64 atomic operation functions
185+ let mut aarch_atomic = Vec :: new ( ) ;
186+ for aarch_op in [ "cas" , "ldadd" , "ldclr" , "ldeor" , "ldset" , "swp" ] {
187+ let op_sizes = if aarch_op == "cas" {
188+ [ 1 , 2 , 4 , 8 , 16 ] . as_slice ( )
189+ } else {
190+ [ 1 , 2 , 4 , 8 ] . as_slice ( )
191+ } ;
192+
193+ for op_size in op_sizes {
194+ for ordering in [ "relax" , "acq" , "rel" , "acq_rel" ] {
195+ aarch_atomic. push ( format ! ( "__aarch64_{}{}_{}" , aarch_op, op_size, ordering) ) ;
196+ }
197+ }
198+ }
199+
200+ for fn_name in HAS_OPTIMIZED_C
201+ . iter ( )
202+ . copied ( )
203+ . chain ( aarch_atomic. iter ( ) . map ( |s| s. as_str ( ) ) )
204+ {
205+ println ! (
206+ "cargo::rustc-check-cfg=cfg({}, values(\" optimized-c\" ))" ,
207+ fn_name
208+ ) ;
209+ }
210+
211+ // Rustc is unaware of sparc target features, but this does show up from
212+ // `rustc --print target-features --target sparc64-unknown-linux-gnu`.
213+ println ! ( "cargo::rustc-check-cfg=cfg(target_feature, values(\" vis3\" ))" ) ;
214+
215+ // FIXME: these come from libm and should be changed there
216+ println ! ( "cargo::rustc-check-cfg=cfg(feature, values(\" checked\" ))" ) ;
217+ println ! ( "cargo::rustc-check-cfg=cfg(assert_no_panic)" ) ;
218+ }
219+
148220#[ cfg( feature = "c" ) ]
149221mod c {
150222 extern crate cc;
@@ -303,14 +375,6 @@ mod c {
303375 ] ) ;
304376 }
305377
306- // When compiling in rustbuild (the rust-lang/rust repo) this library
307- // also needs to satisfy intrinsics that jemalloc or C in general may
308- // need, so include a few more that aren't typically needed by
309- // LLVM/Rust.
310- if cfg ! ( feature = "rustbuild" ) {
311- sources. extend ( & [ ( "__ffsdi2" , "ffsdi2.c" ) ] ) ;
312- }
313-
314378 // On iOS and 32-bit OSX these are all just empty intrinsics, no need to
315379 // include them.
316380 if target_os != "ios"
0 commit comments