about summary refs log tree commit diff
path: root/library/std/src/sys/random
AgeCommit message (Collapse)AuthorLines
2025-09-24std: add support for armv7a-vex-v5 targetTropical-0/+2
Co-authored-by: Lewis McClelland <lewis@lewismcclelland.me>
2025-08-28std: Start supporting WASIp2 nativelyAlex Crichton-3/+17
This commit is the start of an effort to support WASIp2 natively in the standard library. Before this commit the `wasm32-wasip2` target behaved exactly like `wasm32-wasip1` target by importing APIs from the core wasm module `wasi_snapshot_preview1`. These APIs are satisfied by the `wasm-component-ld` target by using an [adapter] which implements WASIp1 in terms of WASIp2. This adapter comes at a cost, however, in terms of runtime indirection and instantiation cost, so ideally the adapter would be removed entirely. The purpose of this adapter was to provide a smoother on-ramp from WASIp1 to WASIp2 when it was originally created. The `wasm32-wasip2` target has been around for long enough now that it's much more established. Additionally the only thing historically blocking using WASIp2 directly was implementation effort. Work is now underway to migrate wasi-libc itself to using WASIp2 directly and now seems as good a time as any to migrate the Rust standard library too. Implementation-wise the milestones here are: * The `wasm32-wasip2` target now also depends on the `wasi` crate at version 0.14.* in addition to the preexisting dependency of 0.11.*. The 0.14.* release series binds WASIp2 APIs instead of WASIp1 APIs. * Some preexisting naming around `mod wasi` or `wasi.rs` was renamed to `wasip1` where appropriate. For example `std::sys::pal::wasi` is now called `std::sys::pal::wasip1`. * More platform-specific WASI modules are now split between WASIp1 and WASIp2. For example getting the current time, randomness, and process arguments now use WASIp2 APIs directly instead of using WASIp1 APIs that require an adapter. It's worth pointing out that this PR does not migrate the entire standard library away from using WASIp1 APIs on the `wasm32-wasip2` target. Everything related to file descriptors and filesystem APIs is still using WASIp1. Migrating that is left for a future PR. In the meantime the goal of this change is to lay the groundwork necessary for migrating in the future. Eventually the goal is to drop the `wasi` 0.11.* dependency on the `wasm32-wasip2` target (the `wasm32-wasip1` target will continue to retain this dependency). [adapter]: https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasi-preview1-component-adapter/README.md
2025-08-16library: Migrate from `cfg_if` to `cfg_select`Josh Triplett-27/+48
Migrate the standard library from using the external `cfg_if` crate to using the now-built-in `cfg_select` macro. This does not yet eliminate the dependency from `library/std/Cargo.toml`, because while the standard library itself no longer uses `cfg_if`, it also incorporates the `backtrace` crate, which does. Migration assisted by the following vim command (after selecting the full `cfg_if!` invocation): ``` '<,'>s/\(cfg_if::\)\?cfg_if/cfg_select/ | '<,'>s/^\( *\)} else {/\1}\r\1_ => {/c | '<,'>s/^\( *\)} else if #\[cfg(\(.*\))\] /\1}\r\1\2 => /e | '<,'>s/if #\[cfg(\(.*\))\] {/\1 => {/e ``` This is imperfect, but substantially accelerated the process. This prompts for confirmation on the `} else {` since that can also appear inside one of the arms. This also requires manual intervention to handle any multi-line conditions.
2025-07-27Remove `[T]::array_chunks(_mut)`Scott McMurray-10/+9
2025-07-13Rollup merge of #143776 - no1wudi:fix, r=tgross35León Orell Valerian Liehr-1/+1
std: move NuttX to use arc4random for random number generation arc4random support in libc merged in https://github.com/rust-lang/libc/pull/4464, so: * Move `target_os = "nuttx"` from unix_legacy to arc4random section * This aligns NuttX with other POSIX-compliant systems that support arc4random * Improves random number generation quality on NuttX by using the system's built-in arc4random implementation instead of legacy fallback methods NuttX supports arc4random_buf which provides better entropy and security compared to the legacy random number generation methods.
2025-07-11std: move NuttX to use arc4random for random number generationHuang Qi-1/+1
* Move `target_os = "nuttx"` from unix_legacy to arc4random section * This aligns NuttX with other POSIX-compliant systems that support arc4random * Improves random number generation quality on NuttX by using the system's built-in arc4random implementation instead of legacy fallback methods NuttX supports arc4random_buf which provides better entropy and security compared to the legacy random number generation methods. Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2025-07-03setup CI and tidy to use typos for spellchecking and fix few typosklensy-3/+3
2025-06-06std: sys: random: uefi: Provide rdrand based fallbackAyush Singh-19/+150
Some UEFI systems based on American Megatrends Inc. v3.3 do not provide RNG support [1]. So fallback to rdrand in such cases. [1]: https://github.com/rust-lang/rust/issues/138252#issuecomment-2891270323 Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-04-27use generic Atomic type where possibleChristopher Durham-6/+6
in core/alloc/std only for now, and ignoring test files Co-authored-by: Pavel Grigorenko <GrigorenkoPV@ya.ru>
2025-03-26Change the syntax of the internal `weak!` macroMads Marquart-4/+4
Change the syntax to include parameter names and a trailing semicolon. Motivation: - Mirror the `syscall!` macro. - Allow rustfmt to format it (when wrapped in parentheses). - For better documentation (having the parameter names available in the source code is a bit nicer). - Allow future improvements to this macro where we can sometimes use the symbol directly when it's statically known to be available.
2025-03-19Fix build failure on TrustyTaiki Endo-1/+1
2025-03-17Rollup merge of #137621 - Berrysoft:cygwin-std, r=joboetJacob Pratt-4/+4
Add std support to cygwin target
2025-03-10Apply rustc-0023-Add-Trusty-OS-support-to-Rust-std.patchNicole LeGare-0/+10
2025-03-10Unify cygwin & horizon random impl王宇逸-15/+4
2025-03-10Impl cygwin rand with getrandom王宇逸-11/+13
2025-03-10Fix code style王宇逸-2/+6
2025-03-10Fix building for cygwin王宇逸-2/+7
2025-02-19Fix `*-win7-windows-msvc` target since 26eeac1a1e9fe46ffd80dd0d3dafdd2c2a644306Li Keqing-1/+1
2025-02-09Mark extern blocks as unsafeMichael Goulet-4/+4
2024-11-21Use arc4random of libc for RTEMS targetJan Sommer-2/+0
Is available since libc 0.2.162
2024-10-25library: consistently use American spelling for 'behavior'Ralf Jung-2/+2
2024-10-22AIX use /dev/urandom for implHenry Jiang-0/+1
2024-10-18Add entropy source for RTEMSJan Sommer-0/+3
2024-09-24Initial std library support for NuttXHuang Qi-0/+1
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2024-09-23std: switch to faster random sources on macOS and most BSDsjoboet-86/+75
2024-09-23std: implement the `random` featurejoboet-0/+605
Implements the ACP https://github.com/rust-lang/libs-team/issues/393.