@@ -9,17 +9,6 @@ fn main() {
9
9
// the rustc version.
10
10
println ! ( "cargo:rerun-if-changed=build.rs" ) ;
11
11
12
- use_feature_or_nothing ( "rustc_attrs" ) ;
13
-
14
- // Features only used in no-std configurations.
15
- #[ cfg( not( feature = "std" ) ) ]
16
- {
17
- use_feature_or_nothing ( "core_c_str" ) ;
18
- use_feature_or_nothing ( "core_ffi_c" ) ;
19
- use_feature_or_nothing ( "alloc_c_string" ) ;
20
- use_feature_or_nothing ( "alloc_ffi" ) ;
21
- }
22
-
23
12
// Gather target information.
24
13
let arch = var ( "CARGO_CFG_TARGET_ARCH" ) . unwrap ( ) ;
25
14
let env = var ( "CARGO_CFG_TARGET_ENV" ) . unwrap ( ) ;
@@ -45,6 +34,13 @@ fn main() {
45
34
// enable the libc backend even if rustix is depended on transitively.
46
35
let cfg_use_libc = var ( "CARGO_CFG_RUSTIX_USE_LIBC" ) . is_ok ( ) ;
47
36
37
+ // Check for eg. `RUSTFLAGS=--cfg=rustix_use_experimental_features`. This
38
+ // is a rustc flag rather than a cargo feature flag because it's
39
+ // experimental and not something we want accidentally enabled via
40
+ // `--all-features`.
41
+ let rustix_use_experimental_features =
42
+ var ( "CARGO_CFG_RUSTIX_USE_EXPERIMENTAL_FEATURES" ) . is_ok ( ) ;
43
+
48
44
// Check for eg. `RUSTFLAGS=--cfg=rustix_use_experimental_asm`. This is a
49
45
// rustc flag rather than a cargo feature flag because it's experimental
50
46
// and not something we want accidentally enabled via `--all-features`.
@@ -54,6 +50,27 @@ fn main() {
54
50
// libc FFI calls, so if we're running under miri, use the libc backend.
55
51
let miri = var ( "CARGO_CFG_MIRI" ) . is_ok ( ) ;
56
52
53
+ // If experimental features are enabled, auto-detect and use available
54
+ // features.
55
+ if rustix_use_experimental_features {
56
+ use_feature_or_nothing ( "rustc_attrs" ) ;
57
+ use_feature_or_nothing ( "core_intrinsics" ) ;
58
+ }
59
+
60
+ // Features needed only in no-std configurations.
61
+ #[ cfg( not( feature = "std" ) ) ]
62
+ {
63
+ use_feature_or_nothing ( "core_c_str" ) ;
64
+ use_feature_or_nothing ( "core_ffi_c" ) ;
65
+ use_feature_or_nothing ( "alloc_c_string" ) ;
66
+ use_feature_or_nothing ( "alloc_ffi" ) ;
67
+ }
68
+
69
+ // Feature needed for testing.
70
+ if use_static_assertions ( ) {
71
+ use_feature ( "static_assertions" ) ;
72
+ }
73
+
57
74
// If the libc backend is requested, or if we're not on a platform for
58
75
// which we have linux_raw support, use the libc backend.
59
76
//
@@ -74,7 +91,6 @@ fn main() {
74
91
} else {
75
92
// Use the linux_raw backend.
76
93
use_feature ( "linux_raw" ) ;
77
- use_feature_or_nothing ( "core_intrinsics" ) ;
78
94
if rustix_use_experimental_asm {
79
95
use_feature ( "asm_experimental_arch" ) ;
80
96
}
@@ -133,14 +149,6 @@ fn main() {
133
149
use_feature ( "fix_y2038" ) ;
134
150
}
135
151
136
- if os == "wasi" {
137
- use_feature_or_nothing ( "wasi_ext" ) ;
138
- }
139
-
140
- if use_static_assertions ( ) {
141
- use_feature ( "static_assertions" ) ;
142
- }
143
-
144
152
println ! ( "cargo:rerun-if-env-changed=CARGO_CFG_RUSTIX_USE_EXPERIMENTAL_ASM" ) ;
145
153
println ! ( "cargo:rerun-if-env-changed=CARGO_CFG_RUSTIX_USE_LIBC" ) ;
146
154
0 commit comments