cpudetect 0.1.0

Ergonomic helpers for CPU feature detection
Documentation
#[cfg(target_arch = "aarch64")]
mod aarch64;
#[cfg(target_arch = "x86_64")]
mod x86_64;

#[cfg(target_arch = "aarch64")]
pub use aarch64::*;
/// 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;
#[cfg(target_arch = "x86_64")]
pub use x86_64::*;

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(feature = "static")]
            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(feature = "static"))]
            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;