Skip to main content

lamina_platform/
lib.rs

1//! lamina-platform - Platform and target detection
2//!
3//! This crate provides target architecture and operating system detection
4//! and definitions. It's separated from the main lamina crate to avoid
5//! dependency cycles with ras and other components.
6//!
7//! ## Modules
8//!
9//! - [`target`] - Target architecture and operating system definitions
10//! - [`detection`] - Host system detection functions
11//! - [`simd`] - SIMD capabilities detection (nightly feature)
12
13pub mod detection;
14pub mod target;
15
16#[cfg(feature = "nightly")]
17pub mod simd;
18
19// Re-export main types
20pub use detection::{cpu_count, detect_host_architecture_only, detect_host_os};
21pub use target::{HOST_ARCH_LIST, Target, TargetArchitecture, TargetOperatingSystem};
22
23#[cfg(feature = "nightly")]
24pub use simd::{ArmSimdExtension, RiscvSimdExtension, SimdCapabilities, X86SimdExtension};
25
26#[cfg(test)]
27mod tests {
28    #![allow(clippy::expect_used)]
29
30    use super::*;
31    use std::str::FromStr;
32
33    #[test]
34    fn test_from_str_roundtrip() {
35        let host = Target::detect_host();
36        let str_repr = host.to_str();
37        let parsed_back = Target::from_str(&str_repr).expect("Valid target should parse");
38
39        assert_eq!(
40            host, parsed_back,
41            "from_str/to_str should be a roundtrip operation"
42        );
43    }
44
45    #[test]
46    fn test_detect_functions_consistency() {
47        // Test that detect_host uses the same logic as the separate functions
48        let combined = Target::detect_host();
49        let arch_str = detect_host_architecture_only();
50        let os_str = detect_host_os();
51
52        assert_eq!(
53            combined.architecture,
54            TargetArchitecture::from_str(arch_str).unwrap_or(TargetArchitecture::Unknown)
55        );
56        assert_eq!(
57            combined.operating_system,
58            TargetOperatingSystem::from_str(os_str).unwrap_or(TargetOperatingSystem::Unknown)
59        );
60    }
61
62    #[cfg(feature = "nightly")]
63    #[test]
64    fn test_target_simd_capabilities() {
65        let target = Target::detect_host();
66        let caps = target.simd_capabilities();
67        // At minimum, we should know if SIMD is supported or not
68        assert!(caps.max_vector_width <= 2048);
69    }
70}