Skip to content

Commit c5fc3a1

Browse files
joshlfjosephlr
andcommitted
Detect atomic support using target_has_atomic
Note that `cfg(target_has_atomic = ...)` was only added in Rust 1.60. However, we do not add a version detection feature for this since, prior to 1.60, these cfgs are not present, so none of the atomics will be supported. This is identical to the behavior if we were to add version detection, so there is no point in doing so. This is adapted from @josephlr's similar implementation in #1091. Fixes #1086 Co-authored-by: Joe Richey <[email protected]>
1 parent f0a52b5 commit c5fc3a1

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ jobs:
5757
"riscv64gc-unknown-linux-gnu",
5858
"s390x-unknown-linux-gnu",
5959
"x86_64-pc-windows-msvc",
60+
"thumbv6m-none-eabi",
6061
"wasm32-wasi"
6162
]
6263
features: [ "--no-default-features", "", "--features __internal_use_only_features_that_work_on_stable", "--all-features" ]
@@ -109,6 +110,8 @@ jobs:
109110
event_name: "pull_request"
110111
- target: "s390x-unknown-linux-gnu"
111112
event_name: "pull_request"
113+
- target: "thumbv6m-none-eabi"
114+
event_name: "pull_request"
112115
- target: "wasm32-wasi"
113116
event_name: "pull_request"
114117

src/impls.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -451,15 +451,33 @@ macro_rules! impl_traits_for_atomics {
451451
};
452452
}
453453

454-
#[rustfmt::skip]
455-
impl_traits_for_atomics!(
456-
AtomicI16, AtomicI32, AtomicI8, AtomicIsize,
457-
AtomicU16, AtomicU32, AtomicU8, AtomicUsize,
458-
);
459-
460-
impl_for_transparent_wrapper!(=> TryFromBytes for AtomicBool);
461-
impl_for_transparent_wrapper!(=> FromZeros for AtomicBool);
462-
impl_for_transparent_wrapper!(=> IntoBytes for AtomicBool);
454+
#[cfg(target_has_atomic = "8")]
455+
#[cfg_attr(doc_cfg, doc(cfg(target_has_atomic = "8")))]
456+
mod atomic_8 {
457+
use super::*;
458+
459+
impl_traits_for_atomics!(AtomicU8, AtomicI8);
460+
461+
impl_for_transparent_wrapper!(=> TryFromBytes for AtomicBool);
462+
impl_for_transparent_wrapper!(=> FromZeros for AtomicBool);
463+
impl_for_transparent_wrapper!(=> IntoBytes for AtomicBool);
464+
}
465+
466+
#[cfg(target_has_atomic = "16")]
467+
#[cfg_attr(doc_cfg, doc(cfg(target_has_atomic = "16")))]
468+
impl_traits_for_atomics!(AtomicU16, AtomicI16);
469+
470+
#[cfg(target_has_atomic = "32")]
471+
#[cfg_attr(doc_cfg, doc(cfg(target_has_atomic = "32")))]
472+
impl_traits_for_atomics!(AtomicU32, AtomicI32);
473+
474+
#[cfg(target_has_atomic = "64")]
475+
#[cfg_attr(doc_cfg, doc(cfg(target_has_atomic = "64")))]
476+
impl_traits_for_atomics!(AtomicU64, AtomicI64);
477+
478+
#[cfg(target_has_atomic = "ptr")]
479+
#[cfg_attr(doc_cfg, doc(cfg(target_has_atomic = "ptr")))]
480+
impl_traits_for_atomics!(AtomicUsize, AtomicIsize);
463481

464482
safety_comment! {
465483
/// SAFETY:

src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ use core::{
338338
ptr::{self, NonNull},
339339
slice,
340340
sync::atomic::{
341-
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicPtr, AtomicU16, AtomicU32,
342-
AtomicU8, AtomicUsize,
341+
AtomicBool, AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize, AtomicPtr, AtomicU16,
342+
AtomicU32, AtomicU64, AtomicU8, AtomicUsize,
343343
},
344344
};
345345

@@ -820,8 +820,9 @@ impl_known_layout!(
820820
bool, char,
821821
NonZeroU8, NonZeroI8, NonZeroU16, NonZeroI16, NonZeroU32, NonZeroI32,
822822
NonZeroU64, NonZeroI64, NonZeroU128, NonZeroI128, NonZeroUsize, NonZeroIsize,
823-
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32,
824-
AtomicU8, AtomicUsize
823+
AtomicBool,
824+
AtomicU8, AtomicU16, AtomicU32, AtomicU64, AtomicUsize,
825+
AtomicI8, AtomicI16, AtomicI32, AtomicI64, AtomicIsize
825826
);
826827
#[rustfmt::skip]
827828
impl_known_layout!(

0 commit comments

Comments
 (0)