From 2e2e57043c831d3c2f88c027d92b5ea5f7f29a38 Mon Sep 17 00:00:00 2001 From: adrian-kong Date: Tue, 12 Jul 2022 14:40:53 +1000 Subject: [PATCH 1/7] add total_cmp --- swiftnav/src/time.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/swiftnav/src/time.rs b/swiftnav/src/time.rs index 30ecbc0..71ee848 100644 --- a/swiftnav/src/time.rs +++ b/swiftnav/src/time.rs @@ -44,6 +44,7 @@ //! [`UtcParams`] object to handle the leap second conversion and one which doesn't //! take a [`UtcParams`] object but has `_hardcoded` appended to the function name. +use std::cmp::Ordering; use std::error::Error; use std::fmt; use std::ops::{Add, AddAssign, Sub, SubAssign}; @@ -299,6 +300,16 @@ impl GpsTime { assert!(self >= GLO_TIME_START); GloTime(unsafe { swiftnav_sys::gps2glo(self.c_ptr(), std::ptr::null()) }) } + + pub fn total_cmp(&self, other: &GpsTime) -> Ordering { + if self == other { + Ordering::Equal + } else if self > other { + Ordering::Greater + } else { + Ordering::Less + } + } } impl fmt::Debug for GpsTime { From 130bc1b11d694695e0b36bc2931376ff2c76f037 Mon Sep 17 00:00:00 2001 From: adrian-kong Date: Tue, 12 Jul 2022 14:49:07 +1000 Subject: [PATCH 2/7] total cmp --- swiftnav/src/time.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/swiftnav/src/time.rs b/swiftnav/src/time.rs index 71ee848..f9c866f 100644 --- a/swiftnav/src/time.rs +++ b/swiftnav/src/time.rs @@ -302,13 +302,7 @@ impl GpsTime { } pub fn total_cmp(&self, other: &GpsTime) -> Ordering { - if self == other { - Ordering::Equal - } else if self > other { - Ordering::Greater - } else { - Ordering::Less - } + self.tow().total_cmp(&other.tow()) } } From c4fcf12a3858ee92eb0fbf2bfc06d636927d9748 Mon Sep 17 00:00:00 2001 From: adrian-kong Date: Thu, 14 Jul 2022 11:50:54 +1000 Subject: [PATCH 3/7] using mirrored f64 total cmp --- swiftnav/src/time.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/swiftnav/src/time.rs b/swiftnav/src/time.rs index f9c866f..3f65549 100644 --- a/swiftnav/src/time.rs +++ b/swiftnav/src/time.rs @@ -301,8 +301,20 @@ impl GpsTime { GloTime(unsafe { swiftnav_sys::gps2glo(self.c_ptr(), std::ptr::null()) }) } + /// Compare between itself and other GpsTime + /// Checks whether week number is same which then mirrors [`f64::total_cmp()`] pub fn total_cmp(&self, other: &GpsTime) -> Ordering { - self.tow().total_cmp(&other.tow()) + if self.wn() != other.wn() { + self.wn().cmp(&other.wn()) + } else { + let mut left = self.tow().to_bits() as i64; + let mut right = other.tow().to_bits() as i64; + + left ^= (((left >> 63) as u64) >> 1) as i64; + right ^= (((right >> 63) as u64) >> 1) as i64; + + left.cmp(&right) + } } } From d91aad6b574db55767f4b782326c4763bcce3507 Mon Sep 17 00:00:00 2001 From: adrian-kong Date: Fri, 15 Jul 2022 09:02:09 +1000 Subject: [PATCH 4/7] added permalink --- swiftnav/src/time.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/swiftnav/src/time.rs b/swiftnav/src/time.rs index 3f65549..32a908d 100644 --- a/swiftnav/src/time.rs +++ b/swiftnav/src/time.rs @@ -303,10 +303,13 @@ impl GpsTime { /// Compare between itself and other GpsTime /// Checks whether week number is same which then mirrors [`f64::total_cmp()`] + /// + /// See: [`https://github.com/rust-lang/rust/blob/481db40311cdd241ae4d33f34f2f75732e44d8e8/library/core/src/num/f64.rs#L1228`] pub fn total_cmp(&self, other: &GpsTime) -> Ordering { if self.wn() != other.wn() { self.wn().cmp(&other.wn()) } else { + //TODO: replace with f64::total_cmp let mut left = self.tow().to_bits() as i64; let mut right = other.tow().to_bits() as i64; From 4e9e7c6f8d5372f7dcd2d0229064678c47e40777 Mon Sep 17 00:00:00 2001 From: adrian-kong Date: Fri, 15 Jul 2022 09:04:49 +1000 Subject: [PATCH 5/7] comment --- swiftnav/src/time.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/swiftnav/src/time.rs b/swiftnav/src/time.rs index 32a908d..780f044 100644 --- a/swiftnav/src/time.rs +++ b/swiftnav/src/time.rs @@ -302,9 +302,7 @@ impl GpsTime { } /// Compare between itself and other GpsTime - /// Checks whether week number is same which then mirrors [`f64::total_cmp()`] - /// - /// See: [`https://github.com/rust-lang/rust/blob/481db40311cdd241ae4d33f34f2f75732e44d8e8/library/core/src/num/f64.rs#L1228`] + /// Checks whether week number is same which then mirrors [`https://github.com/rust-lang/rust/blob/481db40311cdd241ae4d33f34f2f75732e44d8e8/library/core/src/num/f64.rs#L1228`](f64::total_cmp()) pub fn total_cmp(&self, other: &GpsTime) -> Ordering { if self.wn() != other.wn() { self.wn().cmp(&other.wn()) From e418551147c551cb9f5bb66ff1aa05a00fa10f61 Mon Sep 17 00:00:00 2001 From: Jason Mobarak Date: Wed, 19 Oct 2022 15:04:53 -0700 Subject: [PATCH 6/7] Update to use total_cmp from 1.62 --- .github/workflows/ci.yaml | 35 +++++++++++++++++++++++------ ci-makefile.toml => Makefile.toml | 1 + swiftnav/Cargo.toml | 1 + swiftnav/src/time.rs | 37 ++++++++++++++++++++++--------- 4 files changed, 56 insertions(+), 18 deletions(-) rename ci-makefile.toml => Makefile.toml (93%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index db0244b..ebce6c5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,5 +1,6 @@ +--- name: CI -on: +"on": pull_request: push: branches: @@ -11,15 +12,34 @@ jobs: strategy: matrix: include: - - os: ubuntu-18.04 + # Ubuntus + - os: ubuntu-latest binary_target: x86_64-unknown-linux-musl needs_musl: true - - os: ubuntu-18.04 + toolchain: stable + - os: ubuntu-20.04 binary_target: x86_64-unknown-linux-gnu - - os: macos-10.15 + toolchain: stable + + # MacOS + - os: macos-11 binary_target: x86_64-apple-darwin + toolchain: stable + + # Windows - os: windows-latest binary_target: x86_64-pc-windows-msvc + toolchain: stable + + # Nightly Rust + - os: ubuntu-latest + binary_target: x86_64-unknown-linux-gnu + toolchain: nightly + + # MSRV + - os: ubuntu-latest + binary_target: x86_64-unknown-linux-gnu + toolchain: 1.57.0 steps: - uses: actions/checkout@v2 with: @@ -32,7 +52,8 @@ jobs: sudo apt-get install musl-tools sudo ln -s /usr/bin/musl-gcc /usr/bin/musl-g++ - - name: Install LLVM and Clang # required for bindgen on Windows + # Required for bindgen on Windows + - name: Install LLVM and Clang uses: KyleMayes/install-llvm-action@v1 if: matrix.os == 'windows-latest' with: @@ -49,10 +70,10 @@ jobs: - name: Install rust ${{ matrix.binary_target }} uses: actions-rs/toolchain@v1 with: - toolchain: stable-${{ matrix.binary_target }} + toolchain: ${{ matrix.toolchain }}-${{ matrix.binary_target }} profile: minimal - uses: actions-rs/cargo@v1 with: command: make - args: --makefile ci-makefile.toml --no-workspace workspace-ci-flow + args: --no-workspace workspace-ci-flow diff --git a/ci-makefile.toml b/Makefile.toml similarity index 93% rename from ci-makefile.toml rename to Makefile.toml index b697690..30155f2 100644 --- a/ci-makefile.toml +++ b/Makefile.toml @@ -4,6 +4,7 @@ CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true CARGO_MAKE_RUN_CLIPPY = true CARGO_MAKE_CLIPPY_ARGS = "--all-features -- -D warnings" CARGO_MAKE_RUN_CHECK_FORMAT = true +CARGO_MAKE_CARGO_VERBOSE_FLAGS = "-vv" RUSTFLAGS="-D warnings" [tasks.check-format-ci-flow] diff --git a/swiftnav/Cargo.toml b/swiftnav/Cargo.toml index d34f15a..75ac3ee 100644 --- a/swiftnav/Cargo.toml +++ b/swiftnav/Cargo.toml @@ -9,5 +9,6 @@ repository = "https://github.com/swift-nav/swiftnav-rs" license = "LGPL-3.0" [dependencies] +rustversion = "1.0" chrono = { version = "0.4", optional = true } swiftnav-sys = { version = "^0.8.0", path = "../swiftnav-sys/" } diff --git a/swiftnav/src/time.rs b/swiftnav/src/time.rs index 780f044..4dcf0c0 100644 --- a/swiftnav/src/time.rs +++ b/swiftnav/src/time.rs @@ -44,7 +44,6 @@ //! [`UtcParams`] object to handle the leap second conversion and one which doesn't //! take a [`UtcParams`] object but has `_hardcoded` appended to the function name. -use std::cmp::Ordering; use std::error::Error; use std::fmt; use std::ops::{Add, AddAssign, Sub, SubAssign}; @@ -301,20 +300,16 @@ impl GpsTime { GloTime(unsafe { swiftnav_sys::gps2glo(self.c_ptr(), std::ptr::null()) }) } + #[rustversion::since(1.62)] /// Compare between itself and other GpsTime - /// Checks whether week number is same which then mirrors [`https://github.com/rust-lang/rust/blob/481db40311cdd241ae4d33f34f2f75732e44d8e8/library/core/src/num/f64.rs#L1228`](f64::total_cmp()) - pub fn total_cmp(&self, other: &GpsTime) -> Ordering { + /// Checks whether week number is same which then mirrors + /// [f64::total_cmp()](https://doc.rust-lang.org/std/primitive.f64.html#method.total_cmp) + pub fn total_cmp(&self, other: &GpsTime) -> std::cmp::Ordering { if self.wn() != other.wn() { self.wn().cmp(&other.wn()) } else { - //TODO: replace with f64::total_cmp - let mut left = self.tow().to_bits() as i64; - let mut right = other.tow().to_bits() as i64; - - left ^= (((left >> 63) as u64) >> 1) as i64; - right ^= (((right >> 63) as u64) >> 1) as i64; - - left.cmp(&right) + let other = other.tow(); + self.tow().total_cmp(&other) } } } @@ -922,6 +917,26 @@ mod tests { assert!(t3 >= t3); } + #[rustversion::since(1.62)] + #[test] + fn total_order() { + use std::cmp::Ordering; + + let t1 = GpsTime::new(10, 234.566).unwrap(); + let t2 = GpsTime::new(10, 234.567).unwrap(); + let t3 = GpsTime::new(10, 234.568).unwrap(); + + assert!(t1.total_cmp(&t2) == Ordering::Less); + assert!(t2.total_cmp(&t3) == Ordering::Less); + assert!(t1.total_cmp(&t3) == Ordering::Less); + + assert!(t2.total_cmp(&t1) == Ordering::Greater); + assert!(t3.total_cmp(&t2) == Ordering::Greater); + assert!(t3.total_cmp(&t1) == Ordering::Greater); + + assert!(t1.total_cmp(&t1) == Ordering::Equal); + } + #[test] fn add_duration() { let mut t = GpsTime::new(0, 0.0).unwrap(); From d6ae0d7abb5499b701376ac43d7f46c5b6d758f1 Mon Sep 17 00:00:00 2001 From: Jason Mobarak Date: Wed, 19 Oct 2022 17:19:56 -0700 Subject: [PATCH 7/7] msrv --- .github/workflows/ci.yaml | 2 +- swiftnav-sys/Cargo.toml | 1 + swiftnav/Cargo.toml | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ebce6c5..59a8fd4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -39,7 +39,7 @@ jobs: # MSRV - os: ubuntu-latest binary_target: x86_64-unknown-linux-gnu - toolchain: 1.57.0 + toolchain: 1.56.1 steps: - uses: actions/checkout@v2 with: diff --git a/swiftnav-sys/Cargo.toml b/swiftnav-sys/Cargo.toml index 59d2ab2..3d1f0ea 100644 --- a/swiftnav-sys/Cargo.toml +++ b/swiftnav-sys/Cargo.toml @@ -7,6 +7,7 @@ description = "FFI bindings for libswiftnav" readme = "../README.md" repository = "https://github.com/swift-nav/swiftnav-rs" license = "LGPL-3.0" +rust-version = "1.56.1" [build-dependencies] bindgen = "0.59" diff --git a/swiftnav/Cargo.toml b/swiftnav/Cargo.toml index 75ac3ee..89ef698 100644 --- a/swiftnav/Cargo.toml +++ b/swiftnav/Cargo.toml @@ -7,6 +7,7 @@ description = "GNSS positioning and related utilities" readme = "../README.md" repository = "https://github.com/swift-nav/swiftnav-rs" license = "LGPL-3.0" +rust-version = "1.56.1" [dependencies] rustversion = "1.0"