Skip to content

Commit b7bba16

Browse files
authored
CI: run Clippy for all backends, rework the rustdoc job (#477)
Consolidates Clippy runs into one job which uses fixed Nightly version. Moves Clippy, rustdoc, and rustfmt jobs into a separate workflow file. Additionally, tweaks the rustdoc job to use only rustdoc with `-Dwarnings` flag. Minimal versions job has nothing to do with docs and should be done separately for each target. `cargo deadlinks` was not used to check external links and internal links are checked by rustdoc.
1 parent 3174f0c commit b7bba16

File tree

7 files changed

+125
-60
lines changed

7 files changed

+125
-60
lines changed

.github/workflows/tests.yml

+14-50
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,6 @@ env:
1616
RUSTFLAGS: "-Dwarnings"
1717

1818
jobs:
19-
check-doc:
20-
name: Docs, deadlinks, minimal dependencies
21-
runs-on: ubuntu-22.04
22-
steps:
23-
- uses: actions/checkout@v3
24-
- uses: dtolnay/rust-toolchain@nightly # Needed for -Z minimal-versions and doc_cfg
25-
- name: Install precompiled cargo-deadlinks
26-
run: |
27-
VERSION=0.8.1
28-
URL="https://github.com/deadlinks/cargo-deadlinks/releases/download/${VERSION}/cargo-deadlinks-linux"
29-
wget -O ~/.cargo/bin/cargo-deadlinks $URL
30-
chmod +x ~/.cargo/bin/cargo-deadlinks
31-
cargo deadlinks --version
32-
- uses: Swatinem/rust-cache@v2
33-
- name: Generate Docs
34-
env:
35-
RUSTDOCFLAGS: --cfg docsrs
36-
run: cargo deadlinks -- --features=custom,std
37-
- run: |
38-
cargo generate-lockfile -Z minimal-versions
39-
cargo test --features=custom,std
40-
4119
main-tests:
4220
name: Tier 1 Test
4321
runs-on: ${{ matrix.os }}
@@ -54,7 +32,7 @@ jobs:
5432
- os: macos-14
5533
toolchain: stable
5634
steps:
57-
- uses: actions/checkout@v3
35+
- uses: actions/checkout@v4
5836
- uses: dtolnay/rust-toolchain@master
5937
with:
6038
toolchain: ${{ matrix.toolchain }}
@@ -80,7 +58,7 @@ jobs:
8058
# TODO: Find a Linux image/runner with CONFIG_X86_X32_ABI set
8159
cargo_test_opts: --no-run
8260
steps:
83-
- uses: actions/checkout@v3
61+
- uses: actions/checkout@v4
8462
- uses: dtolnay/rust-toolchain@stable
8563
with:
8664
targets: ${{ matrix.target }}
@@ -111,7 +89,7 @@ jobs:
11189
target: aarch64-apple-ios-sim
11290
ios_platform: auto-ios-aarch64-sim
11391
steps:
114-
- uses: actions/checkout@v3
92+
- uses: actions/checkout@v4
11593
- uses: dtolnay/rust-toolchain@stable
11694
with:
11795
targets: ${{ matrix.target }}
@@ -158,7 +136,7 @@ jobs:
158136
stable-i686-msvc,
159137
]
160138
steps:
161-
- uses: actions/checkout@v3
139+
- uses: actions/checkout@v4
162140
- uses: dtolnay/rust-toolchain@master
163141
with:
164142
toolchain: ${{ matrix.toolchain }}
@@ -169,7 +147,7 @@ jobs:
169147
name: Test Windows 7 impl on Windows 10
170148
runs-on: windows-2022
171149
steps:
172-
- uses: actions/checkout@v3
150+
- uses: actions/checkout@v4
173151
# Win7 targets are Tier3, so pin a nightly where libstd builds.
174152
- uses: dtolnay/rust-toolchain@master
175153
with:
@@ -193,7 +171,7 @@ jobs:
193171
wasm32-unknown-emscripten,
194172
]
195173
steps:
196-
- uses: actions/checkout@v3
174+
- uses: actions/checkout@v4
197175
- name: Install precompiled cross
198176
run: |
199177
VERSION=v0.2.5
@@ -207,7 +185,7 @@ jobs:
207185
name: macOS ARM64 Build/Link
208186
runs-on: macos-12
209187
steps:
210-
- uses: actions/checkout@v3
188+
- uses: actions/checkout@v4
211189
- uses: dtolnay/rust-toolchain@nightly
212190
with:
213191
targets: aarch64-apple-darwin, aarch64-apple-ios
@@ -229,7 +207,7 @@ jobs:
229207
x86_64-unknown-netbsd,
230208
]
231209
steps:
232-
- uses: actions/checkout@v3
210+
- uses: actions/checkout@v4
233211
- name: Install precompiled cross
234212
run: |
235213
VERSION=v0.2.5
@@ -256,7 +234,7 @@ jobs:
256234
host: x86_64-apple-darwin
257235
runs-on: ${{ matrix.os }}
258236
steps:
259-
- uses: actions/checkout@v3
237+
- uses: actions/checkout@v4
260238
- uses: dtolnay/rust-toolchain@stable
261239
- run: choco install wget
262240
if: runner.os == 'Windows'
@@ -287,7 +265,7 @@ jobs:
287265
name: wasm64 Build/Link
288266
runs-on: ubuntu-22.04
289267
steps:
290-
- uses: actions/checkout@v3
268+
- uses: actions/checkout@v4
291269
- uses: dtolnay/rust-toolchain@nightly # Need to build libstd
292270
with:
293271
components: rust-src
@@ -302,7 +280,7 @@ jobs:
302280
name: WASI Test
303281
runs-on: ubuntu-22.04
304282
steps:
305-
- uses: actions/checkout@v3
283+
- uses: actions/checkout@v4
306284
- uses: dtolnay/rust-toolchain@stable
307285
with:
308286
targets: wasm32-wasi
@@ -326,7 +304,7 @@ jobs:
326304
x86_64-fortanix-unknown-sgx,
327305
]
328306
steps:
329-
- uses: actions/checkout@v3
307+
- uses: actions/checkout@v4
330308
- uses: dtolnay/rust-toolchain@stable
331309
with:
332310
targets: ${{ matrix.target }}
@@ -368,7 +346,7 @@ jobs:
368346
- target: i686-unknown-hurd-gnu
369347
features: ["std"]
370348
steps:
371-
- uses: actions/checkout@v3
349+
- uses: actions/checkout@v4
372350
- uses: dtolnay/rust-toolchain@nightly # Required to build libcore
373351
with:
374352
components: rust-src
@@ -379,23 +357,9 @@ jobs:
379357
name: No Atomics Build
380358
runs-on: ubuntu-22.04
381359
steps:
382-
- uses: actions/checkout@v3
360+
- uses: actions/checkout@v4
383361
- uses: dtolnay/rust-toolchain@stable
384362
with:
385363
targets: riscv32i-unknown-none-elf
386364
- uses: Swatinem/rust-cache@v2
387365
- run: cargo build --features custom --target riscv32i-unknown-none-elf
388-
389-
clippy-fmt:
390-
name: Clippy + rustfmt
391-
runs-on: ubuntu-22.04
392-
steps:
393-
- uses: actions/checkout@v1
394-
- uses: dtolnay/rust-toolchain@stable
395-
with:
396-
components: rustfmt, clippy
397-
- uses: Swatinem/rust-cache@v2
398-
- name: clippy
399-
run: cargo clippy --all --features=custom,std
400-
- name: fmt
401-
run: cargo fmt --all -- --check

.github/workflows/workspace.yml

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Workspace
2+
3+
on:
4+
push:
5+
branches: master
6+
pull_request:
7+
branches: master
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
clippy:
14+
name: Clippy
15+
runs-on: ubuntu-latest
16+
env:
17+
RUSTFLAGS: "-Dwarnings"
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: dtolnay/rust-toolchain@master
21+
with:
22+
# We need Nightly for -Zbuild-std.
23+
# Fixed Nigthly version is used to prevent
24+
# CI failures which are not relevant to PR changes
25+
# on introduction of new Clippy lints.
26+
toolchain: nightly-2024-06-11
27+
components: clippy,rust-src
28+
- name: std feature
29+
run: cargo clippy --features std
30+
- name: custom feature
31+
run: cargo clippy -Zbuild-std=core --target riscv32i-unknown-none-elf --features custom
32+
- name: iOS (apple-other.rs)
33+
run: cargo clippy -Zbuild-std=core --target x86_64-apple-ios
34+
- name: ESP-IDF (espidf.rs)
35+
run: cargo clippy -Zbuild-std=core --target riscv32imc-esp-espidf
36+
- name: Fuchsia (fuchsia.rs)
37+
run: cargo clippy -Zbuild-std=core --target x86_64-unknown-fuchsia
38+
- name: OpenBSD (getentropy.rs)
39+
run: cargo clippy -Zbuild-std=core --target x86_64-unknown-openbsd
40+
- name: FreeBSD (getrandom.rs)
41+
run: cargo clippy -Zbuild-std=core --target x86_64-unknown-freebsd
42+
- name: Hermit (hermit.rs)
43+
run: cargo clippy -Zbuild-std=core --target x86_64-unknown-hermit
44+
- name: Web WASM (js.rs)
45+
run: cargo clippy -Zbuild-std --target wasm32-unknown-unknown --features js
46+
- name: Linux (linux_android.rs)
47+
run: cargo clippy --target x86_64-unknown-linux-gnu --features linux_disable_fallback
48+
- name: Linux (linux_android_with_fallback.rs)
49+
run: cargo clippy --target x86_64-unknown-linux-gnu
50+
- name: NetBSD (netbsd.rs)
51+
run: cargo clippy -Zbuild-std=core --target x86_64-unknown-netbsd
52+
- name: Fortranix SGX (rdrand.rs)
53+
run: cargo clippy -Zbuild-std=core --target x86_64-fortanix-unknown-sgx
54+
- name: Solaris (solaris.rs)
55+
run: cargo clippy -Zbuild-std=core --target x86_64-pc-solaris
56+
- name: SOLID (solid.rs)
57+
run: cargo clippy -Zbuild-std=core --target aarch64-kmc-solid_asp3
58+
- name: Redox (use_file.rs)
59+
run: cargo clippy -Zbuild-std=core --target x86_64-unknown-redox
60+
- name: VxWorks (vxworks.rs)
61+
run: cargo clippy -Zbuild-std=core --target x86_64-wrs-vxworks
62+
- name: WASI (wasi.rs)
63+
run: cargo clippy -Zbuild-std=core --target wasm32-wasip2
64+
- name: Windows 7 (windows7.rs)
65+
run: cargo clippy -Zbuild-std=core --target x86_64-win7-windows-msvc
66+
- name: Windows (windows.rs)
67+
run: cargo clippy -Zbuild-std=core --target x86_64-pc-windows-msvc
68+
69+
fmt:
70+
name: rustfmt
71+
runs-on: ubuntu-latest
72+
steps:
73+
- uses: actions/checkout@v4
74+
- uses: dtolnay/rust-toolchain@stable
75+
with:
76+
components: rustfmt
77+
- uses: Swatinem/rust-cache@v2
78+
- name: fmt
79+
run: cargo fmt --all -- --check
80+
81+
check-doc:
82+
name: rustdoc
83+
runs-on: ubuntu-latest
84+
steps:
85+
- uses: actions/checkout@v4
86+
- uses: dtolnay/rust-toolchain@master
87+
with:
88+
# We need Nightly for doc_auto_cfg
89+
toolchain: nightly-2024-06-11
90+
- uses: Swatinem/rust-cache@v2
91+
- name: Generate Docs
92+
env:
93+
RUSTDOCFLAGS: "-Dwarnings --cfg docsrs"
94+
run: cargo doc --no-deps --features custom

src/lazy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub(crate) struct LazyUsize(AtomicUsize);
2828

2929
impl LazyUsize {
3030
// The initialization is not completed.
31-
const UNINIT: usize = usize::max_value();
31+
const UNINIT: usize = usize::MAX;
3232

3333
pub const fn new() -> Self {
3434
Self(AtomicUsize::new(Self::UNINIT))

src/use_file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use core::{
1717
/// - On AIX, /dev/urandom will "provide cryptographically secure output".
1818
/// - On Haiku and QNX Neutrino they are identical.
1919
const FILE_PATH: &[u8] = b"/dev/urandom\0";
20-
const FD_UNINIT: usize = usize::max_value();
20+
const FD_UNINIT: usize = usize::MAX;
2121

2222
// Do not inline this when it is the fallback implementation, but don't mark it
2323
// `#[cold]` because it is hot when it is actually used.

src/vxworks.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Implementation for VxWorks
22
use crate::{util_libc::last_os_error, Error};
33
use core::{
4+
cmp::Ordering::{Equal, Greater, Less},
45
mem::MaybeUninit,
56
sync::atomic::{AtomicBool, Ordering::Relaxed},
67
};
@@ -9,17 +10,21 @@ pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
910
static RNG_INIT: AtomicBool = AtomicBool::new(false);
1011
while !RNG_INIT.load(Relaxed) {
1112
let ret = unsafe { libc::randSecure() };
12-
if ret < 0 {
13-
return Err(Error::VXWORKS_RAND_SECURE);
14-
} else if ret > 0 {
15-
RNG_INIT.store(true, Relaxed);
16-
break;
13+
match ret.cmp(&0) {
14+
Greater => {
15+
RNG_INIT.store(true, Relaxed);
16+
break;
17+
}
18+
Equal => unsafe {
19+
libc::usleep(10);
20+
},
21+
Less => return Err(Error::VXWORKS_RAND_SECURE),
1722
}
18-
unsafe { libc::usleep(10) };
1923
}
2024

2125
// Prevent overflow of i32
22-
for chunk in dest.chunks_mut(i32::max_value() as usize) {
26+
let chunk_size = usize::try_from(i32::MAX).expect("VxWorks does not support 16-bit targets");
27+
for chunk in dest.chunks_mut(chunk_size) {
2328
let ret = unsafe { libc::randABytes(chunk.as_mut_ptr().cast::<u8>(), chunk.len() as i32) };
2429
if ret != 0 {
2530
return Err(last_os_error());

src/windows.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
//! - Requires advapi32.dll (in addition to bcryptprimitives.dll)
1919
//! - Requires using name "SystemFunction036"
2020
//! - Thin wrapper around ProcessPrng
21+
//!
2122
//! For more information see the Windows RNG Whitepaper: https://aka.ms/win10rng
2223
use crate::Error;
2324
use core::mem::MaybeUninit;

src/windows7.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const TRUE: BOOLEAN = 1u8;
2525

2626
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
2727
// Prevent overflow of u32
28-
for chunk in dest.chunks_mut(u32::max_value() as usize) {
28+
let chunk_size = usize::try_from(i32::MAX).expect("Windows does not support 16-bit targets");
29+
for chunk in dest.chunks_mut(chunk_size) {
2930
let ret = unsafe { RtlGenRandom(chunk.as_mut_ptr().cast::<c_void>(), chunk.len() as u32) };
3031
if ret != TRUE {
3132
return Err(Error::WINDOWS_RTL_GEN_RANDOM);

0 commit comments

Comments
 (0)