Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Solaris/OpenBSD/Dragonfly build and re-enable CI #301

Merged
merged 6 commits into from Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions .github/workflows/tests.yml
Expand Up @@ -166,8 +166,9 @@ jobs:
strategy:
matrix:
target: [
# See: https://github.com/rust-random/getrandom/issues/254
# sparcv9-sun-solaris,
sparcv9-sun-solaris,
x86_64-unknown-illumos,
x86_64-unknown-freebsd,
x86_64-unknown-netbsd,
]
steps:
Expand Down Expand Up @@ -277,7 +278,6 @@ jobs:
strategy:
matrix:
target: [
x86_64-unknown-freebsd,
x86_64-fuchsia,
x86_64-unknown-redox,
x86_64-fortanix-unknown-sgx,
Expand All @@ -288,7 +288,7 @@ jobs:
with:
profile: minimal
target: ${{ matrix.target }}
toolchain: nightly # Required to build libc for Redox
toolchain: stable
override: true
- uses: Swatinem/rust-cache@v1
- name: Build
Expand Down Expand Up @@ -319,6 +319,14 @@ jobs:
run: cargo build -Z build-std=core --target=aarch64-kmc-solid_asp3
- name: Nintendo 3DS
run: cargo build -Z build-std=core --target=armv6k-nintendo-3ds
- name: RISC-V ESP-IDF
run: cargo build -Z build-std=core --target=riscv32imc-esp-espidf
- name: OpenBSD
run: cargo build -Z build-std=std --target=x86_64-unknown-openbsd --features=std
- name: Dragonfly BSD
run: cargo build -Z build-std=std --target=x86_64-unknown-dragonfly --features=std
- name: Haiku OS
run: cargo build -Z build-std=std --target=x86_64-unknown-haiku --features=std

clippy-fmt:
name: Clippy + rustfmt
Expand Down
6 changes: 4 additions & 2 deletions src/dragonfly.rs
Expand Up @@ -12,7 +12,7 @@ use crate::{
util_libc::{sys_fill_exact, Weak},
Error,
};
use std::mem::MaybeUninit;
use core::mem::MaybeUninit;

pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
static GETRANDOM: Weak = unsafe { Weak::new("getrandom\0") };
Expand All @@ -21,7 +21,9 @@ pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
// getrandom(2) was introduced in DragonflyBSD 5.7
if let Some(fptr) = GETRANDOM.ptr() {
let func: GetRandomFn = unsafe { core::mem::transmute(fptr) };
return sys_fill_exact(dest, |buf| unsafe { func(buf.as_mut_ptr(), buf.len(), 0) });
return sys_fill_exact(dest, |buf| unsafe {
func(buf.as_mut_ptr() as *mut u8, buf.len(), 0)
});
} else {
use_file::getrandom_inner(dest)
}
Expand Down
1 change: 1 addition & 0 deletions src/openbsd.rs
Expand Up @@ -8,6 +8,7 @@

//! Implementation for OpenBSD
use crate::{util_libc::last_os_error, Error};
use core::mem::MaybeUninit;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, good catch.


pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
// getentropy(2) was added in OpenBSD 5.6, so we can use it unconditionally.
Expand Down
4 changes: 2 additions & 2 deletions src/solaris_illumos.rs
Expand Up @@ -22,7 +22,7 @@ use crate::{
util_libc::{sys_fill_exact, Weak},
Error,
};
use core::mem;
use core::mem::{self, MaybeUninit};

#[cfg(target_os = "illumos")]
type GetRandomFn = unsafe extern "C" fn(*mut u8, libc::size_t, libc::c_uint) -> libc::ssize_t;
Expand All @@ -38,7 +38,7 @@ pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
// derived platforms for atomically obtaining random data.
for chunk in dest.chunks_mut(256) {
sys_fill_exact(chunk, |buf| unsafe {
func(buf.as_mut_ptr(), buf.len(), 0) as libc::ssize_t
func(buf.as_mut_ptr() as *mut u8, buf.len(), 0) as libc::ssize_t
})?
}
Ok(())
Expand Down