From 44a1222dd02f842af5476978627260621af1c18d Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Thu, 24 Oct 2019 02:08:16 -0700 Subject: [PATCH] Improve src/lib.rs cfgs Right now for each of `util_libc` and `use_file` we have a list of `target_os` configs to determine if we build the module. This PR moves these mod declarations into the main `cfg_if` statement (the one that selects which implementation we use). This way, the mod statements are kept in-sync with the implementations that use them. Also, I merged together `target_os` cfgs that have the same implementation. The downside to this is that the targets are no longer in alphabetical order. Also, this is only being applied to `0.2` as the `0.1` cfgs still have to keep `std` around. --- src/lib.rs | 62 +++++++++++++++--------------------------------- src/util.rs | 2 +- src/util_libc.rs | 1 + 3 files changed, 21 insertions(+), 44 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0716c63c7..2a2003dcc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -154,73 +154,49 @@ cfg_if! { } mod error; -pub use crate::error::Error; - -#[allow(dead_code)] mod util; -#[cfg(all( - unix, - not(any( - target_os = "ios", - target_os = "fuchsia", - target_os = "hermit", - target_os = "l4re" - )) -))] -#[allow(dead_code)] -mod util_libc; - #[cfg(feature = "std")] mod error_impls; -// These targets read from a file as a fallback method. -#[cfg(any( - target_os = "android", - target_os = "linux", - target_os = "macos", - target_os = "solaris", - target_os = "illumos", -))] -mod use_file; +pub use crate::error::Error; // System-specific implementations. // // These should all provide getrandom_inner with the same signature as getrandom. cfg_if! { - if #[cfg(target_os = "android")] { + if #[cfg(any(target_os = "dragonfly", target_os = "emscripten", + target_os = "haiku", target_os = "redox"))] { + mod util_libc; + #[path = "use_file.rs"] mod imp; + } else if #[cfg(any(target_os = "android", target_os = "linux"))] { + mod util_libc; + mod use_file; #[path = "linux_android.rs"] mod imp; + } else if #[cfg(any(target_os = "illumos", target_os = "solaris"))] { + mod util_libc; + mod use_file; + #[path = "solaris_illumos.rs"] mod imp; + } else if #[cfg(any(target_os = "freebsd", target_os = "netbsd"))] { + mod util_libc; + #[path = "bsd_arandom.rs"] mod imp; } else if #[cfg(target_os = "cloudabi")] { #[path = "cloudabi.rs"] mod imp; - } else if #[cfg(target_os = "dragonfly")] { - #[path = "use_file.rs"] mod imp; - } else if #[cfg(target_os = "emscripten")] { - #[path = "use_file.rs"] mod imp; - } else if #[cfg(target_os = "freebsd")] { - #[path = "bsd_arandom.rs"] mod imp; } else if #[cfg(target_os = "fuchsia")] { #[path = "fuchsia.rs"] mod imp; - } else if #[cfg(target_os = "haiku")] { - #[path = "use_file.rs"] mod imp; - } else if #[cfg(target_os = "illumos")] { - #[path = "solaris_illumos.rs"] mod imp; } else if #[cfg(target_os = "ios")] { #[path = "ios.rs"] mod imp; - } else if #[cfg(target_os = "linux")] { - #[path = "linux_android.rs"] mod imp; } else if #[cfg(target_os = "macos")] { + mod util_libc; + mod use_file; #[path = "macos.rs"] mod imp; - } else if #[cfg(target_os = "netbsd")] { - #[path = "bsd_arandom.rs"] mod imp; } else if #[cfg(target_os = "openbsd")] { + mod util_libc; #[path = "openbsd.rs"] mod imp; - } else if #[cfg(target_os = "redox")] { - #[path = "use_file.rs"] mod imp; - } else if #[cfg(target_os = "solaris")] { - #[path = "solaris_illumos.rs"] mod imp; } else if #[cfg(target_os = "wasi")] { #[path = "wasi.rs"] mod imp; } else if #[cfg(target_os = "vxworks")] { + mod util_libc; #[path = "vxworks.rs"] mod imp; } else if #[cfg(all(windows, getrandom_uwp))] { #[path = "windows_uwp.rs"] mod imp; diff --git a/src/util.rs b/src/util.rs index e0e930752..c0f4f9b24 100644 --- a/src/util.rs +++ b/src/util.rs @@ -5,7 +5,7 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. - +#![allow(dead_code)] use core::sync::atomic::{AtomicUsize, Ordering::Relaxed}; // This structure represents a lazily initialized static usize value. Useful diff --git a/src/util_libc.rs b/src/util_libc.rs index 5a0517011..fde39c9c5 100644 --- a/src/util_libc.rs +++ b/src/util_libc.rs @@ -5,6 +5,7 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. +#![allow(dead_code)] use crate::error::ERRNO_NOT_POSITIVE; use crate::util::LazyUsize; use crate::Error;