2024-01-09 20:58:28 -05:00
|
|
|
use {
|
2024-01-15 19:02:53 -05:00
|
|
|
crate::error::Error,
|
2024-01-09 20:58:28 -05:00
|
|
|
serde::{Deserialize, Serialize},
|
|
|
|
std::{fmt, str},
|
|
|
|
};
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
2024-01-15 19:02:53 -05:00
|
|
|
/// Represents the processor architecture the software is compiled for
|
2024-01-09 20:58:28 -05:00
|
|
|
pub enum Arch {
|
|
|
|
Any,
|
|
|
|
Arm,
|
|
|
|
Arm64,
|
2024-01-31 22:59:31 -05:00
|
|
|
Loongson,
|
|
|
|
Mips32,
|
|
|
|
Mips64,
|
|
|
|
PowerPC,
|
|
|
|
PowerPC64,
|
2024-01-09 20:58:28 -05:00
|
|
|
RiscV64,
|
2024-01-31 22:59:31 -05:00
|
|
|
S390x,
|
|
|
|
Sparc,
|
|
|
|
Sparc64,
|
2024-01-09 20:58:28 -05:00
|
|
|
X86,
|
|
|
|
X86_64,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for Arch {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
"{}",
|
|
|
|
match self {
|
|
|
|
Self::Any => "any",
|
|
|
|
Self::Arm => "armv7l",
|
|
|
|
Self::Arm64 => "aarch64",
|
2024-01-31 22:59:31 -05:00
|
|
|
Self::Loongson => "loongson",
|
|
|
|
Self::Mips32 => "mips32",
|
|
|
|
Self::Mips64 => "mips64",
|
|
|
|
Self::PowerPC => "ppc",
|
|
|
|
Self::PowerPC64 => "ppc64",
|
2024-01-09 20:58:28 -05:00
|
|
|
Self::RiscV64 => "riscv64",
|
2024-01-31 22:59:31 -05:00
|
|
|
Self::S390x => "s390x",
|
|
|
|
Self::Sparc => "sparc",
|
|
|
|
Self::Sparc64 => "sparc64",
|
2024-01-09 20:58:28 -05:00
|
|
|
Self::X86 => "i486",
|
|
|
|
Self::X86_64 => "x86_64",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl str::FromStr for Arch {
|
|
|
|
type Err = Error;
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
match s {
|
|
|
|
"any" | "Any" | "noarch" => Ok(Self::Any),
|
|
|
|
"armv7l" | "ArmV7L" | "Armv7L" => Ok(Self::Arm),
|
|
|
|
"arm64" | "Arm64" | "aarch64" | "Aarch64" => Ok(Self::Arm64),
|
2024-01-31 22:59:31 -05:00
|
|
|
"Loongson" | "loongson" => Ok(Self::Loongson),
|
|
|
|
"Mips" | "mips" | "Mips32" | "mips32" => Ok(Self::Mips32),
|
|
|
|
"Mips64" | "mips64" => Ok(Self::Mips64),
|
|
|
|
"PowerPC" | "powerpc" | "PPC" | "ppc" => Ok(Self::PowerPC),
|
|
|
|
"PowerPC64" | "powerpc64" | "PPC64" | "ppc64" => Ok(Self::PowerPC64),
|
2024-01-09 20:58:28 -05:00
|
|
|
"RiscV64" | "riscv64" => Ok(Self::RiscV64),
|
2024-01-31 22:59:31 -05:00
|
|
|
"S390x" | "s390x" => Ok(Self::S390x),
|
2024-01-09 20:58:28 -05:00
|
|
|
"x86" | "X86" | "i486" => Ok(Self::X86),
|
|
|
|
"X86_64" | "Amd64" | "x86_64" | "amd64" => Ok(Self::X86_64),
|
|
|
|
_ => Err(Error::ParseArch),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|