Skip to content

Commit 9ee4202

Browse files
2 parents 0fc814b + 9dd4dbf commit 9ee4202

File tree

11 files changed

+86
-16
lines changed

11 files changed

+86
-16
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: CI
22
on: [push, pull_request]
33

4+
env:
5+
RUSTDOCFLAGS: -Dwarnings
6+
RUSTFLAGS: -Dwarnings
7+
48
jobs:
59
test:
610
name: Test

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
authors = ["Jorge Aparicio <[email protected]>"]
33
name = "compiler_builtins"
4-
version = "0.1.111"
4+
version = "0.1.112"
55
license = "MIT/Apache-2.0"
66
readme = "README.md"
77
repository = "https://github.com/rust-lang/compiler-builtins"

build.rs

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ use std::{collections::BTreeMap, env, path::PathBuf, 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,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")]
149221
mod 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"

ci/run-docker.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ run() {
4848
docker run \
4949
--rm \
5050
-e RUST_COMPILER_RT_ROOT \
51+
-e RUSTFLAGS \
5152
-e "CARGO_TARGET_DIR=/builtins-target" \
5253
-v "$(pwd):/checkout:ro" \
5354
-w /checkout \

src/float/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub mod trunc;
1414

1515
public_test_dep! {
1616
/// Trait for some basic operations on floats
17+
#[allow(dead_code)]
1718
pub(crate) trait Float:
1819
Copy
1920
+ core::fmt::Debug

src/int/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub use self::leading_zeros::__clzsi2;
1313

1414
public_test_dep! {
1515
/// Trait for some basic operations on integers
16+
#[allow(dead_code)]
1617
pub(crate) trait Int:
1718
Copy
1819
+ core::fmt::Debug

src/x86.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use core::intrinsics;
1010
intrinsics! {
1111
#[naked]
1212
#[cfg(all(
13-
windows,
14-
target_env = "gnu",
13+
any(all(windows, target_env = "gnu"), target_os = "uefi"),
1514
not(feature = "no-asm")
1615
))]
1716
pub unsafe extern "C" fn __chkstk() {
@@ -23,8 +22,7 @@ intrinsics! {
2322

2423
#[naked]
2524
#[cfg(all(
26-
windows,
27-
target_env = "gnu",
25+
any(all(windows, target_env = "gnu"), target_os = "uefi"),
2826
not(feature = "no-asm")
2927
))]
3028
pub unsafe extern "C" fn _alloca() {

testcrate/tests/cmp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![allow(unused_macros)]
22

3+
#[cfg(not(target_arch = "powerpc64"))]
34
use testcrate::*;
45

56
macro_rules! cmp {

testcrate/tests/conv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ macro_rules! conv {
155155
stringify!($fn)
156156
);
157157
}
158-
});
158+
})
159159
};
160160
}
161161

testcrate/tests/misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// makes configuration easier
22
#![allow(unused_macros)]
33

4-
use compiler_builtins::float::Float;
54
use testcrate::*;
65

76
/// Make sure that the the edge case tester and randomized tester don't break, and list examples of
@@ -138,6 +137,7 @@ macro_rules! pow {
138137
#[test]
139138
fn float_pow() {
140139
use compiler_builtins::float::pow::{__powidf2, __powisf2};
140+
use compiler_builtins::float::Float;
141141

142142
pow!(
143143
f32, 1e-4, __powisf2;

0 commit comments

Comments
 (0)