|
| 1 | +//! # Architecture Detection |
| 2 | +//! |
| 3 | +//! Target triple detection and platform support utilities for the |
| 4 | +//! Maintain build orchestrator. |
| 5 | +
|
| 6 | +/// Represents a supported target platform. |
| 7 | +#[derive(Debug, Clone, PartialEq, Eq)] |
| 8 | +pub struct TargetArchitecture { |
| 9 | + /// The full Rust target triple (e.g., "aarch64-apple-darwin"). |
| 10 | + pub Triple: String, |
| 11 | + /// Human-readable platform name. |
| 12 | + pub Name: String, |
| 13 | + /// Whether this architecture is supported for release builds. |
| 14 | + pub IsSupported: bool, |
| 15 | +} |
| 16 | + |
| 17 | +impl TargetArchitecture { |
| 18 | + /// Returns all supported target architectures. |
| 19 | + pub fn SupportedTargets() -> Vec<Self> { |
| 20 | + vec![ |
| 21 | + Self { |
| 22 | + Triple: "aarch64-apple-darwin".to_string(), |
| 23 | + Name: "macOS (Apple Silicon)".to_string(), |
| 24 | + IsSupported: true, |
| 25 | + }, |
| 26 | + Self { |
| 27 | + Triple: "x86_64-apple-darwin".to_string(), |
| 28 | + Name: "macOS (Intel)".to_string(), |
| 29 | + IsSupported: true, |
| 30 | + }, |
| 31 | + Self { |
| 32 | + Triple: "x86_64-unknown-linux-gnu".to_string(), |
| 33 | + Name: "Linux (x86_64)".to_string(), |
| 34 | + IsSupported: true, |
| 35 | + }, |
| 36 | + Self { |
| 37 | + Triple: "x86_64-pc-windows-msvc".to_string(), |
| 38 | + Name: "Windows (x86_64)".to_string(), |
| 39 | + IsSupported: true, |
| 40 | + }, |
| 41 | + ] |
| 42 | + } |
| 43 | + |
| 44 | + /// Returns the current host architecture. |
| 45 | + pub fn Current() -> Self { |
| 46 | + #[cfg(all(target_arch = "aarch64", target_os = "macos"))] |
| 47 | + return Self { |
| 48 | + Triple: "aarch64-apple-darwin".to_string(), |
| 49 | + Name: "macOS (Apple Silicon)".to_string(), |
| 50 | + IsSupported: true, |
| 51 | + }; |
| 52 | + |
| 53 | + #[cfg(all(target_arch = "x86_64", target_os = "macos"))] |
| 54 | + return Self { |
| 55 | + Triple: "x86_64-apple-darwin".to_string(), |
| 56 | + Name: "macOS (Intel)".to_string(), |
| 57 | + IsSupported: true, |
| 58 | + }; |
| 59 | + |
| 60 | + #[cfg(all(target_arch = "x86_64", target_os = "linux"))] |
| 61 | + return Self { |
| 62 | + Triple: "x86_64-unknown-linux-gnu".to_string(), |
| 63 | + Name: "Linux (x86_64)".to_string(), |
| 64 | + IsSupported: true, |
| 65 | + }; |
| 66 | + |
| 67 | + #[cfg(all(target_arch = "x86_64", target_os = "windows"))] |
| 68 | + return Self { |
| 69 | + Triple: "x86_64-pc-windows-msvc".to_string(), |
| 70 | + Name: "Windows (x86_64)".to_string(), |
| 71 | + IsSupported: true, |
| 72 | + }; |
| 73 | + |
| 74 | + #[cfg(not(any( |
| 75 | + all(target_arch = "aarch64", target_os = "macos"), |
| 76 | + all(target_arch = "x86_64", target_os = "macos"), |
| 77 | + all(target_arch = "x86_64", target_os = "linux"), |
| 78 | + all(target_arch = "x86_64", target_os = "windows"), |
| 79 | + )))] |
| 80 | + return Self { |
| 81 | + Triple: "unknown".to_string(), |
| 82 | + Name: "Unknown".to_string(), |
| 83 | + IsSupported: false, |
| 84 | + }; |
| 85 | + } |
| 86 | +} |
0 commit comments