mecha10-cli 0.7.0

Mecha10 CLI tool
Documentation
//! Human-readable names for the Rust target triples `mecha10 build` compiles for.
//!
//! Single source of truth for the `mecha10 init` "where will your robot run" prompt
//! and the `mecha10 build <target>` platform-selection menu, so both stay in sync
//! with each other and with the JSON schema's `buildTargetTriple` enum
//! (`packages/core/src/schema_validation/schemas.rs`) instead of drifting.

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BuildPlatform {
    pub label: &'static str,
    pub triple: &'static str,
}

pub const BUILD_PLATFORMS: &[BuildPlatform] = &[
    BuildPlatform {
        label: "Raspberry Pi 4/5 (64-bit Linux)",
        triple: "aarch64-unknown-linux-gnu",
    },
    BuildPlatform {
        label: "Generic 64-bit Linux (x86_64)",
        triple: "x86_64-unknown-linux-gnu",
    },
    BuildPlatform {
        label: "Apple Silicon Mac (dev/simulation only)",
        triple: "aarch64-apple-darwin",
    },
    BuildPlatform {
        label: "Intel Mac (dev/simulation only)",
        triple: "x86_64-apple-darwin",
    },
];

/// Look up a platform's human-readable label by its triple, for displaying an
/// already-configured `targets.<key>.platforms` entry. Falls back to the raw
/// triple for anything outside `BUILD_PLATFORMS` (e.g. a hand-edited mecha10.json).
pub fn label_for_triple(triple: &str) -> &str {
    BUILD_PLATFORMS
        .iter()
        .find(|p| p.triple == triple)
        .map_or(triple, |p| p.label)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn label_for_triple_finds_known_triples() {
        assert_eq!(
            label_for_triple("aarch64-unknown-linux-gnu"),
            "Raspberry Pi 4/5 (64-bit Linux)"
        );
        assert_eq!(
            label_for_triple("x86_64-unknown-linux-gnu"),
            "Generic 64-bit Linux (x86_64)"
        );
    }

    #[test]
    fn label_for_triple_falls_back_to_the_raw_triple_when_unknown() {
        assert_eq!(
            label_for_triple("riscv64-unknown-linux-gnu"),
            "riscv64-unknown-linux-gnu"
        );
    }

    #[test]
    fn every_platform_has_a_unique_triple() {
        let mut triples: Vec<&str> = BUILD_PLATFORMS.iter().map(|p| p.triple).collect();
        let len_before = triples.len();
        triples.sort_unstable();
        triples.dedup();
        assert_eq!(triples.len(), len_before, "duplicate triple in BUILD_PLATFORMS");
    }
}