Skip to content

Commit

Permalink
Remove linux_android.rs and use getrandom.rs instead (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamird authored Feb 5, 2025
1 parent ce3b017 commit 3ba857b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 47 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/nopanic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ jobs:
- name: Check (linux_android_with_fallback.rs)
run: (exit $( grep -c panic target/release/libgetrandom_wrapper.so ))

- name: Build (linux_android.rs)
- name: Build (getrandom.rs)
env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="linux_getrandom"
run: cargo build --release
- name: Check (linux_android.rs)
- name: Check (getrandom.rs)
run: (exit $( grep -c panic target/release/libgetrandom_wrapper.so ))

- name: Build (rdrand.rs)
Expand Down Expand Up @@ -98,11 +98,6 @@ jobs:
- name: Check (rndr.rs)
run: (exit $( grep -c panic target/aarch64-unknown-linux-gnu/release/libgetrandom_wrapper.so ))

- name: Build (getrandom.rs)
run: cross build --release --target=x86_64-unknown-freebsd
- name: Check (getrandom.rs)
run: (exit $( grep -c panic target/x86_64-unknown-freebsd/release/libgetrandom_wrapper.so ))

- name: Build (netbsd.rs)
run: cross build --release --target=x86_64-unknown-netbsd
- name: Check (netbsd.rs)
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ jobs:
run: cargo clippy -Zbuild-std=core --target x86_64-unknown-fuchsia
- name: OpenBSD (getentropy.rs)
run: cargo clippy -Zbuild-std=core --target x86_64-unknown-openbsd
- name: FreeBSD (getrandom.rs)
run: cargo clippy -Zbuild-std=core --target x86_64-unknown-freebsd
- name: Hermit (hermit.rs)
run: cargo clippy -Zbuild-std=core --target x86_64-unknown-hermit
- name: Web WASM (wasm_js.rs)
Expand All @@ -53,7 +51,7 @@ jobs:
env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js" -Ctarget-feature=+atomics,+bulk-memory
run: cargo clippy -Zbuild-std --target wasm32-unknown-unknown --features wasm_js
- name: Linux (linux_android.rs)
- name: Linux (getrandom.rs)
env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="linux_getrandom"
run: cargo clippy --target x86_64-unknown-linux-gnu
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ cfg-if = "1"
compiler_builtins = { version = "0.1", optional = true }
core = { version = "1.0", optional = true, package = "rustc-std-workspace-core" }

# linux_android / linux_android_with_fallback
# getrandom / linux_android_with_fallback
[target.'cfg(all(any(target_os = "linux", target_os = "android"), not(any(getrandom_backend = "custom", getrandom_backend = "rdrand", getrandom_backend = "rndr"))))'.dependencies]
libc = { version = "0.2.154", default-features = false }

Expand Down
31 changes: 15 additions & 16 deletions src/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ cfg_if! {
mod custom;
pub use custom::*;
} else if #[cfg(getrandom_backend = "linux_getrandom")] {
mod linux_android;
pub use linux_android::*;
mod getrandom;
pub use getrandom::*;
} else if #[cfg(getrandom_backend = "rdrand")] {
mod rdrand;
pub use rdrand::*;
Expand Down Expand Up @@ -51,17 +51,6 @@ cfg_if! {
))] {
mod getentropy;
pub use getentropy::*;
} else if #[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "hurd",
target_os = "illumos",
// Check for target_arch = "arm" to only include the 3DS. Does not
// include the Nintendo Switch (which is target_arch = "aarch64").
all(target_os = "horizon", target_arch = "arm"),
))] {
mod getrandom;
pub use getrandom::*;
} else if #[cfg(any(
// Rust supports Android API level 19 (KitKat) [0] and the next upgrade targets
// level 21 (Lollipop) [1], while `getrandom(2)` was added only in
Expand Down Expand Up @@ -102,9 +91,19 @@ cfg_if! {
mod use_file;
mod linux_android_with_fallback;
pub use linux_android_with_fallback::*;
} else if #[cfg(any(target_os = "android", target_os = "linux"))] {
mod linux_android;
pub use linux_android::*;
} else if #[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "hurd",
target_os = "illumos",
// Check for target_arch = "arm" to only include the 3DS. Does not
// include the Nintendo Switch (which is target_arch = "aarch64").
all(target_os = "horizon", target_arch = "arm"),
))] {
mod getrandom;
pub use getrandom::*;
} else if #[cfg(target_os = "solaris")] {
mod solaris;
pub use solaris::*;
Expand Down
4 changes: 2 additions & 2 deletions src/backends/getrandom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! nothing. On illumos, the default pool is used to implement getentropy(2),
//! so we assume it is acceptable here.
use crate::Error;
use core::{ffi::c_void, mem::MaybeUninit};
use core::mem::MaybeUninit;

pub use crate::util::{inner_u32, inner_u64};

Expand All @@ -26,6 +26,6 @@ mod util_libc;
#[inline]
pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
util_libc::sys_fill_exact(dest, |buf| unsafe {
libc::getrandom(buf.as_mut_ptr().cast::<c_void>(), buf.len(), 0)
libc::getrandom(buf.as_mut_ptr().cast(), buf.len(), 0)
})
}
18 changes: 0 additions & 18 deletions src/backends/linux_android.rs

This file was deleted.

0 comments on commit 3ba857b

Please sign in to comment.