Skip to main content

xtask_kit/
arch.rs

1/// A CPU architecture normalized for release artifact names.
2#[derive(Clone, Copy, Debug, Eq, PartialEq)]
3pub enum Architecture {
4    /// 64-bit ARM, named `arm64` by Apple and many package managers.
5    Arm64,
6    /// 64-bit x86, named `x86_64` by Rust and Apple.
7    X86_64,
8}
9
10impl Architecture {
11    /// Return the architecture for the current compilation target.
12    pub fn current() -> Option<Self> {
13        match std::env::consts::ARCH {
14            "aarch64" => Some(Self::Arm64),
15            "x86_64" => Some(Self::X86_64),
16            _ => None,
17        }
18    }
19
20    /// Rust target architecture name.
21    pub const fn rust(self) -> &'static str {
22        match self {
23            Self::Arm64 => "aarch64",
24            Self::X86_64 => "x86_64",
25        }
26    }
27
28    /// Apple artifact architecture name.
29    pub const fn apple(self) -> &'static str {
30        match self {
31            Self::Arm64 => "arm64",
32            Self::X86_64 => "x86_64",
33        }
34    }
35
36    /// Debian / nfpm architecture name.
37    pub const fn debian(self) -> &'static str {
38        match self {
39            Self::Arm64 => "arm64",
40            Self::X86_64 => "amd64",
41        }
42    }
43}