Skip to content

Commit

Permalink
Fix Solaris/OpenBSD/Dragonfly build and re-enable CI (#301)
Browse files Browse the repository at this point in the history
Fixes #216 

This also adds two minor CI improvements:
  - Do a full link on `freebsd`
  - Build, Link, but don't run on `illumos`
  - Use the stable toolchain for our Tier 2 Build-only targets
  - Build (via `build-std`) for Tier 3 targets: `openbsd`, `dragonfly`, `haiku`

Signed-off-by: Joe Richey <joerichey@google.com>
  • Loading branch information
josephlr committed Oct 22, 2022
1 parent f7b7330 commit d2ca769
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
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;

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

0 comments on commit d2ca769

Please sign in to comment.