Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide 64 bit atomics on x86 and x86_64 only #1580

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion serde/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ fn main() {

let target = env::var("TARGET").unwrap();
let emscripten = target == "asmjs-unknown-emscripten" || target == "wasm32-unknown-emscripten";
let x86 = target.starts_with("x86-");
let x86_64 = target.starts_with("x86_64-");

// std::collections::Bound was stabilized in Rust 1.17
// but it was moved to core::ops later in Rust 1.26:
Expand Down Expand Up @@ -69,8 +71,15 @@ fn main() {
println!("cargo:rustc-cfg=num_nonzero");
}

if minor >= 34 {
// Whitelist of archs that support std::sync::atomic module. Ideally we
// would use #[cfg(target_has_atomic = "...")] but it is not stable yet.
let has_atomic = x86 || x86_64 || emscripten;
let has_atomic_64 = x86 || x86_64;
if minor >= 34 && has_atomic {
println!("cargo:rustc-cfg=std_integer_atomics");
if has_atomic_64 {
println!("cargo:rustc-cfg=std_integer_atomics_64");
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion serde/src/de/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2569,7 +2569,7 @@ atomic_impl! {
AtomicU8 AtomicU16 AtomicU32 AtomicUsize
}

#[cfg(all(feature = "std", std_integer_atomics, not(target_os = "emscripten")))]
#[cfg(all(feature = "std", std_integer_atomics_64))]
atomic_impl! {
AtomicI64 AtomicU64
}
2 changes: 1 addition & 1 deletion serde/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ mod lib {
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU8,
AtomicUsize, Ordering,
};
#[cfg(all(feature = "std", std_integer_atomics, not(target_os = "emscripten")))]
#[cfg(all(feature = "std", std_integer_atomics_64))]
pub use std::sync::atomic::{AtomicI64, AtomicU64};

#[cfg(any(core_duration, feature = "std"))]
Expand Down
2 changes: 1 addition & 1 deletion serde/src/ser/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ atomic_impl! {
AtomicU8 AtomicU16 AtomicU32 AtomicUsize
}

#[cfg(all(feature = "std", std_integer_atomics, not(target_os = "emscripten")))]
#[cfg(all(feature = "std", std_integer_atomics_64))]
atomic_impl! {
AtomicI64 AtomicU64
}
4 changes: 2 additions & 2 deletions test_suite/tests/test_de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::sync::atomic::{
use std::sync::{Arc, Weak as ArcWeak};
use std::time::{Duration, UNIX_EPOCH};

#[cfg(not(target_os = "emscripten"))]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
use std::sync::atomic::{AtomicI64, AtomicU64};

use fnv::FnvHasher;
Expand Down Expand Up @@ -1181,7 +1181,7 @@ fn test_atomics() {
test(AtomicU32::load, 131072u32, Token::U32(131072u32));
test(AtomicUsize::load, 131072usize, Token::U32(131072));

#[cfg(not(target_os = "emscripten"))]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
{
test(AtomicI64::load, -8589934592, Token::I64(-8589934592));
test(AtomicU64::load, 8589934592u64, Token::U64(8589934592));
Expand Down
4 changes: 2 additions & 2 deletions test_suite/tests/test_ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::time::{Duration, UNIX_EPOCH};

#[cfg(unix)]
use std::str;
#[cfg(not(target_os = "emscripten"))]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
use std::sync::atomic::{AtomicI64, AtomicU64};

use fnv::FnvHasher;
Expand Down Expand Up @@ -504,7 +504,7 @@ declare_tests! {
}
}

#[cfg(not(target_os = "emscripten"))]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
declare_tests! {
test_atomic64 {
AtomicI64::new(-4295032832i64) => &[Token::I64(-4295032832i64)],
Expand Down