Skip to content

Commit 5c7c876

Browse files
committed
Emit directives for cargo-check-cfg
1 parent 2001e76 commit 5c7c876

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

build.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ use std::{collections::BTreeMap, env, sync::atomic::Ordering};
22

33
fn 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,70 @@ fn generate_aarch64_outlined_atomics() {
145151
std::fs::write(dst, 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+
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+
148218
#[cfg(feature = "c")]
149219
mod c {
150220
extern crate cc;
@@ -307,6 +377,7 @@ mod c {
307377
// also needs to satisfy intrinsics that jemalloc or C in general may
308378
// need, so include a few more that aren't typically needed by
309379
// LLVM/Rust.
380+
#[allow(unexpected_cfgs)]
310381
if cfg!(feature = "rustbuild") {
311382
sources.extend(&[("__ffsdi2", "ffsdi2.c")]);
312383
}

ci/run-docker.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ run() {
4747
"ci/docker/$target"
4848
docker run \
4949
--rm \
50-
-e "RUSTFLAGS=${RUSTFLAGS:-}" \
50+
-e RUST_COMPILER_RT_ROOT \
51+
-e RUSTFLAGS \
5152
-e "CARGO_TARGET_DIR=/builtins-target" \
5253
-v "$(pwd):/checkout:ro" \
5354
-w /checkout \

0 commit comments

Comments
 (0)