Skip to content

Remove special WASI handling#23

Merged
blyxxyz merged 1 commit intomasterfrom
fix-wasip2
Mar 28, 2025
Merged

Remove special WASI handling#23
blyxxyz merged 1 commit intomasterfrom
fix-wasip2

Conversation

@blyxxyz
Copy link
Owner

@blyxxyz blyxxyz commented Mar 28, 2025

I originally added special handling for WASI OS strings because I saw std::os::wasi::ffi::OsStrExt in the docs and assumed that meant WASI worked like Unix.

It doesn't. The consensus is to only permit Unicode. wasmtime rejects invalid UTF-8:

$ wasmtime target/wasm32-wasip2/debug/examples/echo.wasm $'\xff'
Error: failed to convert "\xFF" to utf-8

Most platforms re-export Unix's OsStrExt and WASI happens to be one of the platforms for which docs are built. But in practice any string that passes between a WASI program and the OS must be Unicode. Invalid OS strings can only be created using the extension traits.

Also, on the new wasm32-wasip2 target std::os::wasi::ffi::OsStrExt is marked unstable, and so lexopt failed to build.

So we no longer treat WASI specially in the library. It's now just another fallback target that sometimes has to use OsStr::to_string_lossy.

In the tests however we can now use wasm32-wasip1 to finally test how the fallback code reacts to invalid OS strings. This was never very exciting but it's nice to have it covered.

I originally added special handling for WASI OS strings because I saw
`std::os::wasi::ffi::OsStrExt` in the docs and assumed that meant WASI
worked like Unix.

It doesn't. The consensus is to only permit Unicode. `wasmtime`
rejects invalid UTF-8:

  $ wasmtime target/wasm32-wasip2/debug/examples/echo.wasm $'\xff'
  Error: failed to convert "\xFF" to utf-8

Most platforms re-export Unix's `OsStrExt` and WASI happens to be one
of the platforms for which docs are built. But in practice any string
that passes between a WASI program and the OS must be Unicode. Invalid
OS strings can only be created using the extension traits.

Also, on the new `wasm32-wasip2` target `std::os::wasi::ffi::OsStrExt`
is marked unstable, and so lexopt failed to build.

So we no longer treat WASI specially in the library. It's now just
another fallback target that sometimes has to use
`OsStr::to_string_lossy`.

In the tests however we can now use `wasm32-wasip1` to finally test
how the fallback code reacts to invalid OS strings. This was never
very exciting but it's nice to have it covered.
@blyxxyz blyxxyz merged commit d1811ec into master Mar 28, 2025
10 checks passed
@blyxxyz blyxxyz deleted the fix-wasip2 branch March 28, 2025 14:02
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