Skip to content

Implementation of wasi:cli@0.2.12 - #70

Merged
andreaTP merged 14 commits into
roastedroot:mainfrom
andreaTP:wasi-p2-cli
Oct 27, 2026
Merged

andreaTP merged 14 commits into
roastedroot:mainfrom
andreaTP:wasi-p2-cli

Conversation

@andreaTP

@andreaTP andreaTP commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Implements wasi:cli@0.2.12, the last interfaces a typical Rust wasm32-wasip2 program needs.

  • Bindgen: a result used as a value (a parameter, or inside another type) now maps to a new run.endive.cm.runtime.Result<T, E>, lifted and lowered like tuples. exit: func(status: result) needs it. Results returned by a function keep their current mapping.
  • WIT: deps/wasi_cli@0.2.12.wit is printed like the other deps, including its imports and command worlds, and the endive:wasi world is now include wasi:cli/imports@0.2.12.
  • Hosts (run.endive.cm.wasi.p2.cli):
    • environment and arguments;
    • exit and exit-with-code, which throw WasiExitException;
    • stdout and stderr written synchronously to the embedder's streams, which are never closed, with a failed PrintStream such as a broken System.out pipe reported to the guest;
    • stdin through one reader per Java stream, shared by every host given it and started on the guest's first read or poll, with backpressure;
    • terminal interfaces controlled by per-stream TTY flags.
  • API: the builder method names follow Endive's WASI p1: withArguments, withEnvironment, withStdin/withStdout/withStderr (each optionally with a TTY flag) and inheritSystemStreams. int run(ComponentStore, WasmComponent) calls the guest's wasi:cli/run export, matched to 0.2 by the same compatible-version rule as imports (Link guests importing semver-compatible interface versions #69), and returns its exit code.
  • TTY default: streams default to not being a terminal, unlike p1, so captured output stays free of terminal styling. inheritSystemStreams counts them as terminals when the JVM has a console, which JDK 22 to 24 report even for redirected streams, as its Javadoc says.

Tests: CliGuestTest (12 end to end, WAT guest), unit tests for each host, the bindgen ResultValuesTest, a bindgen test of an error type one interface returns and another takes as a value (with #73's shared exceptions), and a virtual-thread run test in wasi-p2-loom-tests.

@jeremyg484 jeremyg484 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great!

I've reviewed it mainly with an eye towards compatibility with my in-progress wasi:sockets, and noted (mostly for myself since this will likely merge first) one case in the error handling in bindgen that will need to be handled carefully when we merge sockets.

A few other potential issues were caught with an AI review that feel like they're worth addressing in some form.

Comment thread wasi-p2/src/main/java/run/endive/cm/wasi/p2/cli/stdin/HostStdin.java Outdated
Comment thread wasi-p2/src/main/java/run/endive/cm/wasi/p2/WasiPreview2.java
Comment thread wasi-p2/src/main/java/run/endive/cm/wasi/p2/WasiPreview2.java Outdated
@andreaTP
andreaTP merged commit 5ea5758 into roastedroot:main Oct 27, 2026
3 checks passed
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.

2 participants