mecha10_cli/services/
build_platforms.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub struct BuildPlatform {
12 pub label: &'static str,
13 pub triple: &'static str,
14}
15
16pub const BUILD_PLATFORMS: &[BuildPlatform] = &[
19 BuildPlatform {
20 label: "Raspberry Pi 4/5 (64-bit Linux)",
21 triple: "aarch64-unknown-linux-gnu",
22 },
23 BuildPlatform {
24 label: "Generic 64-bit Linux (x86_64)",
25 triple: "x86_64-unknown-linux-gnu",
26 },
27 BuildPlatform {
28 label: "Apple Silicon Mac (dev/simulation only)",
29 triple: "aarch64-apple-darwin",
30 },
31 BuildPlatform {
32 label: "Intel Mac (dev/simulation only)",
33 triple: "x86_64-apple-darwin",
34 },
35];
36
37pub fn label_for_triple(triple: &str) -> &str {
41 BUILD_PLATFORMS
42 .iter()
43 .find(|p| p.triple == triple)
44 .map_or(triple, |p| p.label)
45}
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn label_for_triple_finds_known_triples() {
53 assert_eq!(
54 label_for_triple("aarch64-unknown-linux-gnu"),
55 "Raspberry Pi 4/5 (64-bit Linux)"
56 );
57 assert_eq!(
58 label_for_triple("x86_64-unknown-linux-gnu"),
59 "Generic 64-bit Linux (x86_64)"
60 );
61 }
62
63 #[test]
64 fn label_for_triple_falls_back_to_the_raw_triple_when_unknown() {
65 assert_eq!(
66 label_for_triple("riscv64-unknown-linux-gnu"),
67 "riscv64-unknown-linux-gnu"
68 );
69 }
70
71 #[test]
72 fn every_platform_has_a_unique_triple() {
73 let mut triples: Vec<&str> = BUILD_PLATFORMS.iter().map(|p| p.triple).collect();
74 let len_before = triples.len();
75 triples.sort_unstable();
76 triples.dedup();
77 assert_eq!(triples.len(), len_before, "duplicate triple in BUILD_PLATFORMS");
78 }
79}