Skip to content

Commit b9a7aad

Browse files
committed
Tweak build script
1 parent 44084bc commit b9a7aad

File tree

1 file changed

+44
-15
lines changed

1 file changed

+44
-15
lines changed

build.rs

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,67 @@ include!("no_atomic.rs");
1616
const LATEST_STABLE: Version =
1717
Version { minor: 59, nightly: false, commit_date: Date::new(2022, 2, 23) };
1818

19+
// Probe if unstable features can be compiled with the expected API.
20+
// This prevents accidental depends on them if the upstream changes its API.
21+
// This is the same approach used in autocfg, anyhow, etc.
22+
// for aarch64 and x86_64 macos
1923
const PROBE_ATOMIC_128: &str = r#"
2024
#![no_std]
2125
#![feature(integer_atomics)]
2226
fn _probe() {
23-
let v = core::sync::atomic::AtomicU128::new(0);
24-
let _ = v.swap(1, core::sync::atomic::Ordering::Relaxed);
25-
}
26-
"#;
27-
const PROBE_ATOMIC_INTRINSICS: &str = r#"
28-
#![no_std]
29-
#![feature(core_intrinsics)]
30-
unsafe fn _probe(dst: *mut u128) {
31-
let _v = core::intrinsics::atomic_load_acq(dst);
32-
let _v = core::intrinsics::atomic_store_rel(dst, 0);
33-
let _v = core::intrinsics::atomic_cxchg_acq_failrelaxed(dst, 0, 0);
34-
let _v = core::intrinsics::atomic_cxchgweak_failacq(dst, 0, 0);
27+
let v = core::sync::atomic::AtomicU128::new(0_u128);
28+
let _: u128 = v.swap(1_u128, core::sync::atomic::Ordering::Relaxed);
3529
}
3630
"#;
31+
// for x86_64
3732
const PROBE_CMPXCHG16B: &str = r#"
3833
#![no_std]
3934
#![feature(stdsimd, cmpxchg16b_target_feature)]
4035
#[allow(unused_unsafe)]
4136
#[target_feature(enable = "cmpxchg16b")]
42-
unsafe fn _probe(dst: *mut u128) -> u128 {
37+
unsafe fn _probe(dst: *mut u128) {
4338
unsafe {
44-
core::arch::x86_64::cmpxchg16b(
39+
let _: u128 = core::arch::x86_64::cmpxchg16b(
4540
dst,
4641
0_u128,
4742
0_u128,
4843
core::sync::atomic::Ordering::Relaxed,
4944
core::sync::atomic::Ordering::Relaxed,
50-
)
45+
);
46+
}
47+
}
48+
"#;
49+
// for s390x
50+
const PROBE_ATOMIC_INTRINSICS: &str = r#"
51+
#![no_std]
52+
#![feature(core_intrinsics)]
53+
#[allow(unused_unsafe)]
54+
unsafe fn _probe(dst: *mut u128) {
55+
unsafe {
56+
let _: u128 = core::intrinsics::atomic_load_acq(dst);
57+
let _: u128 = core::intrinsics::atomic_load_relaxed(dst);
58+
let _: u128 = core::intrinsics::atomic_load(dst);
59+
let _: () = core::intrinsics::atomic_store_rel(dst, 0_u128);
60+
let _: () = core::intrinsics::atomic_store_relaxed(dst, 0_u128);
61+
let _: () = core::intrinsics::atomic_store(dst, 0_u128);
62+
let _: (u128, bool) = core::intrinsics::atomic_cxchg_acq(dst, 0_u128, 0_u128);
63+
let _: (u128, bool) = core::intrinsics::atomic_cxchg_rel(dst, 0_u128, 0_u128);
64+
let _: (u128, bool) = core::intrinsics::atomic_cxchg_acqrel(dst, 0_u128, 0_u128);
65+
let _: (u128, bool) = core::intrinsics::atomic_cxchg_relaxed(dst, 0_u128, 0_u128);
66+
let _: (u128, bool) = core::intrinsics::atomic_cxchg(dst, 0_u128, 0_u128);
67+
let _: (u128, bool) = core::intrinsics::atomic_cxchg_acq_failrelaxed(dst, 0_u128, 0_u128);
68+
let _: (u128, bool) = core::intrinsics::atomic_cxchg_acqrel_failrelaxed(dst, 0_u128, 0_u128);
69+
let _: (u128, bool) = core::intrinsics::atomic_cxchg_failrelaxed(dst, 0_u128, 0_u128);
70+
let _: (u128, bool) = core::intrinsics::atomic_cxchg_failacq(dst, 0_u128, 0_u128);
71+
let _: (u128, bool) = core::intrinsics::atomic_cxchgweak_acq(dst, 0_u128, 0_u128);
72+
let _: (u128, bool) = core::intrinsics::atomic_cxchgweak_rel(dst, 0_u128, 0_u128);
73+
let _: (u128, bool) = core::intrinsics::atomic_cxchgweak_acqrel(dst, 0_u128, 0_u128);
74+
let _: (u128, bool) = core::intrinsics::atomic_cxchgweak_relaxed(dst, 0_u128, 0_u128);
75+
let _: (u128, bool) = core::intrinsics::atomic_cxchgweak(dst, 0_u128, 0_u128);
76+
let _: (u128, bool) = core::intrinsics::atomic_cxchgweak_acq_failrelaxed(dst, 0_u128, 0_u128);
77+
let _: (u128, bool) = core::intrinsics::atomic_cxchgweak_acqrel_failrelaxed(dst, 0_u128, 0_u128);
78+
let _: (u128, bool) = core::intrinsics::atomic_cxchgweak_failrelaxed(dst, 0_u128, 0_u128);
79+
let _: (u128, bool) = core::intrinsics::atomic_cxchgweak_failacq(dst, 0_u128, 0_u128);
5180
}
5281
}
5382
"#;

0 commit comments

Comments
 (0)