Skip to content

Reduce dependencies on cap-std-family crates#13872

Open
alexcrichton wants to merge 2 commits into
bytecodealliance:mainfrom
alexcrichton:cap-primitives-migration
Open

Reduce dependencies on cap-std-family crates#13872
alexcrichton wants to merge 2 commits into
bytecodealliance:mainfrom
alexcrichton:cap-primitives-migration

Conversation

@alexcrichton

Copy link
Copy Markdown
Member

This commit is an attempt to reduce the number of layers of abstraction that we have for the wasmtime-wasi crate and implementation, in particular around the dependencies that we have. Historically wasmtime-wasi has primarily depended on cap-std which provides a std-like API for using the native filesystem and other features (e.g. networking). Over time networking has largely moved away from cap-std, however. I've additionally historically found it difficult to trace through the tree of dependencies for figuring out what a WASI call does. This requires following code in wasmtime-wasi, to cap-std, to cap-*-ext sometimes, to cap-primitives, then to rustix. The goal of this commit is to shorten this chain and instead primarily rely on the "meat" of cap-std, the cap-primitives crate.

The cap-std crate additionally serves a bit of a dual purpose of providing filesystem sandboxing and abstracting the underlying platform. This abstraction though is a bit leaky where the API is different enough across platforms that it can come at a performance cost on some platforms while also still needing #[cfg]s on others. This commit additionally is intended to reduce the reliance on this portability layer since the API that we're implementing, WASI, is the definition of what we want portability-wise which doesn't always match what cap-std does.

Overall this commit removes the cap-std and io-lifetimes dependencies from the Wasmtime workspace itself. A dependency is left on cap-fs-ext out of necessity but it's only to access an otherwise-private API located in the cap-primitives crate. Implementations throughout wasmtime-wasi have shifted to using their std counterparts (e.g. clocks), encapsulating more platform-specific logic (e.g. unix-vs-windows filesystem behavior), and refactoring to avoid dependencies (e.g. networking).

This commit is not intended to introduce any new behavior nor change any preexisting behavior. The goal of this commit is to reduce the dependency tree of Wasmtime to the bare minimum necessary through the cap-primitives crate.

This commit is an attempt to reduce the number of layers of abstraction
that we have for the `wasmtime-wasi` crate and implementation, in
particular around the dependencies that we have. Historically
`wasmtime-wasi` has primarily depended on `cap-std` which provides a
`std`-like API for using the native filesystem and other features (e.g.
networking). Over time networking has largely moved away from `cap-std`,
however. I've additionally historically found it difficult to trace
through the tree of dependencies for figuring out what a WASI call does.
This requires following code in `wasmtime-wasi`, to `cap-std`, to
`cap-*-ext` sometimes, to `cap-primitives`, then to `rustix`. The goal
of this commit is to shorten this chain and instead primarily rely on
the "meat" of `cap-std`, the `cap-primitives` crate.

The `cap-std` crate additionally serves a bit of a dual purpose of
providing filesystem sandboxing and abstracting the underlying platform. This
abstraction though is a bit leaky where the API is different enough
across platforms that it can come at a performance cost on some
platforms while also still needing `#[cfg]`s on others. This commit
additionally is intended to reduce the reliance on this portability
layer since the API that we're implementing, WASI, is the definition of
what we want portability-wise which doesn't always match what `cap-std`
does.

Overall this commit removes the `cap-std` and `io-lifetimes`
dependencies from the Wasmtime workspace itself. A dependency is left on
`cap-fs-ext` out of necessity but it's only to access an
otherwise-private API located in the `cap-primitives` crate.
Implementations throughout `wasmtime-wasi` have shifted to using their
`std` counterparts (e.g. clocks), encapsulating more platform-specific
logic (e.g. unix-vs-windows filesystem behavior), and refactoring to
avoid dependencies (e.g. networking).

This commit is not intended to introduce any new behavior nor change any
preexisting behavior. The goal of this commit is to reduce the
dependency tree of Wasmtime to the bare minimum necessary through the
`cap-primitives` crate.
@alexcrichton alexcrichton requested review from a team as code owners July 13, 2026 18:42
@alexcrichton alexcrichton requested review from dicej and removed request for a team July 13, 2026 18:42
@github-actions github-actions Bot added wasi Issues pertaining to WASI wasmtime:c-api Issues pertaining to the C API. labels Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasi Issues pertaining to WASI wasmtime:c-api Issues pertaining to the C API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant