From 974a5a79196933e020a73b85366d4c1def599079 Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Tue, 19 May 2026 13:50:19 +0900 Subject: [PATCH] sort: remove nix from dep --- Cargo.lock | 1 - fuzz/Cargo.lock | 1 - src/uu/sort/Cargo.toml | 5 +---- src/uu/sort/src/buffer_hint.rs | 39 ++++++---------------------------- 4 files changed, 8 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 18d7ece3b73..6c486a4c33b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4115,7 +4115,6 @@ dependencies = [ "itertools 0.14.0", "libc", "memchr", - "nix", "rand 0.10.1", "rayon", "rustix", diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 769daabe9e1..12132d1f1f9 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -2012,7 +2012,6 @@ dependencies = [ "itertools", "libc", "memchr", - "nix", "rand", "rayon", "rustix", diff --git a/src/uu/sort/Cargo.toml b/src/uu/sort/Cargo.toml index 206fe294920..db51104c096 100644 --- a/src/uu/sort/Cargo.toml +++ b/src/uu/sort/Cargo.toml @@ -48,14 +48,11 @@ fluent = { workspace = true } foldhash = { workspace = true } [target.'cfg(all(unix, not(any(target_os = "redox", target_os = "fuchsia", target_os = "haiku", target_os = "solaris", target_os = "illumos"))))'.dependencies] -rustix = { workspace = true, features = ["process"] } +rustix = { workspace = true, features = ["system", "process"] } [target.'cfg(not(any(target_os = "redox", target_os = "wasi")))'.dependencies] ctrlc = { workspace = true } -[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] -nix = { workspace = true } - [target.'cfg(unix)'.dependencies] libc = { workspace = true } diff --git a/src/uu/sort/src/buffer_hint.rs b/src/uu/sort/src/buffer_hint.rs index d5baf9efbdb..20539a789bf 100644 --- a/src/uu/sort/src/buffer_hint.rs +++ b/src/uu/sort/src/buffer_hint.rs @@ -83,48 +83,23 @@ fn desired_file_buffer_bytes(total_bytes: u128) -> u128 { quarter.max(max) } +#[allow( + clippy::unnecessary_wraps, + reason = "fn sig must match on all platforms" +)] fn physical_memory_bytes() -> Option { - #[cfg(all( - target_family = "unix", - not(target_os = "redox"), - any(target_os = "linux", target_os = "android") - ))] + #[cfg(any(target_os = "linux", target_os = "android"))] { - physical_memory_bytes_unix() + Some(rustix::system::sysinfo().totalram as u128) } - #[cfg(any( - not(target_family = "unix"), - target_os = "redox", - not(any(target_os = "linux", target_os = "android")) - ))] + #[cfg(not(any(target_os = "linux", target_os = "android")))] { // No portable or safe API is available here to detect total physical memory. None } } -#[cfg(all( - target_family = "unix", - not(target_os = "redox"), - any(target_os = "linux", target_os = "android") -))] -fn physical_memory_bytes_unix() -> Option { - use nix::unistd::{SysconfVar, sysconf}; - - let pages = match sysconf(SysconfVar::_PHYS_PAGES) { - Ok(Some(pages)) if pages > 0 => u128::try_from(pages).ok()?, - _ => return None, - }; - - let page_size = match sysconf(SysconfVar::PAGE_SIZE) { - Ok(Some(page_size)) if page_size > 0 => u128::try_from(page_size).ok()?, - _ => return None, - }; - - Some(pages.saturating_mul(page_size)) -} - #[cfg(test)] mod tests { use super::*;