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//! - [`arch_table`] - the architecture table: every property of every architecture
10//! - [`target`] - targets: architecture, environment, operating system and variant
11//! - [`environment`] - the C runtime and ABI axis
12//! - [`cpu_level`] - x86-64 microarchitecture levels (v1 to v4)
13//! - [`arch_variant`] - sub-architecture variants for the other families
14//! - [`detection`] - Host system detection functions
15//! - [`simd`] - SIMD capabilities detection (nightly feature)
16
17pub mod arch_table;
18pub mod arch_variant;
19pub mod cpu_level;
20pub mod detection;
21pub mod environment;
22pub mod shared;
23pub mod target;
24pub mod vector;
25
26#[cfg(feature = "nightly")]
27pub mod simd;
28
29// Re-export main types
30pub use arch_table::{
31    ArchSpec, Endianness, LinuxInterpreters, OutputArtifact, PointerWidth, TargetArchitecture,
32    TargetDataLayout, ToolchainTriples, VaListAbi,
33};
34pub use arch_variant::{
35    Aarch64Level, ArchVariant, Armv7Profile, Armv7Variant, PowerLevel, RiscvIsa, VariantAxis,
36};
37pub use cpu_level::X86CpuLevel;
38pub use detection::{cpu_count, detect_host_architecture_only, detect_host_os};
39pub use environment::{CompilerRuntime, Libc, TargetEnvironment};
40pub use shared::{MemoryOrdering, SourceLoc, TlsModel};
41pub use target::{
42    Target, TargetOperatingSystem, default_environment, host_arch_list, parse_arch_token,
43    parse_architecture, target_alias_list,
44};
45pub use vector::any_vector_register_bits;
46
47#[cfg(feature = "nightly")]
48pub use simd::{ArmSimdExtension, RiscvSimdExtension, SimdCapabilities, X86SimdExtension};
49
50#[cfg(test)]
51mod tests {
52    #![allow(clippy::expect_used)]
53
54    use super::*;
55    use std::str::FromStr;
56
57    #[test]
58    fn test_from_str_roundtrip() {
59        let host = Target::detect_host().expect("host is a supported target");
60        let str_repr = host.to_str();
61        let parsed_back = Target::from_str(&str_repr).expect("Valid target should parse");
62
63        assert_eq!(
64            host, parsed_back,
65            "from_str/to_str should be a roundtrip operation"
66        );
67    }
68
69    #[test]
70    fn test_detect_functions_consistency() {
71        // Test that detect_host uses the same logic as the separate functions
72        let combined = Target::detect_host().expect("host is a supported target");
73        let arch_str = detect_host_architecture_only();
74        let os_str = detect_host_os();
75
76        assert_eq!(
77            combined.architecture,
78            TargetArchitecture::from_str(arch_str).expect("host arch parses")
79        );
80        assert_eq!(
81            combined.operating_system,
82            TargetOperatingSystem::from_str(os_str).expect("host os parses")
83        );
84    }
85
86    #[cfg(feature = "nightly")]
87    #[test]
88    fn test_target_simd_capabilities() {
89        let target = Target::detect_host().expect("host is a supported target");
90        let caps = target.simd_capabilities();
91        // At minimum, we should know if SIMD is supported or not
92        assert!(caps.max_vector_width <= 2048);
93    }
94}