buildkit_rs_llb/
platform.rs1use std::{borrow::Cow, fmt};
2
3#[derive(Debug, Clone, PartialEq, Eq, Hash)]
4pub struct Platform<'a> {
5 pub architecture: Cow<'a, str>,
7 pub os: Cow<'a, str>,
9 pub variant: Option<Cow<'a, str>>,
11}
12
13impl<'a> Platform<'a> {
14 pub const fn new(os: &'a str, arch: &'a str, variant: Option<&'a str>) -> Self {
15 Self {
16 architecture: Cow::Borrowed(arch),
17 os: Cow::Borrowed(os),
18 variant: match variant {
21 Some(variant) => Some(Cow::Borrowed(variant)),
22 None => None,
23 },
24 }
25 }
26}
27
28impl Platform<'_> {
29 pub fn into_static(self) -> Platform<'static> {
30 Platform {
31 architecture: Cow::Owned(self.architecture.into_owned()),
32 os: Cow::Owned(self.os.into_owned()),
33 variant: match self.variant {
34 Some(variant) => Some(Cow::Owned(variant.into_owned())),
35 None => None,
36 },
37 }
38 }
39}
40
41impl fmt::Display for Platform<'_> {
42 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43 write!(f, "{}-{}", self.os, self.architecture)?;
44 if let Some(variant) = &self.variant {
45 write!(f, "-{}", variant)?;
46 }
47 Ok(())
48 }
49}
50
51pub const LINUX_AMD64: Platform = Platform::new("linux", "amd64", None);
52pub const LINUX_ARMHF: Platform = Platform::new("linux", "arm", Some("v7"));
53pub const LINUX_ARM: Platform = LINUX_ARMHF; pub const LINUX_ARMEL: Platform = Platform::new("linux", "arm", Some("v6"));
55pub const LINUX_ARM64: Platform = Platform::new("linux", "arm64", None);
56pub const LINUX_S390X: Platform = Platform::new("linux", "s390x", None);
57pub const LINUX_PPC64: Platform = Platform::new("linux", "ppc64", None);
58pub const LINUX_PPC64LE: Platform = Platform::new("linux", "ppc64le", None);
59pub const DARWIN: Platform = Platform::new("darwin", "amd64", None);
60pub const WINDOWS: Platform = Platform::new("windows", "amd64", None);