From 324b66c553085c5e24c00a70e563beddc3beb89f Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 23 May 2024 15:20:25 +0200 Subject: [PATCH 1/4] Expect any feature cfg in core and std crates --- library/core/Cargo.toml | 4 +++- library/std/Cargo.toml | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/library/core/Cargo.toml b/library/core/Cargo.toml index daf2612833ddc..0c2642341235b 100644 --- a/library/core/Cargo.toml +++ b/library/core/Cargo.toml @@ -46,6 +46,8 @@ check-cfg = [ 'cfg(bootstrap)', 'cfg(no_fp_fmt_parse)', 'cfg(stdarch_intel_sde)', - # This matches `EXTRA_CHECK_CFGS` in `src/bootstrap/src/lib.rs`. + # core use #[path] imports to portable-simd `core_simd` crate + # and to stdarch `core_arch` crate which messes-up with Cargo list + # of declared features, we therefor expect any feature cfg 'cfg(feature, values(any()))', ] diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index 4b8ee4c130918..4b9e827247e74 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -105,5 +105,8 @@ check-cfg = [ 'cfg(backtrace_in_libstd)', 'cfg(netbsd10)', 'cfg(target_arch, values("xtensa"))', - 'cfg(feature, values("std", "as_crate"))', + # std use #[path] imports to portable-simd `std_float` crate + # and to the `backtrace` crate which messes-up with Cargo list + # of declared features, we therefor expect any feature cfg + 'cfg(feature, values(any()))', ] From a59589b1cc7799ac847763ef0395f4d48aabf883 Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 23 May 2024 15:30:46 +0200 Subject: [PATCH 2/4] Replace fake "restricted-std" Cargo feature by custom cfg --- library/std/build.rs | 3 ++- library/std/src/lib.rs | 4 ++-- src/bootstrap/src/lib.rs | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/library/std/build.rs b/library/std/build.rs index 7a47b52e8e4eb..04f6f666875c0 100644 --- a/library/std/build.rs +++ b/library/std/build.rs @@ -10,6 +10,7 @@ fn main() { if target_os == "netbsd" && env::var("RUSTC_STD_NETBSD10").is_ok() { println!("cargo:rustc-cfg=netbsd10"); } + println!("cargo:rustc-check-cfg=cfg(restricted_std)"); if target_os == "linux" || target_os == "android" || target_os == "netbsd" @@ -59,7 +60,7 @@ fn main() { // - arch=avr // - JSON targets // - Any new targets that have not been explicitly added above. - println!("cargo:rustc-cfg=feature=\"restricted-std\""); + println!("cargo:rustc-cfg=restricted_std"); } println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap()); println!("cargo:rustc-cfg=backtrace_in_libstd"); diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 949c543a26479..4a18db3d5a3fc 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -213,9 +213,9 @@ //! [array]: prim@array //! [slice]: prim@slice -#![cfg_attr(not(feature = "restricted-std"), stable(feature = "rust1", since = "1.0.0"))] +#![cfg_attr(not(restricted_std), stable(feature = "rust1", since = "1.0.0"))] #![cfg_attr( - feature = "restricted-std", + restricted_std, unstable( feature = "restricted_std", issue = "none", diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 38de5e3800005..af9fc32c98c40 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -94,6 +94,7 @@ const EXTRA_CHECK_CFGS: &[(Option, &str, Option<&[&'static str]>)] = &[ (Some(Mode::Std), "no_sync", None), (Some(Mode::Std), "netbsd10", None), (Some(Mode::Std), "backtrace_in_libstd", None), + (Some(Mode::Std), "restricted_std", None), /* Extra values not defined in the built-in targets yet, but used in std */ (Some(Mode::Std), "target_env", Some(&["libnx", "p2"])), (Some(Mode::Std), "target_os", Some(&["visionos"])), From 28689850e52efea0de8e76eb1a9d4aa6de098061 Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 23 May 2024 15:41:34 +0200 Subject: [PATCH 3/4] Move some expected cfgs to std build.rs as per Cargo recommandation --- library/std/Cargo.toml | 2 -- library/std/build.rs | 8 +++++++- src/bootstrap/src/lib.rs | 3 --- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index 4b9e827247e74..db4aea6a1ea64 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -102,8 +102,6 @@ test = true level = "warn" check-cfg = [ 'cfg(bootstrap)', - 'cfg(backtrace_in_libstd)', - 'cfg(netbsd10)', 'cfg(target_arch, values("xtensa"))', # std use #[path] imports to portable-simd `std_float` crate # and to the `backtrace` crate which messes-up with Cargo list diff --git a/library/std/build.rs b/library/std/build.rs index 04f6f666875c0..7d975df545ecf 100644 --- a/library/std/build.rs +++ b/library/std/build.rs @@ -7,9 +7,12 @@ fn main() { let target_vendor = env::var("CARGO_CFG_TARGET_VENDOR").expect("CARGO_CFG_TARGET_VENDOR was not set"); let target_env = env::var("CARGO_CFG_TARGET_ENV").expect("CARGO_CFG_TARGET_ENV was not set"); + + println!("cargo:rustc-check-cfg=cfg(netbsd10)"); if target_os == "netbsd" && env::var("RUSTC_STD_NETBSD10").is_ok() { println!("cargo:rustc-cfg=netbsd10"); } + println!("cargo:rustc-check-cfg=cfg(restricted_std)"); if target_os == "linux" || target_os == "android" @@ -62,6 +65,9 @@ fn main() { // - Any new targets that have not been explicitly added above. println!("cargo:rustc-cfg=restricted_std"); } - println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap()); + + println!("cargo:rustc-check-cfg=cfg(backtrace_in_libstd)"); println!("cargo:rustc-cfg=backtrace_in_libstd"); + + println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap()); } diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index af9fc32c98c40..52c94465cd33d 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -92,9 +92,6 @@ const EXTRA_CHECK_CFGS: &[(Option, &str, Option<&[&'static str]>)] = &[ (Some(Mode::Std), "no_global_oom_handling", None), (Some(Mode::Std), "no_rc", None), (Some(Mode::Std), "no_sync", None), - (Some(Mode::Std), "netbsd10", None), - (Some(Mode::Std), "backtrace_in_libstd", None), - (Some(Mode::Std), "restricted_std", None), /* Extra values not defined in the built-in targets yet, but used in std */ (Some(Mode::Std), "target_env", Some(&["libnx", "p2"])), (Some(Mode::Std), "target_os", Some(&["visionos"])), From 45ad60d05ad904e1a3de1089480a614fcd4e90dd Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 23 May 2024 15:53:28 +0200 Subject: [PATCH 4/4] Copy core/alloc check-cfg message also in std --- library/std/Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index db4aea6a1ea64..e56f03808b311 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -100,6 +100,9 @@ test = true [lints.rust.unexpected_cfgs] level = "warn" +# x.py uses beta cargo, so `check-cfg` entries do not yet take effect +# for rust-lang/rust. But for users of `-Zbuild-std` it does. +# The unused warning is waiting for rust-lang/cargo#13925 to reach beta. check-cfg = [ 'cfg(bootstrap)', 'cfg(target_arch, values("xtensa"))',