about summary refs log tree commit diff
path: root/library/std/src/sys/args
AgeCommit message (Collapse)AuthorLines
2025-09-17Auto merge of #139849 - thaliaarchi:args/zkvm, r=ibraheemdevbors-45/+58
Fix `env::ArgsOs` for zkVM The zkVM implementation of `env::ArgsOs` incorrectly reports the full length even after having iterated. Instead, use a range approach which works out to be simpler. Also, implement more iterator methods like the other platforms in #139847. cc `@flaub` `@jbruestle` `@SchmErik`
2025-08-28std: Start supporting WASIp2 nativelyAlex Crichton-3/+13
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-10/+17
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-08-02Change visibility of Args new functionChristopher Hotchkiss-1/+1
Currently the Args new function is scope constrained to pub(super) but this stops me from being able to construct Args structs in unit tests.
2025-05-02zkVM: Cache args from hostThalia Archibald-55/+31
Retrieve argc/argv from the host once, on demand when the first `env::ArgsOs` is constructed, and globally cache it. Copy each argument to an `OsString` while iterating.
2025-05-02zkVM: Fix env::ArgsOsThalia Archibald-17/+54
The zkVM implementation of `env::ArgsOs` incorrectly reports the full length even after having iterated. Instead, use a range approach which works out to be simpler. Also, implement more iterator methods like the other platforms in #139847.
2025-05-02Implement Iterator::last for vec::IntoIterThalia Archibald-2/+2
2025-05-01Delegate to inner `vec::IntoIter` from `env::ArgsOs`Thalia Archibald-20/+132
Delegate from `std::env::ArgsOs` to the methods of the inner platform-specific iterators, when it would be more efficient than just using the default methods of its own impl. Most platforms use `vec::IntoIter` as the inner type, so prioritize delegating to the methods it provides. `std::env::Args` is implemented atop `std::env::ArgsOs` and performs UTF-8 validation with a panic for invalid data. This is a visible effect which users certainly rely on, so we can't skip any arguments. Any further iterator methods would skip some elements, so no change is needed for that type. Add `#[inline]` for any methods which simply wrap the inner iterator.
2025-04-27use generic Atomic type where possibleChristopher Durham-5/+5
in core/alloc/std only for now, and ignoring test files Co-authored-by: Pavel Grigorenko <GrigorenkoPV@ya.ru>
2025-04-21Unify owned `Env` types between platformsThalia Archibald-20/+15
Also, update the same pattern of reuse in `sys::args` to match.
2025-04-21Rollup merge of #139795 - jethrogb:jb/sgx-linkage-comments, r=joboetChris Denton-0/+1
Clarify why SGX code specifies linkage/symbol names for certain statics Specifying linkage/symbol name is solely to ensure a single instance between the `std` crate and its unit tests. Also update the symbol names as items have moved around a bit. The actual name isn't that important, it just needs to be unique. But for debugging it can be useful for it to point to the right place.
2025-04-14Clarify why SGX code specifies linkage/symbol names for certain staticsJethro Beekman-0/+1
Also update the symbol names as items have moved around a bit. The actual name isn't that important, it just needs to be unique. But for debugging it can be useful for it to point to the right place.
2025-04-13Hermit: Unify std::env::args with UnixThalia Archibald-40/+9
The only differences between these implementations are that Unix uses relaxed ordering, but Hermit uses acquire/release, and Unix truncates `argv` at the first null pointer, but Hermit doesn't. Since Hermit aims for Unix compatibility, unify it with Unix.
2025-04-12Unify owned Args types between platformsThalia Archibald-222/+77
2025-04-12Use unsupported args for espidf and vitaThalia Archibald-14/+1
2025-04-12Move args into std::sysThalia Archibald-0/+1322