use strum::IntoStaticStr;
#[derive(Debug, Clone, PartialEq, Eq, Hash, IntoStaticStr)]
pub(crate) enum Architecture {
#[strum(serialize = "x86")]
X86,
#[strum(serialize = "x86-64")]
X86_64,
#[strum(serialize = "ppc")]
Ppc,
#[strum(serialize = "ppc-le")]
PpcLE,
#[strum(serialize = "ppc64")]
Ppc64,
#[strum(serialize = "ppc64-le")]
Ppc64LE,
#[strum(serialize = "ia64")]
Ia64,
#[strum(serialize = "parisc")]
Parisc,
#[strum(serialize = "parisc64")]
Parisc64,
#[strum(serialize = "s390")]
S390,
#[strum(serialize = "s390x")]
S390x,
#[strum(serialize = "sparc")]
Sparc,
#[strum(serialize = "sparc64")]
Sparc64,
#[strum(serialize = "mips")]
Mips,
#[strum(serialize = "mips64")]
Mips64,
#[strum(serialize = "alpha")]
Alpha,
#[strum(serialize = "arm")]
Arm,
#[strum(serialize = "arm-be")]
ArmBe,
#[strum(serialize = "arm64")]
Arm64,
#[strum(serialize = "arm64-be")]
Arm64Be,
#[strum(serialize = "sh")]
Sh,
#[strum(serialize = "sh64")]
Sh64,
#[strum(serialize = "mk68k")]
M68k,
#[strum(serialize = "tilegx")]
Tilegx,
#[strum(serialize = "cris")]
Cris,
#[strum(serialize = "arc")]
Arc,
#[strum(serialize = "arc-be")]
ArcBe,
#[strum(serialize = "riscv32")]
Riscv32,
#[strum(serialize = "riscv64")]
Riscv64,
}
impl Architecture {
pub(crate) fn from_uname(uname_arch: &str) -> Option<Self> {
match uname_arch {
"i386" => Some(Self::X86),
"i486" => Some(Self::X86),
"i586" => Some(Self::X86),
"i686" => Some(Self::X86),
"x86_64" => Some(Self::X86_64),
"aarch64" => Some(Self::Arm64),
"aarch64_be" => Some(Self::Arm64Be),
"ppc" => Some(Self::Ppc),
"ppcle" => Some(Self::PpcLE),
"ppc64" => Some(Self::Ppc64),
"ppc64le" => Some(Self::Ppc64LE),
"riscv32" => Some(Self::Riscv32),
"riscv64" => Some(Self::Riscv64),
"mips" => Some(Self::Mips),
"mips64" => Some(Self::Mips64),
"sh5" => Some(Self::Sh64),
"s390" => Some(Self::S390),
"s390x" => Some(Self::S390x),
"sparc" => Some(Self::Sparc),
"sparc64" => Some(Self::Sparc64),
"alpha" => Some(Self::Alpha),
"ia64" => Some(Self::Ia64),
"parisc" => Some(Self::Parisc),
"parisc64" => Some(Self::Parisc64),
"m68k" => Some(Self::M68k),
"tilegx" => Some(Self::Tilegx),
"crisv32" => Some(Self::Cris),
"arc" => Some(Self::Arc),
"arceb" => Some(Self::ArcBe),
_ => {
if uname_arch.starts_with("arm") {
if uname_arch.ends_with('b') {
Some(Self::ArmBe)
} else {
Some(Self::Arm)
}
} else if uname_arch.starts_with("sh") {
Some(Self::Sh)
} else {
None
}
}
}
}
}