#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BuildPlatform {
pub label: &'static str,
pub triple: &'static str,
}
pub const BUILD_PLATFORMS: &[BuildPlatform] = &[
BuildPlatform {
label: "Raspberry Pi 4/5 (64-bit Linux)",
triple: "aarch64-unknown-linux-gnu",
},
BuildPlatform {
label: "Generic 64-bit Linux (x86_64)",
triple: "x86_64-unknown-linux-gnu",
},
BuildPlatform {
label: "Apple Silicon Mac (dev/simulation only)",
triple: "aarch64-apple-darwin",
},
BuildPlatform {
label: "Intel Mac (dev/simulation only)",
triple: "x86_64-apple-darwin",
},
];
pub fn label_for_triple(triple: &str) -> &str {
BUILD_PLATFORMS
.iter()
.find(|p| p.triple == triple)
.map_or(triple, |p| p.label)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn label_for_triple_finds_known_triples() {
assert_eq!(
label_for_triple("aarch64-unknown-linux-gnu"),
"Raspberry Pi 4/5 (64-bit Linux)"
);
assert_eq!(
label_for_triple("x86_64-unknown-linux-gnu"),
"Generic 64-bit Linux (x86_64)"
);
}
#[test]
fn label_for_triple_falls_back_to_the_raw_triple_when_unknown() {
assert_eq!(
label_for_triple("riscv64-unknown-linux-gnu"),
"riscv64-unknown-linux-gnu"
);
}
#[test]
fn every_platform_has_a_unique_triple() {
let mut triples: Vec<&str> = BUILD_PLATFORMS.iter().map(|p| p.triple).collect();
let len_before = triples.len();
triples.sort_unstable();
triples.dedup();
assert_eq!(triples.len(), len_before, "duplicate triple in BUILD_PLATFORMS");
}
}