pub type Os = oci_spec::image::Os;
pub type Arch = oci_spec::image::Arch;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Platform {
pub os: Os,
pub arch: Arch,
pub variant: Option<String>,
}
impl Platform {
pub fn new(os: impl Into<Os>, arch: impl Into<Arch>) -> Self {
Self {
os: os.into(),
arch: arch.into(),
variant: None,
}
}
pub fn with_variant(
os: impl Into<Os>,
arch: impl Into<Arch>,
variant: impl Into<String>,
) -> Self {
Self {
os: os.into(),
arch: arch.into(),
variant: Some(variant.into()),
}
}
pub fn host_linux() -> Self {
let arch = match std::env::consts::ARCH {
"x86_64" => "amd64",
"aarch64" => "arm64",
other => other,
};
Self::new("linux", arch)
}
}
impl Default for Platform {
fn default() -> Self {
Self::host_linux()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_host_linux() {
let p = Platform::host_linux();
assert_eq!(p.os, Os::Linux);
assert!(p.arch == Arch::Amd64 || p.arch == Arch::ARM64);
}
#[test]
fn test_default_is_host_linux() {
let p = Platform::default();
assert_eq!(p.os, Os::Linux);
}
}