Skip to content

Commit

Permalink
Merge pull request #12 from rust-random/work
Browse files Browse the repository at this point in the history
Update CI
  • Loading branch information
dhardy authored Nov 26, 2024
2 parents d922191 + 512fb46 commit ed3ad1a
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 54 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: "cargo"
directory: "/"
schedule:
interval: "monthly"
open-pull-requests-limit: 10
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
98 changes: 73 additions & 25 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,42 @@ name: Tests

on:
push:
branches: [ master ]
branches: [ master, '0.[0-9]+' ]
pull_request:
branches: [ master ]
branches: [ master, '0.[0-9]+' ]

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
check-doc:
name: Check doc, clippy, fmt
runs-on: ubuntu-latest
env:
RUSTDOCFLAGS: "-Dwarnings --cfg docsrs -Zunstable-options --generate-link-to-definition"
steps:
- uses: actions/checkout@v4
- name: Install toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
components: clippy, rustfmt
- name: Doc build
run: cargo doc --all-features --no-deps
- name: Clippy
run: cargo clippy --workspace --all-targets -- -D warnings
- name: rustfmt
run: cargo fmt -- --check

test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
toolchain: stable
- os: macos-latest
target: x86_64-apple-darwin
toolchain: stable
Expand All @@ -26,7 +51,8 @@ jobs:
# Test both windows-gnu and windows-msvc; use beta rust on one
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
toolchain: 1.36.0 # MSRV
variant: MSRV
toolchain: 1.63.0
- os: ubuntu-latest
deps: sudo apt-get update ; sudo apt install gcc-multilib
target: i686-unknown-linux-gnu
Expand All @@ -37,23 +63,23 @@ jobs:
variant: minimal_versions

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: MSRV
if: ${{ matrix.variant == 'MSRV' }}
run: cp Cargo.lock.msrv Cargo.lock
- name: Install toolchain
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@master
with:
profile: minimal
target: ${{ matrix.target }}
toolchain: ${{ matrix.toolchain }}
override: true
- run: ${{ matrix.deps }}
- name: Maybe minimal versions
if: ${{ matrix.variant == 'minimal_versions' }}
run: cargo generate-lockfile -Z minimal-versions
- name: Test nightly
if: ${{ matrix.toolchain == 'nightly' }}
run: cargo test --target ${{ matrix.target }} --benches
run: |
cargo generate-lockfile -Z minimal-versions
- name: Test
run: cargo test
run: |
cargo test --no-fail-fast --target ${{ matrix.target }}
test-cross:
runs-on: ${{ matrix.os }}
Expand All @@ -62,36 +88,58 @@ jobs:
matrix:
include:
- os: ubuntu-latest
target: mips-unknown-linux-gnu
target: powerpc-unknown-linux-gnu
toolchain: stable

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Install toolchain
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@master
with:
profile: minimal
target: ${{ matrix.target }}
toolchain: ${{ matrix.toolchain }}
override: true
- name: Cache cargo plugins
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ~/.cargo/bin/
key: ${{ runner.os }}-cargo-plugins
- name: Install cross
run: cargo install cross || true
- name: Test
run: cross test --no-fail-fast --target ${{ matrix.target }}
run: |
cross test --no-fail-fast
test-miri:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Install toolchain
run: |
MIRI_NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri)
rustup default "$MIRI_NIGHTLY"
rustup component add miri
- name: Test
run: cargo miri test
rustup toolchain install nightly --component miri
rustup override set nightly
cargo miri setup
- name: Test rand
run: |
cargo miri test
test-no-std:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install toolchain
uses: dtolnay/rust-toolchain@nightly
with:
target: thumbv6m-none-eabi
- name: Build top-level only
run: cargo build --target=thumbv6m-none-eabi --no-default-features

test-ios:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Install toolchain
uses: dtolnay/rust-toolchain@nightly
with:
target: aarch64-apple-ios
- name: Build top-level only
run: cargo build --target=aarch64-apple-ios
16 changes: 16 additions & 0 deletions Cargo.lock.msrv

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ A universal random number seeder based on SipHash.
"""
keywords = ["random", "rng", "seeder"]
categories = ["algorithms", "no-std"]
edition = "2021"
rust-version = "1.63"

[dependencies]
rand_core = { version = "0.6", default-features = false }

[lints.clippy]
unit_arg = "allow"
println_empty_string = "allow"
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[![Build Status](https://travis-ci.org/rust-random/seeder.svg)](https://travis-ci.org/rust-random/seeder)
[![Latest version](https://img.shields.io/crates/v/rand_seeder.svg)](https://crates.io/crates/rand_seeder)
[![Documentation](https://docs.rs/rand_seeder/badge.svg)](https://docs.rs/rand_seeder)
[![Minimum rustc version](https://img.shields.io/badge/rustc-1.32+-yellow.svg)](https://github.com/rust-random/seeder#rust-version-requirements)
[![License](https://img.shields.io/crates/l/rand_seeder.svg)](https://github.com/rust-random/seeder#license)

A universal seeder based on [SipHash].
Expand Down Expand Up @@ -44,11 +43,6 @@ println!("First value: {}", rng.next_u32());
[rand]: https://github.com/rust-random/rand
[`rand_core::SeedableRng`]: https://rust-random.github.io/rand/rand_core/trait.SeedableRng.html

## Rust version requirements

Requires rustc 1.32 or greater for the `.to_le_bytes()` method and for
`rand_core` 0.5 compatibility.

# License

`rand_seeder` is distributed under the terms of both the MIT license and the
Expand Down
2 changes: 1 addition & 1 deletion examples/seedrng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn main() {
match arg.as_str() {
"-h" => return print_usage(),
"-s" => output = Output::Stream,
o @ _ => {
o => {
eprintln!("Error: unrecognised option {}", o);
return;
}
Expand Down
46 changes: 24 additions & 22 deletions src/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,25 @@ macro_rules! load_int_le {
/// Unsafe because: unchecked indexing at start..start+len
#[inline]
unsafe fn u8to64_le(buf: &[u8], start: usize, len: usize) -> u64 {
debug_assert!(len < 8);
let mut i = 0; // current byte index (from LSB) in the output u64
let mut out = 0;
if i + 3 < len {
out = load_int_le!(buf, start + i, u32) as u64;
i += 4;
}
if i + 1 < len {
out |= (load_int_le!(buf, start + i, u16) as u64) << (i * 8);
i += 2
}
if i < len {
out |= (*buf.as_ptr().add(start + i) as u64) << (i * 8);
i += 1;
}
debug_assert_eq!(i, len);
out
unsafe {
debug_assert!(len < 8);
let mut i = 0; // current byte index (from LSB) in the output u64
let mut out = 0;
if i + 3 < len {
out = load_int_le!(buf, start + i, u32) as u64;
i += 4;
}
if i + 1 < len {
out |= (load_int_le!(buf, start + i, u16) as u64) << (i * 8);
i += 2
}
if i < len {
out |= (*buf.as_ptr().add(start + i) as u64) << (i * 8);
i += 1;
}
debug_assert_eq!(i, len);
out
}
}

impl SipHasher {
Expand Down Expand Up @@ -392,7 +394,7 @@ impl<S: Sip> hash::Hasher for Hasher<S> {

if self.ntail != 0 {
needed = 8 - self.ntail;
self.tail |= unsafe { u8to64_le(msg, 0, cmp::min(length, needed)) } << 8 * self.ntail;
self.tail |= unsafe { u8to64_le(msg, 0, cmp::min(length, needed)) } << (8 * self.ntail);
if length < needed {
self.ntail += length;
return;
Expand Down Expand Up @@ -565,8 +567,8 @@ mod test {
// for _ in 0..8 {
// println!("0x{:x}, 0x{:x},", rng.next_u64(), rng.next_u64());
// }
for i in 0..16 {
assert_eq!(rng.next_u64(), vector[i]);
for x in &vector {
assert_eq!(rng.next_u64(), *x);
}

// set seed to 0, 1, 2, ..., 31
Expand All @@ -593,8 +595,8 @@ mod test {
0x62cbac703609d15,
0x74aec28d9fdd44bf,
];
for i in 0..16 {
assert_eq!(rng.next_u64(), vector[i]);
for x in &vector {
assert_eq!(rng.next_u64(), *x);
}
}
}

0 comments on commit ed3ad1a

Please sign in to comment.