cpudetect
cpudetect is a Rust crate that provides ergonomic helpers for CPU feature detection.
It exposes:
- per-feature checks such as
has_avx2()andhas_neon() - per-family compatibility checks such as
is_x86_64_v3_compatible() - a
#[target_family(...)]procedural macro for expanding a CPU family into Rust#[target_feature]requirements
The crate currently targets x86_64 and aarch64.
Installation
Add the crate to your Cargo.toml:
[]
= "0.1.0"
Cargo features
enabled(default): enables CPU detectionstatic: disables runtime detection and relies on compile-timetarget_feature/target-cpusettings
If you disable the default enabled feature, all detection helpers return false.
Usage
Check an x86_64 CPU feature
Check a baseline CPU family
Check an AArch64 feature set
Use target_family to enable code for a CPU family
use target_family;
unsafe
Supported API shape
- On
x86_64, the crate exports feature helpers fromsrc/x86_64/features.rsand family helpers fromsrc/x86_64/families.rs. - On
aarch64, the crate exports feature helpers fromsrc/aarch64/features.rsand family helpers fromsrc/aarch64/families.rs. - Family helpers cache runtime detection results on non-
staticbuilds.
Development
The repository includes a just precommit task that runs the configured Clippy checks.
License
MIT