From 7d6376d5c4e18f76ee7634d045466d05bac50753 Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Tue, 4 Apr 2023 21:52:29 -0400 Subject: [PATCH] Store target arch as `HOST_ARCH` const, use this as default value for `Package` struct --- src/package/arch.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/package/arch.rs b/src/package/arch.rs index cde2d3c..e453f27 100644 --- a/src/package/arch.rs +++ b/src/package/arch.rs @@ -1,7 +1,18 @@ use serde::{Deserialize, Serialize}; use std::{fmt, str::FromStr, error::Error}; -#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize)] +#[cfg(target_arch = "arm")] +pub const HOST_ARCH: Arch = Arch::armv7l; +#[cfg(target_arch = "aarch64")] +pub const HOST_ARCH: Arch = Arch::aarch64; +#[cfg(target_arch = "x86")] +pub const HOST_ARCH: Arch = Arch::i486; +#[cfg(target_arch = "riscv64")] +pub const HOST_ARCH: Arch = Arch::riscv64; +#[cfg(target_arch = "x86_64")] +pub const HOST_ARCH: Arch = Arch::x86_64; + +#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)] #[allow(non_camel_case_types)] pub enum Arch { armv7l, @@ -10,10 +21,15 @@ pub enum Arch { i586, i686, riscv64, - #[default] x86_64, } +impl Default for Arch { + fn default() -> Self { + HOST_ARCH + } +} + impl fmt::Display for Arch { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", match self {