Skip to content

Vendor the cap-primitives crate within the wasmtime-wasi crate - #14219

Open
alexcrichton wants to merge 34 commits into
bytecodealliance:mainfrom
alexcrichton:vendor-cap-primitives
Open

Vendor the cap-primitives crate within the wasmtime-wasi crate#14219
alexcrichton wants to merge 34 commits into
bytecodealliance:mainfrom
alexcrichton:vendor-cap-primitives

Conversation

@alexcrichton

Copy link
Copy Markdown
Member

This PR is a series of commits which vendors the cap-primitives crate, or what Wasmtime needs, within the wasmtime-wasi crate. This is done as an acknowledgement of the current maintenance and state of the cap-std repository and project where having a security-critical dependency external of Wasmtime itself is becoming more and more of a burden. This was discussed in today's Wasmtime meeting and had unanimous agreement about this transition. The Bytecode Alliance TSC will, I believe, ask if anyone would like to end up maintaining the cap-std crates in parallel to this but our decision was that regardless of that outcome it's still best to vendor the code here within Wasmtime itself.

This PR is structured as a sequential list of commits which tell a story of sorts of how this was vendored. This is a very large change so the intention is to be as methodical and "obviously correct" as possible. The cap-primitives crate contains quite a bit of functionality which Wasmtime doesn't need and can thus be deleted. Additionally the tests for cap-primitives are all written against the cap-std layer which has a differently-shaped API surface area. To that end the major adjustments from cap-primitives are:

  • Only the fs, rustix, and windows submodules are vendored here.
  • All dead code and dead #[cfg]-related code has been deleted.
  • Tests were copied verbatim from cap-std, and then adjusted/deleted as necessary. Due to the scale of the change this step was primarily done with LLM assistance and manual review.
  • A minor debug-only bug was fixed for me to run tests locally.
  • All dependencies of cap-primitives, added to wasmtime-wasi, were subsequently removed as they were pretty light dependencies.

The end result is intended to be a source-wise pretty much line-for-line vendor of cap-primitives. The tests are spiritually all ported over but greatly differ at the source level due to API differences. This PR is intended to be proactively backported to supported release branches of Wasmtime to avoid the need to patch external code should future security issues arise with the wasi:filesystem implementation. This includes Wasmtime 36, 47, and 48. To this end the switch-over here was audited to ensure that the public API of the wasmtime-wasi crate does not change as a result of this commit and is thus semver-compatible to backport. This means that there's a single remaining vestigal use of the cap-primitives crate to simply reexport the SystemTimeSpec type at the root of the wasmtime-wasi crate. This isn't actually used anywhere, though, so the only purpose is its reexport. This reexport will be deleted on main after this PR, but will not be deleted in backports.

The backport situation for Wasmtime 36 and 47 is going to be more complicated because they do not contain #13872. Despite that I think we'll still be able to basically pull it off, but I've not yet proven this out.

Copy the entire contents of this crate into
`crates/wasi/src/filesystem/primitives` for future modifications to get
it building.
* Add necessary dependencies
* Adjust imports
* Rename `cap-primitives to `public-cap-primitives`
* Move public-facing dependencies to `public-cap-primitives`
* Move internal dependencies to `crate::filesystem::primitives`
This isn't something used in Wasmtime so it's all dead code
These are related to nightly features that cap-primitives optionally
used, and Wasmtime won't be using any nightly features from Wasmtime.
Not going to be used by Wasmtime.
* `unix_file_vectored_at`
* `io_error_more`
* `io_error_uncategorized`
Will work on handling these later.
Much of cap-primitives isn't used by Wasmtime, so this commit goes
through and resolves all rustc warnings and deletes a whole bunch of
dead code.
This commit gets all relevant tests from cap-std compiling against the
vendored version of cap-primitives. The goal here is to retain as much
test coverage as possible so tests are modified pretty heavily to the
new API structure where `cap-primitives` is effectively used instead of
`cap-std`'s API surface area. This includes lots of various hlepers and
such to keep tests relatively terse and such.
This commit resolves a debug-mode-only panic about an overflow which
happens internally within cap-std.
Not needed from the cap-primitives vendoring
Also remove unused cap-fs-ext dependency
prtest:full
@alexcrichton
alexcrichton requested review from a team as code owners August 27, 2026 21:46
@alexcrichton
alexcrichton requested review from pchickey and removed request for a team August 27, 2026 21:46
@alexcrichton
alexcrichton requested a review from fitzgen August 27, 2026 21:46
@fitzgen
fitzgen removed their request for review August 27, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant