diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 65bd8a68..f38e40ed 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -144,6 +144,8 @@ jobs: matrix: target: - armv7-unknown-linux-gnueabihf + - mipsel-unknown-linux-gnu + - powerpc-unknown-linux-gnu - powerpc64-unknown-linux-gnu steps: - uses: actions/checkout@v2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a09146d..ef84e363 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Expose `Encoder` methods. See [PR 41]. +### Changed + +- Use `AtomicU32` on platforms that don't support `AtomicU64`. See [PR 42]. + [PR 41]: https://github.com/prometheus/client_rust/pull/41 +[PR 42]: https://github.com/prometheus/client_rust/pull/42 ## [0.15.0] - 2022-01-16 diff --git a/src/metrics/counter.rs b/src/metrics/counter.rs index fac0c309..c8ad9461 100644 --- a/src/metrics/counter.rs +++ b/src/metrics/counter.rs @@ -4,7 +4,9 @@ use super::{MetricType, TypedMetric}; use std::marker::PhantomData; -use std::sync::atomic::{AtomicU32, AtomicU64, Ordering}; +#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +use std::sync::atomic::AtomicU64; +use std::sync::atomic::{AtomicU32, Ordering}; use std::sync::Arc; /// Open Metrics [`Counter`] to measure discrete events. @@ -36,11 +38,18 @@ use std::sync::Arc; /// counter.inc(); /// let _value: f64 = counter.get(); /// ``` +#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] pub struct Counter { value: Arc, phantom: PhantomData, } +#[cfg(any(target_arch = "mips", target_arch = "powerpc"))] +pub struct Counter { + value: Arc, + phantom: PhantomData, +} + impl Clone for Counter { fn clone(&self) -> Self { Self { @@ -96,6 +105,7 @@ pub trait Atomic { fn get(&self) -> N; } +#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] impl Atomic for AtomicU64 { fn inc(&self) -> u64 { self.inc_by(1) @@ -124,6 +134,7 @@ impl Atomic for AtomicU32 { } } +#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] impl Atomic for AtomicU64 { fn inc(&self) -> f64 { self.inc_by(1.0) @@ -165,6 +176,7 @@ mod tests { assert_eq!(1, counter.get()); } + #[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] #[test] fn f64_stored_in_atomic_u64() { fn prop(fs: Vec) { diff --git a/src/metrics/exemplar.rs b/src/metrics/exemplar.rs index 90bb9fde..66a043bb 100644 --- a/src/metrics/exemplar.rs +++ b/src/metrics/exemplar.rs @@ -6,6 +6,9 @@ use super::counter::{self, Counter}; use super::histogram::Histogram; use owning_ref::OwningRef; use std::collections::HashMap; +#[cfg(any(target_arch = "mips", target_arch = "powerpc"))] +use std::sync::atomic::AtomicU32; +#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] use std::sync::atomic::AtomicU64; use std::sync::{Arc, RwLock, RwLockReadGuard}; @@ -26,10 +29,16 @@ pub struct Exemplar { /// counter_with_exemplar.inc_by(1, Some(vec![("user_id".to_string(), "42".to_string())])); /// let _value: (u64, _) = counter_with_exemplar.get(); /// ``` +#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] pub struct CounterWithExemplar { pub(crate) inner: Arc>>, } +#[cfg(any(target_arch = "mips", target_arch = "powerpc"))] +pub struct CounterWithExemplar { + pub(crate) inner: Arc>>, +} + impl Clone for CounterWithExemplar { fn clone(&self) -> Self { CounterWithExemplar { diff --git a/src/metrics/gauge.rs b/src/metrics/gauge.rs index b36fbeb0..504d5bd9 100644 --- a/src/metrics/gauge.rs +++ b/src/metrics/gauge.rs @@ -4,7 +4,9 @@ use super::{MetricType, TypedMetric}; use std::marker::PhantomData; -use std::sync::atomic::{AtomicU32, AtomicU64, Ordering}; +#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +use std::sync::atomic::AtomicU64; +use std::sync::atomic::{AtomicU32, Ordering}; use std::sync::Arc; /// Open Metrics [`Gauge`] to record current measurements. @@ -36,11 +38,18 @@ use std::sync::Arc; /// gauge.set(42.0); /// let _value: f64 = gauge.get(); /// ``` +#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] pub struct Gauge { value: Arc, phantom: PhantomData, } +#[cfg(any(target_arch = "mips", target_arch = "powerpc"))] +pub struct Gauge { + value: Arc, + phantom: PhantomData, +} + impl Clone for Gauge { fn clone(&self) -> Self { Self { @@ -113,6 +122,7 @@ pub trait Atomic { fn get(&self) -> N; } +#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] impl Atomic for AtomicU64 { fn inc(&self) -> u64 { self.inc_by(1) @@ -165,6 +175,7 @@ impl Atomic for AtomicU32 { } } +#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] impl Atomic for AtomicU64 { fn inc(&self) -> f64 { self.inc_by(1.0)