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 36b7a6f
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 20 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 _,
};
}
12 changes: 4 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,18 +441,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 36b7a6f

Please sign in to comment.