cpudetect 0.2.0

Ergonomic helpers for CPU feature detection
Documentation
pub mod aarch64;
pub mod x86_64;

/// Expands a CPU family name into Rust `#[target_feature]` requirements.
///
/// Takes the family name as an attribute, e.g. `#[target_family("znver3")]`.
pub use cpudetect_macros::target_family;

macro_rules! declare_is_compatible {
    ($family:literal $(, $feature:literal)* $(,)?) => {
        pastey::paste! {
            #[doc = concat!(
                "Returns `true` if the current CPU is compatible with the `",
                $family,
                "` feature set."
            )]
            #[must_use]
            #[inline(always)]
            #[cfg(any(feature = "static", not(feature = "enabled")))]
            pub fn [<is_ $family _compatible>]() -> bool {
                true $(&& [<has_ $feature>]())*
            }

            #[doc = concat!(
                "Returns `true` if the current CPU is compatible with the `",
                $family,
                "` feature set."
            )]
            #[must_use]
            #[inline]
            #[cfg(not(any(feature = "static", not(feature = "enabled"))))]
            pub fn [<is_ $family _compatible>]() -> bool {
                // For non-static builds, cache family detection to avoid
                // long chains of feature detection calls.
                use std::sync::LazyLock;
                #[allow(non_upper_case_globals)]
                static [<lazy_ $family>]: LazyLock<bool> = LazyLock::new(|| {
                    true $(&& [<has_ $feature>]())*
                });
                *[<lazy_ $family>]
            }
        }
    };
}

pub(crate) use declare_is_compatible;