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