Skip to content

Commit 4220ed0

Browse files
committed
Fix building on 32bit platforms
Signed-off-by: Nico Burns <[email protected]>
1 parent ac5a7ce commit 4220ed0

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ jobs:
9898
uses: dtolnay/rust-toolchain@master
9999
with:
100100
toolchain: ${{ env.RUST_STABLE_VER }}
101-
targets: x86_64-unknown-none
101+
targets: x86_64-unknown-none,thumbv8m.main-none-eabihf
102102
components: clippy
103103

104104
- name: install cargo-hack
@@ -114,6 +114,9 @@ jobs:
114114
- name: cargo clippy (no_std)
115115
run: cargo hack clippy --workspace --locked --optional-deps --each-feature --ignore-unknown-features --features libm --exclude-features ${{ env.FEATURES_DEPENDING_ON_STD }} --target x86_64-unknown-none -- -D warnings
116116

117+
- name: cargo clippy (no_std 32bit)
118+
run: cargo hack clippy --workspace --locked --optional-deps --each-feature --ignore-unknown-features --features libm --exclude-features ${{ env.FEATURES_DEPENDING_ON_STD }} --target thumbv8m.main-none-eabihf -- -D warnings
119+
117120
- name: cargo clippy
118121
run: cargo hack clippy --workspace --locked --optional-deps --each-feature --ignore-unknown-features --features std -- -D warnings
119122

@@ -213,7 +216,7 @@ jobs:
213216
uses: dtolnay/rust-toolchain@master
214217
with:
215218
toolchain: ${{ env.RUST_MIN_VER }}
216-
targets: x86_64-unknown-none
219+
targets: x86_64-unknown-none,thumbv8m.main-none-eabihf
217220

218221
- name: install cargo-hack
219222
uses: taiki-e/install-action@v2
@@ -228,6 +231,9 @@ jobs:
228231
- name: cargo check (no_std)
229232
run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} --locked --optional-deps --each-feature --ignore-unknown-features --features libm --exclude-features ${{ env.FEATURES_DEPENDING_ON_STD }} --target x86_64-unknown-none
230233

234+
- name: cargo check (no_std 32bit)
235+
run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} --locked --optional-deps --each-feature --ignore-unknown-features --features libm --exclude-features ${{ env.FEATURES_DEPENDING_ON_STD }} --target thumbv8m.main-none-eabihf
236+
231237
- name: cargo check
232238
run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} --locked --optional-deps --each-feature --ignore-unknown-features --features std
233239

src/blob.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33

44
use core::fmt;
5-
use core::sync::atomic::{AtomicU64, Ordering};
5+
use core::sync::atomic::Ordering;
66
extern crate alloc;
77
use alloc::boxed::Box;
88
use alloc::sync::{Arc, Weak};
99
use alloc::vec::Vec;
1010

11+
#[cfg(not(target_has_atomic = "64"))]
12+
use core::sync::atomic::AtomicU32 as AtomicCounter;
13+
#[cfg(target_has_atomic = "64")]
14+
use core::sync::atomic::AtomicU64 as AtomicCounter;
15+
1116
/// Shared data with an associated unique identifier.
1217
pub struct Blob<T> {
1318
data: Arc<dyn AsRef<[T]> + Send + Sync>,
@@ -82,15 +87,18 @@ where
8287
}
8388
}
8489

85-
static ID_COUNTER: AtomicU64 = AtomicU64::new(0);
90+
static ID_COUNTER: AtomicCounter = AtomicCounter::new(0);
8691

8792
impl<T> Blob<T> {
8893
/// Creates a new blob from the given data and generates a unique
8994
/// identifier.
9095
pub fn new(data: Arc<dyn AsRef<[T]> + Send + Sync>) -> Self {
9196
Self {
9297
data,
93-
id: ID_COUNTER.fetch_add(1, Ordering::Relaxed),
98+
#[allow(clippy::useless_conversion)] // Conversion is not useless on 32-bit platforms and is harmless on 64-bit platforms
99+
// Overflow: We expect running this code on 32-bit targets to be rare enough in practise that we don't handle overflow.
100+
// Impossible on 64-bit as counter is only ever incremented by 1.
101+
id: ID_COUNTER.fetch_add(1, Ordering::Relaxed).into(),
94102
}
95103
}
96104

0 commit comments

Comments
 (0)