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

ci: add no-panic check for the custom backend #517

Merged
merged 1 commit into from
Oct 14, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/nopanic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ jobs:
- name: Check (rdrand.rs)
run: ret=$(grep panic target/release/libgetrandom_wrapper.so; echo $?); [ $ret -eq 1 ]

- name: Build (custom.rs)
env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="custom"
run: cargo build --release
- name: Check (custom.rs)
run: ret=$(grep panic target/release/libgetrandom_wrapper.so; echo $?); [ $ret -eq 1 ]

- name: Build (wasi.rs, preview 1)
run: cargo build --release --target wasm32-wasip1
- name: Check (wasi.rs, preview 1)
Expand Down
6 changes: 6 additions & 0 deletions nopanic_check/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ getrandom = { path = ".." }

[profile.release]
panic = "abort"

[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = [
'cfg(getrandom_backend, values("custom"))',
]
12 changes: 12 additions & 0 deletions nopanic_check/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ pub extern "C" fn getrandom_wrapper(buf_ptr: *mut u8, buf_len: usize) -> u32 {
let res = getrandom::getrandom_uninit(buf).map(|_| ());
unsafe { core::mem::transmute(res) }
}

#[cfg(getrandom_backend = "custom")]
#[no_mangle]
unsafe extern "Rust" fn __getrandom_custom(
dest: *mut u8,
len: usize,
) -> Result<(), getrandom::Error> {
for i in 0..len {
core::ptr::write(dest.add(i), i as u8);
}
Ok(())
}
Loading