Skip to content

Commit

Permalink
Expose cfg_{has,no}_atomic_* macros
Browse files Browse the repository at this point in the history
Closes #133
  • Loading branch information
taiki-e committed Dec 3, 2023
1 parent 9b55bfa commit f388319
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 21 deletions.
97 changes: 85 additions & 12 deletions src/cfgs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

#![allow(missing_docs)]

#[cfg(not(all(
portable_atomic_no_atomic_load_store,
not(any(
Expand All @@ -12,20 +14,26 @@
)))]
#[macro_use]
mod atomic_8_16_macros {
#[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API)
#[macro_export]
macro_rules! cfg_has_atomic_8 {
($($tt:tt)*) => {
$($tt)*
};
}
#[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API)
#[macro_export]
macro_rules! cfg_no_atomic_8 {
($($tt:tt)*) => {};
}
#[macro_export]
macro_rules! cfg_has_atomic_16 {
($($tt:tt)*) => {
$($tt)*
};
}
#[macro_export]
macro_rules! cfg_no_atomic_16 {
($($tt:tt)*) => {};
}
}
#[cfg(all(
portable_atomic_no_atomic_load_store,
Expand All @@ -39,16 +47,26 @@ mod atomic_8_16_macros {
))]
#[macro_use]
mod atomic_8_16_macros {
#[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API)
#[macro_export]
macro_rules! cfg_has_atomic_8 {
($($tt:tt)*) => {};
}
#[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API)
#[macro_export]
macro_rules! cfg_no_atomic_8 {
($($tt:tt)*) => {
$($tt)*
};
}
#[macro_export]
macro_rules! cfg_has_atomic_16 {
($($tt:tt)*) => {};
}
#[macro_export]
macro_rules! cfg_no_atomic_16 {
($($tt:tt)*) => {
$($tt)*
};
}
}

#[cfg(all(
Expand All @@ -66,13 +84,16 @@ mod atomic_8_16_macros {
))]
#[macro_use]
mod atomic_32_macros {
#[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API)
#[macro_export]
macro_rules! cfg_has_atomic_32 {
($($tt:tt)*) => {
$($tt)*
};
}
#[macro_export]
macro_rules! cfg_no_atomic_32 {
($($tt:tt)*) => {};
}
}
#[cfg(not(all(
any(not(target_pointer_width = "16"), feature = "fallback"),
Expand All @@ -89,11 +110,16 @@ mod atomic_32_macros {
)))]
#[macro_use]
mod atomic_32_macros {
#[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API)
#[macro_export]
macro_rules! cfg_has_atomic_32 {
($($tt:tt)*) => {};
}
#[macro_export]
macro_rules! cfg_no_atomic_32 {
($($tt:tt)*) => {
$($tt)*
};
}
}

#[cfg_attr(
Expand Down Expand Up @@ -132,13 +158,16 @@ mod atomic_32_macros {
)]
#[macro_use]
mod atomic_64_macros {
#[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API)
#[macro_export]
macro_rules! cfg_has_atomic_64 {
($($tt:tt)*) => {
$($tt)*
};
}
#[macro_export]
macro_rules! cfg_no_atomic_64 {
($($tt:tt)*) => {};
}
}
#[cfg_attr(
portable_atomic_no_cfg_target_has_atomic,
Expand Down Expand Up @@ -176,11 +205,16 @@ mod atomic_64_macros {
)]
#[macro_use]
mod atomic_64_macros {
#[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API)
#[macro_export]
macro_rules! cfg_has_atomic_64 {
($($tt:tt)*) => {};
}
#[macro_export]
macro_rules! cfg_no_atomic_64 {
($($tt:tt)*) => {
$($tt)*
};
}
}

#[cfg_attr(
Expand Down Expand Up @@ -258,13 +292,16 @@ mod atomic_64_macros {
)]
#[macro_use]
mod atomic_128_macros {
#[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API)
#[macro_export]
macro_rules! cfg_has_atomic_128 {
($($tt:tt)*) => {
$($tt)*
};
}
#[macro_export]
macro_rules! cfg_no_atomic_128 {
($($tt:tt)*) => {};
}
}
#[cfg_attr(
not(feature = "fallback"),
Expand Down Expand Up @@ -341,11 +378,16 @@ mod atomic_128_macros {
)]
#[macro_use]
mod atomic_128_macros {
#[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API)
#[macro_export]
macro_rules! cfg_has_atomic_128 {
($($tt:tt)*) => {};
}
#[macro_export]
macro_rules! cfg_no_atomic_128 {
($($tt:tt)*) => {
$($tt)*
};
}
}

#[cfg_attr(
Expand All @@ -370,13 +412,16 @@ mod atomic_128_macros {
)]
#[macro_use]
mod atomic_cas_macros {
#[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API)
#[macro_export]
macro_rules! cfg_has_atomic_cas {
($($tt:tt)*) => {
$($tt)*
};
}
#[macro_export]
macro_rules! cfg_no_atomic_cas {
($($tt:tt)*) => {};
}
}
#[cfg_attr(
portable_atomic_no_cfg_target_has_atomic,
Expand All @@ -400,9 +445,37 @@ mod atomic_cas_macros {
)]
#[macro_use]
mod atomic_cas_macros {
#[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API)
#[macro_export]
macro_rules! cfg_has_atomic_cas {
($($tt:tt)*) => {};
}
#[macro_export]
macro_rules! cfg_no_atomic_cas {
($($tt:tt)*) => {
$($tt)*
};
}
}

// Check that all cfg_ macros work.
mod check {
crate::cfg_has_atomic_8! { type _Atomic8 = (); }
crate::cfg_no_atomic_8! { type _Atomic8 = (); }
crate::cfg_has_atomic_16! { type _Atomic16 = (); }
crate::cfg_no_atomic_16! { type _Atomic16 = (); }
crate::cfg_has_atomic_32! { type _Atomic32 = (); }
crate::cfg_no_atomic_32! { type _Atomic32 = (); }
crate::cfg_has_atomic_64! { type _Atomic64 = (); }
crate::cfg_no_atomic_64! { type _Atomic64 = (); }
crate::cfg_has_atomic_128! { type _Atomic128 = (); }
crate::cfg_no_atomic_128! { type _Atomic128 = (); }
crate::cfg_has_atomic_ptr! { type _AtomicPtr = (); }
crate::cfg_no_atomic_ptr! { type _AtomicPtr = (); }
crate::cfg_has_atomic_cas! { type __AtomicPtr = (); }
crate::cfg_no_atomic_cas! { type __AtomicPtr = (); }
#[allow(unused_imports)]
use {
_Atomic128 as _, _Atomic16 as _, _Atomic32 as _, _Atomic64 as _, _Atomic8 as _,
_AtomicPtr as _, __AtomicPtr as _,
};
}
15 changes: 6 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ RUSTFLAGS="--cfg portable_atomic_no_outline_atomics" cargo ...
#![warn(
// Lints that may help when writing public library.
missing_debug_implementations,
missing_docs,
// missing_docs,
clippy::alloc_instead_of_core,
clippy::exhaustive_enums,
clippy::exhaustive_structs,
Expand All @@ -209,6 +209,7 @@ RUSTFLAGS="--cfg portable_atomic_no_outline_atomics" cargo ...
clippy::std_instead_of_alloc,
clippy::std_instead_of_core,
)]
#![cfg_attr(not(portable_atomic_no_asm), warn(missing_docs))] // module-level #![allow(missing_docs)] doesn't work for macros on old rustc
#![allow(
clippy::cast_lossless,
clippy::inline_always,
Expand Down Expand Up @@ -441,18 +442,14 @@ extern crate std;

#[macro_use]
mod cfgs;
#[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API)
#[cfg(target_pointer_width = "128")]
pub use cfg_has_atomic_128 as cfg_has_atomic_ptr;
#[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API)
pub use {cfg_has_atomic_128 as cfg_has_atomic_ptr, cfg_no_atomic_128 as cfg_no_atomic_ptr};
#[cfg(target_pointer_width = "16")]
pub use cfg_has_atomic_16 as cfg_has_atomic_ptr;
#[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API)
pub use {cfg_has_atomic_16 as cfg_has_atomic_ptr, cfg_no_atomic_16 as cfg_no_atomic_ptr};
#[cfg(target_pointer_width = "32")]
pub use cfg_has_atomic_32 as cfg_has_atomic_ptr;
#[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API)
pub use {cfg_has_atomic_32 as cfg_has_atomic_ptr, cfg_no_atomic_32 as cfg_no_atomic_ptr};
#[cfg(target_pointer_width = "64")]
pub use cfg_has_atomic_64 as cfg_has_atomic_ptr;
pub use {cfg_has_atomic_64 as cfg_has_atomic_ptr, cfg_no_atomic_64 as cfg_no_atomic_ptr};

#[macro_use]
mod utils;
Expand Down

0 comments on commit f388319

Please sign in to comment.