Skip to main content

mecha10_cli/services/
build_platforms.rs

1//! Human-readable names for the Rust target triples `mecha10 build` compiles for.
2//!
3//! Single source of truth for the `mecha10 init` "where will your robot run" prompt
4//! and the `mecha10 build <target>` platform-selection menu, so both stay in sync
5//! with each other and with the JSON schema's `buildTargetTriple` enum
6//! (`packages/core/src/schema_validation/schemas.rs`) instead of drifting.
7
8#[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
33/// Look up a platform's human-readable label by its triple, for displaying an
34/// already-configured `targets.<key>.platforms` entry. Falls back to the raw
35/// triple for anything outside `BUILD_PLATFORMS` (e.g. a hand-edited mecha10.json).
36pub 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}