From 489f16e46259b59342bc66fdc4e8290996efa80c Mon Sep 17 00:00:00 2001 From: Revertron Date: Mon, 6 Apr 2026 02:40:45 +0200 Subject: [PATCH] Added forgotten file, fixed CI. --- .github/workflows/rust_parallel_release.yml | 9 ++-- src/p2p/version.rs | 59 +++++++++++++++++++++ 2 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 src/p2p/version.rs diff --git a/.github/workflows/rust_parallel_release.yml b/.github/workflows/rust_parallel_release.yml index 3ba4fa3..09fe671 100644 --- a/.github/workflows/rust_parallel_release.yml +++ b/.github/workflows/rust_parallel_release.yml @@ -94,9 +94,10 @@ jobs: name: darwin-arm64 bin_path: ./target/release/alfis archive_cmd: zip - - os: macos-13 + - os: macos-latest name: darwin-amd64 - bin_path: ./target/release/alfis + target: x86_64-apple-darwin + bin_path: ./target/x86_64-apple-darwin/release/alfis archive_cmd: zip defaults: @@ -108,6 +109,8 @@ jobs: - name: Install Rust toolchain uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target || '' }} - name: Install Linux dependencies if: contains(matrix.os, 'ubuntu') @@ -121,7 +124,7 @@ jobs: libayatana-appindicator3-dev - name: Build release binaries - run: cargo build --release + run: cargo build --release ${{ matrix.target && format('--target {0}', matrix.target) || '' }} - name: Package zip env: diff --git a/src/p2p/version.rs b/src/p2p/version.rs new file mode 100644 index 0000000..aa9f06f --- /dev/null +++ b/src/p2p/version.rs @@ -0,0 +1,59 @@ +use std::fmt; + +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Version { + pub major: u16, + pub minor: u16, + pub patch: u16, +} + +impl Version { + pub fn parse(s: &str) -> Version { + let parts: Vec<&str> = s.split('.').collect(); + Version { + major: parts.get(0).and_then(|s| s.parse().ok()).unwrap_or(0), + minor: parts.get(1).and_then(|s| s.parse().ok()).unwrap_or(0), + patch: parts.get(2).and_then(|s| s.parse().ok()).unwrap_or(0), + } + } +} + +impl Default for Version { + fn default() -> Self { + Version { major: 0, minor: 0, patch: 0 } + } +} + +impl PartialOrd for Version { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for Version { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.major.cmp(&other.major) + .then(self.minor.cmp(&other.minor)) + .then(self.patch.cmp(&other.patch)) + } +} + +impl fmt::Display for Version { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}.{}.{}", self.major, self.minor, self.patch) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_version_comparison() { + assert!(Version::parse("0.8.9") >= Version::parse("0.8.9")); + assert!(Version::parse("0.8.10") > Version::parse("0.8.9")); + assert!(Version::parse("0.8.8") < Version::parse("0.8.9")); + assert!(Version::parse("0.9.0") > Version::parse("0.8.99")); + assert!(Version::parse("1.0.0") > Version::parse("0.99.99")); + } +}