Store target arch as HOST_ARCH const, use this as default value for

`Package` struct
This commit is contained in:
Nathan Fisher 2023-04-04 21:52:29 -04:00
parent a58150cc9c
commit 7d6376d5c4

View File

@ -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 {