Invert use_target_has_atomic cfg

This way, a build system that does not want to run Cargo build scripts
can build serde without any cfgs defined, and get the most modern
feature set.
This commit is contained in:
David Tolnay 2022-12-11 15:51:17 -08:00
parent 692ac99c69
commit 6159ead404
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
4 changed files with 20 additions and 21 deletions

View File

@ -95,9 +95,8 @@ fn main() {
// Whitelist of archs that support std::sync::atomic module. Ideally we // Whitelist of archs that support std::sync::atomic module. Ideally we
// would use #[cfg(target_has_atomic = "...")] but it is not stable yet. // would use #[cfg(target_has_atomic = "...")] but it is not stable yet.
// Instead this is based on rustc's compiler/rustc_target/src/spec/*.rs. // Instead this is based on rustc's compiler/rustc_target/src/spec/*.rs.
if minor >= 60 { if minor < 60 {
println!("cargo:rustc-cfg=use_target_has_atomic"); println!("cargo:rustc-cfg=no_target_has_atomic");
} else {
let has_atomic64 = target.starts_with("x86_64") let has_atomic64 = target.starts_with("x86_64")
|| target.starts_with("i686") || target.starts_with("i686")
|| target.starts_with("aarch64") || target.starts_with("aarch64")

View File

@ -2660,7 +2660,7 @@ where
} }
} }
#[cfg(all(feature = "std", not(use_target_has_atomic), not(no_std_atomic)))] #[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]
macro_rules! atomic_impl { macro_rules! atomic_impl {
($($ty:ident)*) => { ($($ty:ident)*) => {
$( $(
@ -2676,7 +2676,7 @@ macro_rules! atomic_impl {
}; };
} }
#[cfg(all(feature = "std", use_target_has_atomic))] #[cfg(all(feature = "std", not(no_target_has_atomic)))]
macro_rules! atomic_impl { macro_rules! atomic_impl {
($($ty:ident $size:expr),*) => { ($($ty:ident $size:expr),*) => {
$( $(
@ -2693,19 +2693,19 @@ macro_rules! atomic_impl {
}; };
} }
#[cfg(all(feature = "std", not(use_target_has_atomic), not(no_std_atomic)))] #[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]
atomic_impl! { atomic_impl! {
AtomicBool AtomicBool
AtomicI8 AtomicI16 AtomicI32 AtomicIsize AtomicI8 AtomicI16 AtomicI32 AtomicIsize
AtomicU8 AtomicU16 AtomicU32 AtomicUsize AtomicU8 AtomicU16 AtomicU32 AtomicUsize
} }
#[cfg(all(feature = "std", not(use_target_has_atomic), not(no_std_atomic64)))] #[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic64)))]
atomic_impl! { atomic_impl! {
AtomicI64 AtomicU64 AtomicI64 AtomicU64
} }
#[cfg(all(feature = "std", use_target_has_atomic))] #[cfg(all(feature = "std", not(no_target_has_atomic)))]
atomic_impl! { atomic_impl! {
AtomicBool "8", AtomicBool "8",
AtomicI8 "8", AtomicI8 "8",

View File

@ -236,25 +236,25 @@ mod lib {
#[cfg(not(no_range_inclusive))] #[cfg(not(no_range_inclusive))]
pub use self::core::ops::RangeInclusive; pub use self::core::ops::RangeInclusive;
#[cfg(all(feature = "std", not(use_target_has_atomic), not(no_std_atomic)))] #[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]
pub use std::sync::atomic::{ pub use std::sync::atomic::{
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU8, AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU8,
AtomicUsize, Ordering, AtomicUsize, Ordering,
}; };
#[cfg(all(feature = "std", not(use_target_has_atomic), not(no_std_atomic64)))] #[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic64)))]
pub use std::sync::atomic::{AtomicI64, AtomicU64}; pub use std::sync::atomic::{AtomicI64, AtomicU64};
#[cfg(all(feature = "std", use_target_has_atomic))] #[cfg(all(feature = "std", not(no_target_has_atomic)))]
pub use std::sync::atomic::Ordering; pub use std::sync::atomic::Ordering;
#[cfg(all(feature = "std", use_target_has_atomic, target_has_atomic = "8"))] #[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "8"))]
pub use std::sync::atomic::{AtomicBool, AtomicI8, AtomicU8}; pub use std::sync::atomic::{AtomicBool, AtomicI8, AtomicU8};
#[cfg(all(feature = "std", use_target_has_atomic, target_has_atomic = "16"))] #[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "16"))]
pub use std::sync::atomic::{AtomicI16, AtomicU16}; pub use std::sync::atomic::{AtomicI16, AtomicU16};
#[cfg(all(feature = "std", use_target_has_atomic, target_has_atomic = "32"))] #[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "32"))]
pub use std::sync::atomic::{AtomicI32, AtomicU32}; pub use std::sync::atomic::{AtomicI32, AtomicU32};
#[cfg(all(feature = "std", use_target_has_atomic, target_has_atomic = "64"))] #[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "64"))]
pub use std::sync::atomic::{AtomicI64, AtomicU64}; pub use std::sync::atomic::{AtomicI64, AtomicU64};
#[cfg(all(feature = "std", use_target_has_atomic, target_has_atomic = "ptr"))] #[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "ptr"))]
pub use std::sync::atomic::{AtomicIsize, AtomicUsize}; pub use std::sync::atomic::{AtomicIsize, AtomicUsize};
#[cfg(any(feature = "std", not(no_core_duration)))] #[cfg(any(feature = "std", not(no_core_duration)))]

View File

@ -945,7 +945,7 @@ where
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#[cfg(all(feature = "std", not(use_target_has_atomic), not(no_std_atomic)))] #[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]
macro_rules! atomic_impl { macro_rules! atomic_impl {
($($ty:ident)*) => { ($($ty:ident)*) => {
$( $(
@ -962,7 +962,7 @@ macro_rules! atomic_impl {
} }
} }
#[cfg(all(feature = "std", use_target_has_atomic))] #[cfg(all(feature = "std", not(no_target_has_atomic)))]
macro_rules! atomic_impl { macro_rules! atomic_impl {
($($ty:ident $size:expr),*) => { ($($ty:ident $size:expr),*) => {
$( $(
@ -980,19 +980,19 @@ macro_rules! atomic_impl {
} }
} }
#[cfg(all(feature = "std", not(use_target_has_atomic), not(no_std_atomic)))] #[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]
atomic_impl! { atomic_impl! {
AtomicBool AtomicBool
AtomicI8 AtomicI16 AtomicI32 AtomicIsize AtomicI8 AtomicI16 AtomicI32 AtomicIsize
AtomicU8 AtomicU16 AtomicU32 AtomicUsize AtomicU8 AtomicU16 AtomicU32 AtomicUsize
} }
#[cfg(all(feature = "std", not(use_target_has_atomic), not(no_std_atomic64)))] #[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic64)))]
atomic_impl! { atomic_impl! {
AtomicI64 AtomicU64 AtomicI64 AtomicU64
} }
#[cfg(all(feature = "std", use_target_has_atomic))] #[cfg(all(feature = "std", not(no_target_has_atomic)))]
atomic_impl! { atomic_impl! {
AtomicBool "8", AtomicBool "8",
AtomicI8 "8", AtomicI8 "8",