Skip to content
Closed
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
44 changes: 22 additions & 22 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ jobs:
targets: aarch64-apple-darwin, aarch64-apple-ios
components: rust-src
- uses: Swatinem/rust-cache@v2
- run: cargo test --no-run --target=aarch64-apple-darwin --features=std
- run: cargo test --no-run --target=aarch64-apple-ios --features=std
- run: cargo test --no-run --target=aarch64-apple-tvos -Zbuild-std --features=std
- run: cargo test --no-run --target=aarch64-apple-watchos -Zbuild-std --features=std
- run: cargo test --no-run --target=aarch64-apple-darwin --features=std,default-backends
- run: cargo test --no-run --target=aarch64-apple-ios --features=std,default-backends
- run: cargo test --no-run --target=aarch64-apple-tvos -Zbuild-std --features=std,default-backends
- run: cargo test --no-run --target=aarch64-apple-watchos -Zbuild-std --features=std,default-backends
# visionOS requires Xcode 15.2+, GitHub Actions defaults to an older version.
- run: sudo xcode-select -switch /Applications/Xcode_15.2.app
# std is broken on visionOS right now
#- run: cargo test --no-run --target=aarch64-apple-visionos -Zbuild-std --features=std
#- run: cargo test --no-run --target=aarch64-apple-visionos -Zbuild-std --features=std,default-backends

cross:
name: Cross
Expand All @@ -56,7 +56,7 @@ jobs:
wget -O - $URL | tar -xz -C ~/.cargo/bin
cross --version
- name: Build Tests
run: cross test --no-run --target=${{ matrix.target }} --features=std
run: cross test --no-run --target=${{ matrix.target }} --features=std,default-backends

tier2:
name: Tier 2
Expand All @@ -76,7 +76,7 @@ jobs:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build --target=${{ matrix.target }} --features=std
run: cargo build --target=${{ matrix.target }} --features=std,default-backends

tier3:
name: Tier 3
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
with:
components: rust-src
- uses: Swatinem/rust-cache@v2
- run: cargo build -Z build-std=core --target=${{ matrix.target }}
- run: cargo build -Z build-std=core --target=${{ matrix.target }} --features default-backends

# Ubuntu does not support running x32 binaries:
# https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1994516/comments/21
Expand All @@ -125,16 +125,16 @@ jobs:
sudo apt-get update
sudo apt-get install --no-install-recommends libc6-dev-x32 libx32gcc-11-dev
- uses: Swatinem/rust-cache@v2
- run: cargo build --target=${{ matrix.target }} --features=std
- run: cargo build --target=${{ matrix.target }} --features=std,default-backends
- env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="linux_getrandom"
run: cargo build --target=${{ matrix.target }} --features=std
run: cargo build --target=${{ matrix.target }} --features=std,default-backends
- env:
RUSTFLAGS: -Dwarnings --cfg getrandom_test_linux_fallback
run: cargo build --features=std
run: cargo build --features=std,default-backends
- env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="rdrand"
run: cargo build --features=std
run: cargo build --features=std,default-backends

linux-raw:
name: Build Raw Linux
Expand All @@ -160,7 +160,7 @@ jobs:
components: rust-src
- env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="linux_raw"
run: cargo build -Zbuild-std=core --target=${{ matrix.target }}
run: cargo build -Zbuild-std=core --target=${{ matrix.target }} --features default-backends

web:
name: ${{ matrix.target.description }} ${{ matrix.feature.description }} ${{ matrix.atomic.description }}
Expand Down Expand Up @@ -194,7 +194,7 @@ jobs:
components: rust-src
- uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build --target ${{ matrix.target.target }} ${{ matrix.feature.feature }} -Zbuild-std=${{ matrix.feature.build-std }}
run: cargo build --target ${{ matrix.target.target }} ${{ matrix.feature.feature }} -Zbuild-std=${{ matrix.feature.build-std }} --features default-backends

efi-rng:
name: UEFI RNG Protocol
Expand All @@ -214,7 +214,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
- env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="efi_rng"
run: cargo build -Z build-std=std --target=${{ matrix.target }} --features std
run: cargo build -Z build-std=std --target=${{ matrix.target }} --features std,default-backends

rdrand-uefi:
name: RDRAND UEFI
Expand All @@ -233,10 +233,10 @@ jobs:
- uses: Swatinem/rust-cache@v2
- env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="rdrand"
run: cargo build -Z build-std=core --target=${{ matrix.target }}
run: cargo build -Z build-std=core --target=${{ matrix.target }} --features default-backends
- env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="rdrand"
run: cargo build -Z build-std=std --target=${{ matrix.target }} --features std
run: cargo build -Z build-std=std --target=${{ matrix.target }} --features std,default-backends

rndr:
name: RNDR
Expand All @@ -251,15 +251,15 @@ jobs:
- name: RNDR enabled at compile time (Linux)
env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="rndr" -C target-feature=+rand
run: cargo build --target=aarch64-unknown-linux-gnu
run: cargo build --target=aarch64-unknown-linux-gnu --features default-backends
- name: Runtime RNDR detection without std (Linux)
env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="rndr"
run: cargo build --target=aarch64-unknown-linux-gnu
run: cargo build --target=aarch64-unknown-linux-gnu --features default-backends
- name: Runtime RNDR detection with std (macOS)
env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="rndr"
run: cargo build --target=aarch64-unknown-linux-gnu --features std
run: cargo build --target=aarch64-unknown-linux-gnu --features std,default-backends

no-atomics:
name: No Atomics
Expand All @@ -272,7 +272,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
- env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="custom"
run: cargo build --target riscv32i-unknown-none-elf
run: cargo build --target riscv32i-unknown-none-elf --features default-backends

unsupported:
name: Runtime error
Expand All @@ -285,4 +285,4 @@ jobs:
- uses: Swatinem/rust-cache@v2
- env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="unsupported"
run: cargo build --target wasm32-unknown-unknown
run: cargo build --target wasm32-unknown-unknown --features default-backends
46 changes: 23 additions & 23 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ jobs:
with:
toolchain: ${{ matrix.toolchain }}
- uses: Swatinem/rust-cache@v2
- run: cargo test
- run: cargo test --features default-backends
# Make sure enabling the std feature doesn't break anything
- run: cargo test --features=std
- run: cargo test --features=std,default-backends
- if: ${{ matrix.toolchain == 'nightly' }}
run: cargo test --benches
run: cargo test --benches --features default-backends

linux:
name: Linux
Expand All @@ -53,27 +53,27 @@ jobs:
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- run: cargo test --target=${{ matrix.target }} --features=std
- run: cargo test --target=${{ matrix.target }} --features=std,default-backends
- env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="linux_getrandom"
RUSTDOCFLAGS: -Dwarnings --cfg getrandom_backend="linux_getrandom"
run: cargo test --target=${{ matrix.target }} --features=std
run: cargo test --target=${{ matrix.target }} --features=std,default-backends
- env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="linux_raw"
RUSTDOCFLAGS: -Dwarnings --cfg getrandom_backend="linux_raw"
run: cargo test --target=${{ matrix.target }} --features=std
run: cargo test --target=${{ matrix.target }} --features=std,default-backends
- env:
RUSTFLAGS: -Dwarnings --cfg getrandom_test_linux_fallback
RUSTDOCFLAGS: -Dwarnings --cfg getrandom_test_linux_fallback
run: cargo test --features=std
run: cargo test --features=std,default-backends
- env:
RUSTFLAGS: -Dwarnings --cfg getrandom_test_linux_without_fallback
RUSTDOCFLAGS: -Dwarnings --cfg getrandom_test_linux_without_fallback
run: cargo test --features=std
run: cargo test --features=std,default-backends
- env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="rdrand"
RUSTDOCFLAGS: -Dwarnings --cfg getrandom_backend="rdrand"
run: cargo test --features=std
run: cargo test --features=std,default-backends

ios:
name: iOS Simulator
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
echo "device=$SIM_ID" >> $GITHUB_ENV
- uses: Swatinem/rust-cache@v2
- name: Run tests
run: cargo dinghy -p auto-ios-aarch64-sim -d ${{ env.device }} test
run: cargo dinghy -p auto-ios-aarch64-sim -d ${{ env.device }} test --features default-backends

windows:
name: Windows
Expand All @@ -123,7 +123,7 @@ jobs:
with:
toolchain: ${{ matrix.toolchain }}
- uses: Swatinem/rust-cache@v2
- run: cargo test --features=std
- run: cargo test --features=std,default-backends

windows7:
name: Windows 7 (on Windows 10)
Expand All @@ -136,8 +136,8 @@ jobs:
toolchain: nightly-2024-05-20
components: rust-src
- uses: Swatinem/rust-cache@v2
- run: cargo test --target=x86_64-win7-windows-msvc -Z build-std --features=std
- run: cargo test --target=i686-win7-windows-msvc -Z build-std --features=std
- run: cargo test --target=x86_64-win7-windows-msvc -Z build-std --features=std,default-backends
- run: cargo test --target=i686-win7-windows-msvc -Z build-std --features=std,default-backends

sanitizer:
name: Sanitizer
Expand All @@ -151,7 +151,7 @@ jobs:
- env:
RUSTFLAGS: -Dwarnings -Zsanitizer=memory
RUSTDOCFLAGS: -Dwarnings -Zsanitizer=memory
run: cargo test -Zbuild-std --target=x86_64-unknown-linux-gnu
run: cargo test -Zbuild-std --target=x86_64-unknown-linux-gnu --features default-backends

cross:
name: Cross
Expand Down Expand Up @@ -180,7 +180,7 @@ jobs:
wget -O - $URL | tar -xz -C ~/.cargo/bin
cross --version
- name: Test
run: cross test --no-fail-fast --target=${{ matrix.target }} --features=std
run: cross test --no-fail-fast --target=${{ matrix.target }} --features=std,default-backends

freebsd:
name: FreeBSD VM
Expand All @@ -194,7 +194,7 @@ jobs:
usesh: true
prepare: |
pkg install -y rust
run: cargo test
run: cargo test --features default-backends

openbsd:
name: OpenBSD VM
Expand All @@ -208,7 +208,7 @@ jobs:
usesh: true
prepare: |
pkg_add rust
run: cargo test
run: cargo test --features default-backends

netbsd:
name: NetBSD VM
Expand All @@ -223,8 +223,8 @@ jobs:
prepare: |
/usr/sbin/pkg_add rust
run: |
cargo test
RUSTFLAGS="--cfg getrandom_test_netbsd_fallback -D warnings" cargo test
cargo test --features default-backends
RUSTFLAGS="--cfg getrandom_test_netbsd_fallback -D warnings" cargo test --features default-backends

web:
name: ${{ matrix.rust.description }}
Expand All @@ -237,14 +237,14 @@ jobs:
description: Web,
version: stable,
flags: '-Dwarnings --cfg getrandom_backend="wasm_js"',
args: '--features=std,wasm_js',
args: '--features=std,wasm_js,default-backends',
}
- {
description: Web with Atomics,
version: nightly,
components: rust-src,
flags: '-Dwarnings --cfg getrandom_backend="wasm_js" -Ctarget-feature=+atomics,+bulk-memory',
args: '--features=std,wasm_js -Zbuild-std=panic_abort,std',
args: '--features=std,wasm_js,default-backends -Zbuild-std=panic_abort,std',
}
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -314,6 +314,6 @@ jobs:
wasmtime --version
- uses: Swatinem/rust-cache@v2
- name: WASI 0.1 Test
run: cargo test --target wasm32-wasip1
run: cargo test --target wasm32-wasip1 --features default-backends
- name: WASI 0.2 Test
run: cargo test --target wasm32-wasip2
run: cargo test --target wasm32-wasip2 --features default-backends
2 changes: 1 addition & 1 deletion Cargo.lock

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

26 changes: 14 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "getrandom"
version = "0.3.3"
version = "0.4.0"
edition = "2021"
rust-version = "1.63" # Sync tests.yml and README.md.
authors = ["The Rand Project Developers"]
Expand All @@ -18,12 +18,14 @@ std = []
# Unstable feature to support being a libstd dependency
rustc-dep-of-std = ["dep:compiler_builtins", "dep:core"]

# Provides a default implementations of the backend for many supported targets.
default-backends = ["dep:libc", "dep:r-efi", "dep:wasi"]
# Optional backend: wasm_js
# This flag enables the backend but does not select it. To use the backend, use
# this flag *and* set getrandom_backend=wasm_js (see README).
# WARNING: It is highly recommended to enable this feature only for binary crates and tests,
# i.e. avoid unconditionally enabling it in library crates.
wasm_js = ["dep:wasm-bindgen", "dep:js-sys"]
wasm_js = ["dep:wasm-bindgen", "dep:js-sys", "default-backends"]

[dependencies]
cfg-if = "1"
Expand All @@ -34,43 +36,43 @@ core = { version = "1.0", optional = true, package = "rustc-std-workspace-core"

# getrandom / linux_android_with_fallback
[target.'cfg(all(any(target_os = "linux", target_os = "android"), not(any(all(target_os = "linux", target_env = ""), getrandom_backend = "custom", getrandom_backend = "linux_raw", getrandom_backend = "rdrand", getrandom_backend = "rndr"))))'.dependencies]
libc = { version = "0.2.154", default-features = false }
libc = { version = "0.2.154", default-features = false, optional = true }

# apple-other
[target.'cfg(any(target_os = "ios", target_os = "visionos", target_os = "watchos", target_os = "tvos"))'.dependencies]
libc = { version = "0.2.154", default-features = false }
libc = { version = "0.2.154", default-features = false, optional = true }

# efi_rng
[target.'cfg(all(target_os = "uefi", getrandom_backend = "efi_rng"))'.dependencies]
r-efi = { version = "5.1", default-features = false }
r-efi = { version = "5.1", default-features = false, optional = true }

# getentropy
[target.'cfg(any(target_os = "macos", target_os = "openbsd", target_os = "vita", target_os = "emscripten"))'.dependencies]
libc = { version = "0.2.154", default-features = false }
libc = { version = "0.2.154", default-features = false, optional = true }

# getrandom
[target.'cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "hurd", target_os = "illumos", target_os = "cygwin", all(target_os = "horizon", target_arch = "arm")))'.dependencies]
libc = { version = "0.2.154", default-features = false }
libc = { version = "0.2.154", default-features = false, optional = true }

# netbsd
[target.'cfg(target_os = "netbsd")'.dependencies]
libc = { version = "0.2.154", default-features = false }
libc = { version = "0.2.154", default-features = false, optional = true }

# solaris
[target.'cfg(target_os = "solaris")'.dependencies]
libc = { version = "0.2.154", default-features = false }
libc = { version = "0.2.154", default-features = false, optional = true }

# use_file
[target.'cfg(any(target_os = "haiku", target_os = "redox", target_os = "nto", target_os = "aix"))'.dependencies]
libc = { version = "0.2.154", default-features = false }
libc = { version = "0.2.154", default-features = false, optional = true }

# vxworks
[target.'cfg(target_os = "vxworks")'.dependencies]
libc = { version = "0.2.154", default-features = false }
libc = { version = "0.2.154", default-features = false, optional = true }

# wasi (0.2 only)
[target.'cfg(all(target_arch = "wasm32", target_os = "wasi", target_env = "p2"))'.dependencies]
wasi = { version = "0.14", default-features = false }
wasi = { version = "0.14", default-features = false, optional = true }

# wasm_js
[target.'cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion nopanic_check/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ name = "getrandom_wrapper"
crate-type = ["cdylib"]

[dependencies]
getrandom = { path = ".." }
getrandom = { path = "..", features = ["default-backends"]}

[profile.release]
panic = "abort"
Expand Down
Loading
Loading