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// Backward compatibility: keep the deprecated helper available, but don't warn in this crate.
24#[allow(deprecated)]
25pub use detection::detect_host_architecture;
26
27#[cfg(feature = "nightly")]
28pub use simd::{ArmSimdExtension, RiscvSimdExtension, SimdCapabilities, X86SimdExtension};
29
30#[cfg(test)]
31mod tests {
32    #![allow(clippy::expect_used)]
33
34    use super::*;
35    use std::str::FromStr;
36
37    #[test]
38    fn test_from_str_roundtrip() {
39        let host = Target::detect_host();
40        let str_repr = host.to_str();
41        let parsed_back = Target::from_str(&str_repr).expect("Valid target should parse");
42
43        assert_eq!(
44            host, parsed_back,
45            "from_str/to_str should be a roundtrip operation"
46        );
47    }
48
49    #[test]
50    fn test_detect_functions_consistency() {
51        // Test that detect_host uses the same logic as the separate functions
52        let combined = Target::detect_host();
53        let arch_str = detect_host_architecture_only();
54        let os_str = detect_host_os();
55
56        assert_eq!(
57            combined.architecture,
58            TargetArchitecture::from_str(arch_str).unwrap_or(TargetArchitecture::Unknown)
59        );
60        assert_eq!(
61            combined.operating_system,
62            TargetOperatingSystem::from_str(os_str).unwrap_or(TargetOperatingSystem::Unknown)
63        );
64    }
65
66    #[cfg(feature = "nightly")]
67    #[test]
68    fn test_target_simd_capabilities() {
69        let target = Target::detect_host();
70        let caps = target.simd_capabilities();
71        // At minimum, we should know if SIMD is supported or not
72        assert!(caps.max_vector_width >= 0);
73    }
74}