cargo_gazelle/
platforms.rsuse std::sync::Arc;
use guppy::platform::{Platform, PlatformSpec, TargetFeatures, Triple};
use std::sync::LazyLock;
use crate::ToBazelDefinition;
static AARCH64_MAC_OS: LazyLock<PlatformSpec> = LazyLock::new(|| {
let triple = Triple::new("aarch64-apple-darwin").unwrap();
PlatformSpec::Platform(Arc::new(Platform::from_triple(triple, TargetFeatures::All)))
});
static X86_64_MAC_OS: LazyLock<PlatformSpec> = LazyLock::new(|| {
let triple = Triple::new("x86_64-apple-darwin").unwrap();
PlatformSpec::Platform(Arc::new(Platform::from_triple(triple, TargetFeatures::All)))
});
static AARCH64_LINUX_GNU: LazyLock<PlatformSpec> = LazyLock::new(|| {
let triple = Triple::new("aarch64-unknown-linux-gnu").unwrap();
PlatformSpec::Platform(Arc::new(Platform::from_triple(triple, TargetFeatures::All)))
});
static X86_64_LINUX_GNU: LazyLock<PlatformSpec> = LazyLock::new(|| {
let triple = Triple::new("x86_64-unknown-linux-gnu").unwrap();
PlatformSpec::Platform(Arc::new(Platform::from_triple(triple, TargetFeatures::All)))
});
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum PlatformVariant {
Aarch64MacOS,
X86_64MacOS,
Aarch64Linux,
X86_64Linux,
}
impl PlatformVariant {
const ALL: &'static [PlatformVariant] = &[
PlatformVariant::Aarch64MacOS,
PlatformVariant::X86_64MacOS,
PlatformVariant::Aarch64Linux,
PlatformVariant::X86_64Linux,
];
pub fn spec(&self) -> &PlatformSpec {
match self {
PlatformVariant::Aarch64MacOS => &*AARCH64_MAC_OS,
PlatformVariant::X86_64MacOS => &*X86_64_MAC_OS,
PlatformVariant::Aarch64Linux => &*AARCH64_LINUX_GNU,
PlatformVariant::X86_64Linux => &*X86_64_LINUX_GNU,
}
}
pub fn all() -> &'static [PlatformVariant] {
Self::ALL
}
}
impl ToBazelDefinition for PlatformVariant {
fn format(&self, writer: &mut dyn std::fmt::Write) -> Result<(), std::fmt::Error> {
use PlatformVariant::*;
let s = match self {
Aarch64MacOS => "@//misc/bazel/platforms:macos_arm",
X86_64MacOS => "@//misc/bazel/platforms:macos_x86_64",
Aarch64Linux => "@//misc/bazel/platforms:linux_arm",
X86_64Linux => "@//misc/bazel/platforms:linux_x86_64",
};
write!(writer, "\"{s}\"")
}
}