Skip to content

Commit d7b0d8c

Browse files
committed
cksum: switch to uucore::hardware for --debug\n\n- Remove local hardware module and cpufeatures dependency\n- Enable uucore 'hardware' feature in uu_cksum\n- Print CPU feature info via uucore instead of local module\n\nRefs: uutils#9279
1 parent 7e02652 commit d7b0d8c

File tree

5 files changed

+46
-197
lines changed

5 files changed

+46
-197
lines changed

Cargo.lock

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

fuzz/Cargo.lock

Lines changed: 14 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/cksum/Cargo.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ path = "src/cksum.rs"
1919

2020
[dependencies]
2121
clap = { workspace = true }
22-
uucore = { workspace = true, features = ["checksum", "encoding", "sum"] }
22+
uucore = { workspace = true, features = [
23+
"checksum",
24+
"encoding",
25+
"sum",
26+
"hardware",
27+
] }
2328
hex = { workspace = true }
2429
fluent = { workspace = true }
2530

26-
[target.'cfg(all(any(target_arch = "x86_64", target_arch = "aarch64", target_arch = "loongarch64", target_arch = "x86"), not(target_os = "android")))'.dependencies]
27-
cpufeatures = { workspace = true }
28-
2931
[dev-dependencies]
3032
divan = { workspace = true }
3133
tempfile = { workspace = true }

src/uu/cksum/src/cksum.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55

66
// spell-checker:ignore (ToDO) fname, algo, bitlen
77

8-
mod hardware;
9-
108
use clap::builder::ValueParser;
119
use clap::{Arg, ArgAction, Command};
12-
use hardware::CpuFeatures;
1310
use std::ffi::{OsStr, OsString};
1411
use std::iter;
1512
use uucore::checksum::compute::{
@@ -23,14 +20,32 @@ use uucore::checksum::{
2320
sanitize_sha2_sha3_length_str,
2421
};
2522
use uucore::error::UResult;
23+
use uucore::hardware::CpuFeatures;
2624
use uucore::line_ending::LineEnding;
2725
use uucore::{format_usage, translate};
2826

2927
/// Print CPU hardware capability detection information to stderr
3028
/// This matches GNU cksum's --debug behavior
3129
fn print_cpu_debug_info() {
3230
let features = CpuFeatures::detect();
33-
features.print_debug();
31+
32+
fn print_feature(name: &str, available: bool) {
33+
if available {
34+
eprintln!("cksum: using {name} hardware support");
35+
} else {
36+
eprintln!("cksum: {name} support not detected");
37+
}
38+
}
39+
40+
// x86/x86_64
41+
print_feature("avx512", features.has_avx512());
42+
print_feature("avx2", features.has_avx2());
43+
print_feature("pclmul", features.has_pclmul());
44+
45+
// ARM aarch64
46+
if cfg!(target_arch = "aarch64") {
47+
print_feature("vmull", features.has_vmull());
48+
}
3449
}
3550

3651
mod options {
@@ -192,11 +207,17 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
192207
matches.get_flag(options::BASE64),
193208
);
194209

210+
// Print hardware debug info if requested
211+
if matches.get_flag(options::DEBUG) {
212+
print_cpu_debug_info();
213+
}
214+
195215
let opts = ChecksumComputeOptions {
196216
algo_kind: algo,
197217
output_format,
198218
line_ending,
199-
debug: matches.get_flag(options::DEBUG),
219+
binary,
220+
no_names: false,
200221
};
201222

202223
perform_checksum_computation(opts, files)?;

src/uu/cksum/src/hardware.rs

Lines changed: 0 additions & 172 deletions
This file was deleted.

0 commit comments

Comments
 (0)