From 4ca22fa9532dcba26e9138f0fd9b4cd592020923 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Wed, 27 Nov 2024 17:10:52 -0500 Subject: [PATCH 1/3] Fix the build with `rustc-dep-of-std` Since [1] we use derive macros rather than manually implementing `Clone` and `Copy`. However, this caused the build in `std` to start failing since the `core` prelude is not available. This provides the derive macros as well as `derive` itself. Resolve this by using complete paths. Additionally allow `internal_features` to suppress the warning using `link_cfg`, and change to using global paths for all uses of `core`. Link: https://github.com/rust-lang/libc/pull/4038 [1] (backport ) (cherry picked from commit d69ad56bd8c12329780739d42f9ed8392814595b) --- src/lib.rs | 1 + src/macros.rs | 33 +++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1be0a003382d..4e73243af7e5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,6 +21,7 @@ // Attributes needed when building as part of the standard library #![cfg_attr(feature = "rustc-dep-of-std", feature(link_cfg, no_core))] #![cfg_attr(libc_thread_local, feature(thread_local))] +#![cfg_attr(feature = "rustc-dep-of-std", allow(internal_features))] // Enable extra lints: #![cfg_attr(feature = "extra_traits", deny(missing_debug_implementations))] #![deny(missing_copy_implementations, safe_packed_borrows)] diff --git a/src/macros.rs b/src/macros.rs index 2ea084398da4..3bfac90518ad 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -70,13 +70,13 @@ macro_rules! prelude { mod prelude { // Exports from `core` #[allow(unused_imports)] - pub(crate) use core::clone::Clone; + pub(crate) use ::core::clone::Clone; #[allow(unused_imports)] - pub(crate) use core::marker::{Copy, Send, Sync}; + pub(crate) use ::core::marker::{Copy, Send, Sync}; #[allow(unused_imports)] - pub(crate) use core::option::Option; + pub(crate) use ::core::option::Option; #[allow(unused_imports)] - pub(crate) use core::{fmt, hash, iter, mem}; + pub(crate) use ::core::{fmt, hash, iter, mem}; // Commonly used types defined in this crate #[allow(unused_imports)] @@ -108,8 +108,11 @@ macro_rules! s { (it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => ( __item! { #[repr(C)] - #[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))] - #[derive(Copy, Clone)] + #[cfg_attr( + feature = "extra_traits", + ::core::prelude::v1::derive(Debug, Eq, Hash, PartialEq) + )] + #[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)] #[allow(deprecated)] $(#[$attr])* pub struct $i { $($field)* } @@ -127,8 +130,11 @@ macro_rules! s_paren { pub struct $i:ident ( $($field:tt)* ); )*) => ($( __item! { - #[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))] - #[derive(Copy, Clone)] + #[cfg_attr( + feature = "extra_traits", + ::core::prelude::v1::derive(Debug, Eq, Hash, PartialEq) + )] + #[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)] $(#[$attr])* pub struct $i ( $($field)* ); } @@ -149,7 +155,7 @@ macro_rules! s_no_extra_traits { (it: $(#[$attr:meta])* pub union $i:ident { $($field:tt)* }) => ( __item! { #[repr(C)] - #[derive(Copy, Clone)] + #[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)] $(#[$attr])* pub union $i { $($field)* } } @@ -158,7 +164,7 @@ macro_rules! s_no_extra_traits { (it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => ( __item! { #[repr(C)] - #[derive(Copy, Clone)] + #[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)] $(#[$attr])* pub struct $i { $($field)* } } @@ -186,8 +192,11 @@ macro_rules! e { pub enum $i:ident { $($field:tt)* } )*) => ($( __item! { - #[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))] - #[derive(Copy, Clone)] + #[cfg_attr( + feature = "extra_traits", + ::core::prelude::v1::derive(Debug, Eq, Hash, PartialEq) + )] + #[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)] $(#[$attr])* pub enum $i { $($field)* } } From 96db1f4edb862c32d4f1cf9708188359eb475774 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Wed, 27 Nov 2024 22:14:21 -0500 Subject: [PATCH 2/3] ci: test with `rustc-dep-of-std` Add a test that the crate builds correctly with the configuration that is used in `std`. (backport ) (cherry picked from commit 9839a9ab3727e8046afb1951b4e3ace016b64476) --- ci/verify-build.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ci/verify-build.sh b/ci/verify-build.sh index e1cad0b7df57..97d6bba4f822 100755 --- a/ci/verify-build.sh +++ b/ci/verify-build.sh @@ -70,6 +70,11 @@ test_target() { $cmd --no-default-features $cmd --no-default-features --features extra_traits + # Ensure the crate will build when used with `std` + if [ "$rust" = "nightly" ]; then + $cmd --no-default-features --features rustc-dep-of-std + fi + # For tier 2 freebsd targets, check with the different versions we support # if on nightly or stable case "$rust-$target" in From 70b1487bb06aaaeb12df794fe9b6dda4121de591 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Wed, 27 Nov 2024 23:27:11 -0500 Subject: [PATCH 3/3] Alow `static_mut_refs` with `rustc-dep-of-std` This combination raises an error suggesting `&raw mut errno`. This was removed in 1.0, but allow the lint on 0.2 for now. --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 4e73243af7e5..9ac6df16073e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,6 +22,8 @@ #![cfg_attr(feature = "rustc-dep-of-std", feature(link_cfg, no_core))] #![cfg_attr(libc_thread_local, feature(thread_local))] #![cfg_attr(feature = "rustc-dep-of-std", allow(internal_features))] +// DIFF(1.0): The thread local references that raise this lint were removed in 1.0 +#![cfg_attr(feature = "rustc-dep-of-std", allow(static_mut_refs))] // Enable extra lints: #![cfg_attr(feature = "extra_traits", deny(missing_debug_implementations))] #![deny(missing_copy_implementations, safe_packed_borrows)]