Skip to content

Commit 4a2c1ae

Browse files
committed
feat(uucore): add shared hardware detection module
Add shared CPU hardware capability detection in uucore to prevent code duplication across utilities. This provides a unified interface for detecting CPU features (AVX512, AVX2, PCLMUL, SSE2, ASIMD) and respecting GLIBC_TUNABLES environment variable. This unblocks PR #9088 (cksum --debug) and PR #9144 (wc --debug) by providing a common implementation that both utilities can use. Features: - CPU feature detection with caching (singleton pattern) - GLIBC_TUNABLES parsing for hwcaps restrictions - Cross-platform support (x86/x86_64, aarch64) - Comprehensive test coverage - Zero-cost abstractions using std::arch Implementation details: - Uses std::arch feature detection (no external deps for detection) - Adds cfg-if dependency for conditional compilation - Feature-gated behind "hardware" feature flag - Android excluded (no CPUID access in sandboxed environment) Related: #9088, #9144
1 parent 73d1bce commit 4a2c1ae

File tree

6 files changed

+451
-0
lines changed

6 files changed

+451
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ binary-heap-plus = "0.5.0"
302302
bstr = "1.9.1"
303303
bytecount = "0.6.8"
304304
byteorder = "1.5.0"
305+
cfg-if = "1.0"
305306
chrono = { version = "0.4.41", default-features = false, features = [
306307
"std",
307308
"alloc",

src/uucore/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ path = "src/lib/lib.rs"
2323

2424
[dependencies]
2525
bstr = { workspace = true }
26+
cfg-if = { workspace = true }
2627
chrono = { workspace = true, optional = true }
2728
clap = { workspace = true }
2829
uucore_procs = { workspace = true }
@@ -131,6 +132,7 @@ fast-inc = []
131132
fs = ["dunce", "libc", "winapi-util", "windows-sys"]
132133
fsext = ["libc", "windows-sys"]
133134
fsxattr = ["xattr"]
135+
hardware = []
134136
lines = []
135137
feat_systemd_logind = ["utmpx", "libc"]
136138
format = [

src/uucore/src/lib/features.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ pub mod tty;
7474

7575
#[cfg(all(unix, feature = "fsxattr"))]
7676
pub mod fsxattr;
77+
#[cfg(feature = "hardware")]
78+
pub mod hardware;
7779
#[cfg(all(target_os = "linux", feature = "selinux"))]
7880
pub mod selinux;
7981
#[cfg(all(unix, not(target_os = "fuchsia"), feature = "signals"))]

0 commit comments

Comments
 (0)