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/// One selectable platform: a human-readable label and the Rust target triple it
9/// maps to.
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub struct BuildPlatform {
12    pub label: &'static str,
13    pub triple: &'static str,
14}
15
16/// Every triple `mecha10 build` supports, in display order. Must stay in sync with
17/// `buildTargetTriple`'s enum in `packages/core/src/schema_validation/schemas.rs`.
18pub 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
37/// Look up a platform's human-readable label by its triple, for displaying an
38/// already-configured `targets.<key>.platforms` entry. Falls back to the raw
39/// triple for anything outside `BUILD_PLATFORMS` (e.g. a hand-edited mecha10.json).
40pub 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}