Skip to content

Commit cf2d81b

Browse files
josephlrnewpavlov
authored andcommitted
Improve src/lib.rs cfgs (#119)
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.
1 parent 1f1f964 commit cf2d81b

File tree

3 files changed

+21
-44
lines changed

3 files changed

+21
-44
lines changed

src/lib.rs

+19-43
Original file line numberDiff line numberDiff line change
@@ -154,73 +154,49 @@ cfg_if! {
154154
}
155155

156156
mod error;
157-
pub use crate::error::Error;
158-
159-
#[allow(dead_code)]
160157
mod util;
161158

162-
#[cfg(all(
163-
unix,
164-
not(any(
165-
target_os = "ios",
166-
target_os = "fuchsia",
167-
target_os = "hermit",
168-
target_os = "l4re"
169-
))
170-
))]
171-
#[allow(dead_code)]
172-
mod util_libc;
173-
174159
#[cfg(feature = "std")]
175160
mod error_impls;
176161

177-
// These targets read from a file as a fallback method.
178-
#[cfg(any(
179-
target_os = "android",
180-
target_os = "linux",
181-
target_os = "macos",
182-
target_os = "solaris",
183-
target_os = "illumos",
184-
))]
185-
mod use_file;
162+
pub use crate::error::Error;
186163

187164
// System-specific implementations.
188165
//
189166
// These should all provide getrandom_inner with the same signature as getrandom.
190167
cfg_if! {
191-
if #[cfg(target_os = "android")] {
168+
if #[cfg(any(target_os = "dragonfly", target_os = "emscripten",
169+
target_os = "haiku", target_os = "redox"))] {
170+
mod util_libc;
171+
#[path = "use_file.rs"] mod imp;
172+
} else if #[cfg(any(target_os = "android", target_os = "linux"))] {
173+
mod util_libc;
174+
mod use_file;
192175
#[path = "linux_android.rs"] mod imp;
176+
} else if #[cfg(any(target_os = "illumos", target_os = "solaris"))] {
177+
mod util_libc;
178+
mod use_file;
179+
#[path = "solaris_illumos.rs"] mod imp;
180+
} else if #[cfg(any(target_os = "freebsd", target_os = "netbsd"))] {
181+
mod util_libc;
182+
#[path = "bsd_arandom.rs"] mod imp;
193183
} else if #[cfg(target_os = "cloudabi")] {
194184
#[path = "cloudabi.rs"] mod imp;
195-
} else if #[cfg(target_os = "dragonfly")] {
196-
#[path = "use_file.rs"] mod imp;
197-
} else if #[cfg(target_os = "emscripten")] {
198-
#[path = "use_file.rs"] mod imp;
199-
} else if #[cfg(target_os = "freebsd")] {
200-
#[path = "bsd_arandom.rs"] mod imp;
201185
} else if #[cfg(target_os = "fuchsia")] {
202186
#[path = "fuchsia.rs"] mod imp;
203-
} else if #[cfg(target_os = "haiku")] {
204-
#[path = "use_file.rs"] mod imp;
205-
} else if #[cfg(target_os = "illumos")] {
206-
#[path = "solaris_illumos.rs"] mod imp;
207187
} else if #[cfg(target_os = "ios")] {
208188
#[path = "ios.rs"] mod imp;
209-
} else if #[cfg(target_os = "linux")] {
210-
#[path = "linux_android.rs"] mod imp;
211189
} else if #[cfg(target_os = "macos")] {
190+
mod util_libc;
191+
mod use_file;
212192
#[path = "macos.rs"] mod imp;
213-
} else if #[cfg(target_os = "netbsd")] {
214-
#[path = "bsd_arandom.rs"] mod imp;
215193
} else if #[cfg(target_os = "openbsd")] {
194+
mod util_libc;
216195
#[path = "openbsd.rs"] mod imp;
217-
} else if #[cfg(target_os = "redox")] {
218-
#[path = "use_file.rs"] mod imp;
219-
} else if #[cfg(target_os = "solaris")] {
220-
#[path = "solaris_illumos.rs"] mod imp;
221196
} else if #[cfg(target_os = "wasi")] {
222197
#[path = "wasi.rs"] mod imp;
223198
} else if #[cfg(target_os = "vxworks")] {
199+
mod util_libc;
224200
#[path = "vxworks.rs"] mod imp;
225201
} else if #[cfg(all(windows, getrandom_uwp))] {
226202
#[path = "windows_uwp.rs"] mod imp;

src/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
8-
8+
#![allow(dead_code)]
99
use core::sync::atomic::{AtomicUsize, Ordering::Relaxed};
1010

1111
// This structure represents a lazily initialized static usize value. Useful

src/util_libc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
8+
#![allow(dead_code)]
89
use crate::error::ERRNO_NOT_POSITIVE;
910
use crate::util::LazyUsize;
1011
use crate::Error;

0 commit comments

Comments
 (0)