This repository was archived by the owner on Apr 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +34
-11
lines changed
crates/compiler-builtins-smoke-test Expand file tree Collapse file tree 7 files changed +34
-11
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,11 @@ unstable = ["unstable-intrinsics"]
24
24
unstable-intrinsics = []
25
25
26
26
# Used to prevent using any intrinsics or arch-specific code.
27
+ #
28
+ # HACK: this is a negative feature which is generally a bad idea in Cargo, but
29
+ # we need it to be able to forbid other features when this crate is used in
30
+ # Rust dependencies. Setting this overrides all features that may enable
31
+ # hard float operations.
27
32
force-soft-floats = []
28
33
29
34
[workspace ]
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ use std::env;
3
3
fn main ( ) {
4
4
println ! ( "cargo:rerun-if-changed=build.rs" ) ;
5
5
println ! ( "cargo:rustc-check-cfg=cfg(assert_no_panic)" ) ;
6
- println ! ( "cargo:rustc-check-cfg=cfg(feature, values(\" unstable\" ))" ) ;
7
6
8
7
println ! ( "cargo:rustc-check-cfg=cfg(feature, values(\" checked\" ))" ) ;
9
8
@@ -14,4 +13,18 @@ fn main() {
14
13
println ! ( "cargo:rustc-cfg=assert_no_panic" ) ;
15
14
}
16
15
}
16
+
17
+ configure_intrinsics ( ) ;
18
+ }
19
+
20
+ /// Simplify the feature logic for enabling intrinsics so code only needs to use
21
+ /// `cfg(intrinsics_enabled)`.
22
+ fn configure_intrinsics ( ) {
23
+ println ! ( "cargo:rustc-check-cfg=cfg(intrinsics_enabled)" ) ;
24
+
25
+ // Disabled by default; `unstable-intrinsics` enables again; `force-soft-floats` overrides
26
+ // to disable.
27
+ if cfg ! ( feature = "unstable-intrinsics" ) && !cfg ! ( feature = "force-soft-floats" ) {
28
+ println ! ( "cargo:rustc-cfg=intrinsics_enabled" ) ;
29
+ }
17
30
}
Original file line number Diff line number Diff line change @@ -46,6 +46,10 @@ if [ "$(uname -a)" = "Linux" ]; then
46
46
extra_flags=" $extra_flags --features libm-test/test-musl-serialized"
47
47
fi
48
48
49
+ # Make sure we can build with overriding features. We test the indibidual
50
+ # features it controls separately.
51
+ cargo check --features " force-soft-floats"
52
+
49
53
if [ " ${BUILD_ONLY:- } " = " 1" ]; then
50
54
cmd=" cargo build --target $target --package libm"
51
55
$cmd
Original file line number Diff line number Diff line change @@ -15,3 +15,9 @@ unstable = []
15
15
unstable-intrinsics = []
16
16
checked = []
17
17
force-soft-floats = []
18
+
19
+ [lints .rust ]
20
+ unexpected_cfgs = { level = " warn" , check-cfg = [
21
+ " cfg(assert_no_panic)" ,
22
+ " cfg(intrinsics_enabled)" ,
23
+ ] }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
//! libm in pure Rust
2
2
#![ no_std]
3
- #![ cfg_attr( feature = "unstable-intrinsics" , allow( internal_features) ) ]
4
- #![ cfg_attr( feature = "unstable-intrinsics" , feature( core_intrinsics) ) ]
3
+ #![ cfg_attr( intrinsics_enabled , allow( internal_features) ) ]
4
+ #![ cfg_attr( intrinsics_enabled , feature( core_intrinsics) ) ]
5
5
#![ allow( clippy:: assign_op_pattern) ]
6
6
#![ allow( clippy:: deprecated_cfg_attr) ]
7
7
#![ allow( clippy:: eq_op) ]
Original file line number Diff line number Diff line change @@ -60,14 +60,14 @@ macro_rules! i {
60
60
// the time of this writing this is only used in a few places, and once
61
61
// rust-lang/rust#72751 is fixed then this macro will no longer be necessary and
62
62
// the native `/` operator can be used and panics won't be codegen'd.
63
- #[ cfg( any( debug_assertions, not( feature = "unstable-intrinsics" ) ) ) ]
63
+ #[ cfg( any( debug_assertions, not( intrinsics_enabled ) ) ) ]
64
64
macro_rules! div {
65
65
( $a: expr, $b: expr) => {
66
66
$a / $b
67
67
} ;
68
68
}
69
69
70
- #[ cfg( all( not( debug_assertions) , feature = "unstable-intrinsics" ) ) ]
70
+ #[ cfg( all( not( debug_assertions) , intrinsics_enabled ) ) ]
71
71
macro_rules! div {
72
72
( $a: expr, $b: expr) => {
73
73
unsafe { core:: intrinsics:: unchecked_div( $a, $b) }
@@ -76,9 +76,7 @@ macro_rules! div {
76
76
77
77
macro_rules! llvm_intrinsically_optimized {
78
78
( #[ cfg( $( $clause: tt) * ) ] $e: expr) => {
79
- #[ cfg( all(
80
- feature = "unstable-intrinsics" , not( feature = "force-soft-floats" ) , $( $clause) *
81
- ) ) ]
79
+ #[ cfg( all( intrinsics_enabled, not( feature = "force-soft-floats" ) , $( $clause) * ) ) ]
82
80
{
83
81
if true { // thwart the dead code lint
84
82
$e
You can’t perform that action at this time.
0 commit comments