@@ -2,13 +2,15 @@ use std::{collections::BTreeMap, env, sync::atomic::Ordering};
2
2
3
3
fn main ( ) {
4
4
println ! ( "cargo:rerun-if-changed=build.rs" ) ;
5
+ configure_check_cfg ( ) ;
5
6
6
7
let target = env:: var ( "TARGET" ) . unwrap ( ) ;
7
8
let cwd = env:: current_dir ( ) . unwrap ( ) ;
8
9
9
10
println ! ( "cargo:compiler-rt={}" , cwd. join( "compiler-rt" ) . display( ) ) ;
10
11
11
12
// Activate libm's unstable features to make full use of Nightly.
13
+ println ! ( "cargo::rustc-check-cfg=cfg(feature, values(\" unstable\" ))" ) ;
12
14
println ! ( "cargo:rustc-cfg=feature=\" unstable\" " ) ;
13
15
14
16
// Emscripten's runtime includes all the builtins
@@ -36,6 +38,7 @@ fn main() {
36
38
}
37
39
38
40
// These targets have hardware unaligned access support.
41
+ println ! ( "cargo::rustc-check-cfg=cfg(feature, values(\" mem-unaligned\" ))" ) ;
39
42
if target. contains ( "x86_64" )
40
43
|| target. contains ( "i686" )
41
44
|| target. contains ( "aarch64" )
@@ -64,20 +67,23 @@ fn main() {
64
67
}
65
68
66
69
// To compile intrinsics.rs for thumb targets, where there is no libc
70
+ println ! ( "cargo::rustc-check-cfg=cfg(thumb)" ) ;
67
71
if llvm_target[ 0 ] . starts_with ( "thumb" ) {
68
72
println ! ( "cargo:rustc-cfg=thumb" )
69
73
}
70
74
71
75
// compiler-rt `cfg`s away some intrinsics for thumbv6m and thumbv8m.base because
72
76
// these targets do not have full Thumb-2 support but only original Thumb-1.
73
77
// We have to cfg our code accordingly.
78
+ println ! ( "cargo::rustc-check-cfg=cfg(thumb_1)" ) ;
74
79
if llvm_target[ 0 ] == "thumbv6m" || llvm_target[ 0 ] == "thumbv8m.base" {
75
80
println ! ( "cargo:rustc-cfg=thumb_1" )
76
81
}
77
82
78
83
// Only emit the ARM Linux atomic emulation on pre-ARMv6 architectures. This
79
84
// includes the old androideabi. It is deprecated but it is available as a
80
85
// rustc target (arm-linux-androideabi).
86
+ println ! ( "cargo::rustc-check-cfg=cfg(kernel_user_helpers)" ) ;
81
87
if llvm_target[ 0 ] == "armv4t"
82
88
|| llvm_target[ 0 ] == "armv5te"
83
89
|| target == "arm-linux-androideabi"
@@ -145,6 +151,70 @@ fn generate_aarch64_outlined_atomics() {
145
151
std:: fs:: write ( dst, buf) . unwrap ( ) ;
146
152
}
147
153
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
+ for op_size in [ 1 , 2 , 4 , 8 ] . iter ( ) . chain ( if aarch_op == "cas" {
188
+ [ 16 ] . as_slice ( )
189
+ } else {
190
+ [ ] . as_slice ( )
191
+ } ) {
192
+ for ordering in [ "relax" , "acq" , "rel" , "acq_rel" ] {
193
+ aarch_atomic. push ( format ! ( "__aarch64_{}{}_{}" , aarch_op, op_size, ordering) ) ;
194
+ }
195
+ }
196
+ }
197
+
198
+ for fn_name in HAS_OPTIMIZED_C
199
+ . iter ( )
200
+ . copied ( )
201
+ . chain ( aarch_atomic. iter ( ) . map ( |s| s. as_str ( ) ) )
202
+ {
203
+ println ! (
204
+ "cargo::rustc-check-cfg=cfg({}, values(\" optimized-c\" ))" ,
205
+ fn_name
206
+ ) ;
207
+ }
208
+
209
+ // Rustc is unaware of sparc target features, but this does show up from
210
+ // `rustc --print target-features --target sparc64-unknown-linux-gnu`.
211
+ println ! ( "cargo::rustc-check-cfg=cfg(target_feature, values(\" vis3\" ))" ) ;
212
+
213
+ // FIXME: these come from libm and should be changed there
214
+ println ! ( "cargo::rustc-check-cfg=cfg(feature, values(\" checked\" ))" ) ;
215
+ println ! ( "cargo::rustc-check-cfg=cfg(assert_no_panic)" ) ;
216
+ }
217
+
148
218
#[ cfg( feature = "c" ) ]
149
219
mod c {
150
220
extern crate cc;
@@ -307,6 +377,7 @@ mod c {
307
377
// also needs to satisfy intrinsics that jemalloc or C in general may
308
378
// need, so include a few more that aren't typically needed by
309
379
// LLVM/Rust.
380
+ #[ allow( unexpected_cfgs) ]
310
381
if cfg ! ( feature = "rustbuild" ) {
311
382
sources. extend ( & [ ( "__ffsdi2" , "ffsdi2.c" ) ] ) ;
312
383
}
0 commit comments