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