From 7d87451333c976512a8ae90b48f555edab95b569 Mon Sep 17 00:00:00 2001 From: morenol <22335041+morenol@users.noreply.github.com> Date: Tue, 8 Nov 2022 11:07:14 -0500 Subject: [PATCH] Fixes for release (#237) * Fixes for release * add new test * Remove change applied in development branch * Only add dependency for wasm32 * Update ci.yml Co-authored-by: Luis Moreno Co-authored-by: Lorenzo --- .github/workflows/ci.yml | 7 ++++++- Cargo.toml | 3 +-- src/rand_custom.rs | 14 +++++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2cd825..89b3b37 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,11 +46,16 @@ jobs: - name: Install test runner for wasi if: matrix.platform.target == 'wasm32-wasi' run: curl https://wasmtime.dev/install.sh -sSf | bash - - name: Stable Build + - name: Stable Build with all features uses: actions-rs/cargo@v1 with: command: build args: --all-features --target ${{ matrix.platform.target }} + - name: Stable Build without features + uses: actions-rs/cargo@v1 + with: + command: build + args: --target ${{ matrix.platform.target }} - name: Tests if: matrix.platform.target == 'x86_64-unknown-linux-gnu' || matrix.platform.target == 'x86_64-pc-windows-msvc' || matrix.platform.target == 'aarch64-apple-darwin' uses: actions-rs/cargo@v1 diff --git a/Cargo.toml b/Cargo.toml index 42faefa..63c9389 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,6 @@ ndarray = { version = "0.15", optional = true } num-traits = "0.2.12" num = "0.4" rand = { version = "0.8.5", default-features = false, features = ["small_rng"] } -getrandom = "*" rand_distr = { version = "0.4", optional = true } serde = { version = "1", features = ["derive"], optional = true } @@ -40,7 +39,7 @@ std_rand = ["rand/std_rng", "rand/std"] js = ["getrandom/js"] [target.'cfg(target_arch = "wasm32")'.dependencies] -getrandom = { version = "*", features = ["js"] } +getrandom = { version = "*", optional = true } [target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dev-dependencies] wasm-bindgen-test = "0.3" diff --git a/src/rand_custom.rs b/src/rand_custom.rs index b22390e..936ec9e 100644 --- a/src/rand_custom.rs +++ b/src/rand_custom.rs @@ -15,9 +15,17 @@ pub fn get_rng_impl(seed: Option) -> RngImpl { RngImpl::seed_from_u64(rand::thread_rng().next_u64()) } else { // no std_random feature build, use getrandom - let mut buf = [0u8; 64]; - getrandom::getrandom(&mut buf).unwrap(); - RngImpl::seed_from_u64(buf[0] as u64) + #[cfg(feature = "js")] + { + let mut buf = [0u8; 64]; + getrandom::getrandom(&mut buf).unwrap(); + RngImpl::seed_from_u64(buf[0] as u64) + } + #[cfg(not(feature = "js"))] + { + // Using 0 as default seed + RngImpl::seed_from_u64(0) + } } } }