Provide 32 bit atomic impls for emscripten
This commit is contained in:
parent
3158bf9093
commit
7b0e06c825
@ -14,8 +14,6 @@ fn main() {
|
||||
let target = env::var("TARGET").unwrap();
|
||||
let emscripten = target == "asmjs-unknown-emscripten" || target == "wasm32-unknown-emscripten";
|
||||
|
||||
let has_atomic_integers = target_has_at_least_atomic_u64(&target);
|
||||
|
||||
// std::collections::Bound was stabilized in Rust 1.17
|
||||
// but it was moved to core::ops later in Rust 1.26:
|
||||
// https://doc.rust-lang.org/core/ops/enum.Bound.html
|
||||
@ -71,8 +69,23 @@ fn main() {
|
||||
println!("cargo:rustc-cfg=num_nonzero");
|
||||
}
|
||||
|
||||
if minor >= 34 && has_atomic_integers {
|
||||
println!("cargo:rustc-cfg=std_integer_atomics");
|
||||
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.
|
||||
// Instead this is based on rustc's src/librustc_target/spec/*.rs.
|
||||
let has_atomic64 = target.starts_with("x86_64")
|
||||
|| target.starts_with("i686")
|
||||
|| target.starts_with("aarch64")
|
||||
|| target.starts_with("powerpc64")
|
||||
|| target.starts_with("sparc64")
|
||||
|| target.starts_with("mips64el");
|
||||
let has_atomic32 = has_atomic64 || emscripten;
|
||||
if has_atomic64 {
|
||||
println!("cargo:rustc-cfg=std_atomic64");
|
||||
}
|
||||
if has_atomic32 {
|
||||
println!("cargo:rustc-cfg=std_atomic");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,17 +117,3 @@ fn rustc_minor_version() -> Option<u32> {
|
||||
|
||||
u32::from_str(next).ok()
|
||||
}
|
||||
|
||||
fn target_has_at_least_atomic_u64(target: &str) -> bool {
|
||||
// The cfg variable target_has_atomic is unstable
|
||||
// so this data comes from the src/librustc_target/spec/*.rs
|
||||
// files in the rust source. Generally, it's 64-bit platforms
|
||||
// plus i686.
|
||||
if target.starts_with("x86_64") || target.starts_with("i686") ||
|
||||
target.starts_with("aarch64") || target.starts_with("powerpc64") ||
|
||||
target.starts_with("sparc64") || target.starts_with("mips64el") {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
@ -2546,7 +2546,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "std", std_integer_atomics))]
|
||||
#[cfg(all(feature = "std", std_atomic))]
|
||||
macro_rules! atomic_impl {
|
||||
($($ty:ident)*) => {
|
||||
$(
|
||||
@ -2562,14 +2562,14 @@ macro_rules! atomic_impl {
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "std", std_integer_atomics))]
|
||||
#[cfg(all(feature = "std", std_atomic))]
|
||||
atomic_impl! {
|
||||
AtomicBool
|
||||
AtomicI8 AtomicI16 AtomicI32 AtomicIsize
|
||||
AtomicU8 AtomicU16 AtomicU32 AtomicUsize
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "std", std_integer_atomics, not(target_os = "emscripten")))]
|
||||
#[cfg(all(feature = "std", std_atomic64))]
|
||||
atomic_impl! {
|
||||
AtomicI64 AtomicU64
|
||||
}
|
||||
|
@ -212,12 +212,12 @@ mod lib {
|
||||
#[cfg(range_inclusive)]
|
||||
pub use self::core::ops::RangeInclusive;
|
||||
|
||||
#[cfg(all(feature = "std", std_integer_atomics))]
|
||||
#[cfg(all(feature = "std", std_atomic))]
|
||||
pub use std::sync::atomic::{
|
||||
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_atomic64))]
|
||||
pub use std::sync::atomic::{AtomicI64, AtomicU64};
|
||||
|
||||
#[cfg(any(core_duration, feature = "std"))]
|
||||
|
@ -842,7 +842,7 @@ where
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(all(feature = "std", std_integer_atomics))]
|
||||
#[cfg(all(feature = "std", std_atomic))]
|
||||
macro_rules! atomic_impl {
|
||||
($($ty:ident)*) => {
|
||||
$(
|
||||
@ -858,14 +858,14 @@ macro_rules! atomic_impl {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "std", std_integer_atomics))]
|
||||
#[cfg(all(feature = "std", std_atomic))]
|
||||
atomic_impl! {
|
||||
AtomicBool
|
||||
AtomicI8 AtomicI16 AtomicI32 AtomicIsize
|
||||
AtomicU8 AtomicU16 AtomicU32 AtomicUsize
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "std", std_integer_atomics, not(target_os = "emscripten")))]
|
||||
#[cfg(all(feature = "std", std_atomic64))]
|
||||
atomic_impl! {
|
||||
AtomicI64 AtomicU64
|
||||
}
|
||||
|
@ -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(target_arch = "x86_64")]
|
||||
use std::sync::atomic::{AtomicI64, AtomicU64};
|
||||
|
||||
use fnv::FnvHasher;
|
||||
@ -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(target_arch = "x86_64")]
|
||||
{
|
||||
test(AtomicI64::load, -8589934592, Token::I64(-8589934592));
|
||||
test(AtomicU64::load, 8589934592u64, Token::U64(8589934592));
|
||||
|
@ -19,7 +19,7 @@ use std::time::{Duration, UNIX_EPOCH};
|
||||
|
||||
#[cfg(unix)]
|
||||
use std::str;
|
||||
#[cfg(not(target_os = "emscripten"))]
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
use std::sync::atomic::{AtomicI64, AtomicU64};
|
||||
|
||||
use fnv::FnvHasher;
|
||||
@ -504,7 +504,7 @@ declare_tests! {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "emscripten"))]
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
declare_tests! {
|
||||
test_atomic64 {
|
||||
AtomicI64::new(-4295032832i64) => &[Token::I64(-4295032832i64)],
|
||||
|
Loading…
x
Reference in New Issue
Block a user