Stream: git-wasmtime

Topic: wasmtime / issue #8274 Memory Input Pipe Write from outside


view this post on Zulip Wasmtime GitHub notifications bot (Apr 01 2024 at 03:58):

MinusGix opened issue #8274:

Feature

When supplying a customMemoryInputPipe to WasiCtxBuilder as stdin it would be useful to have the ability to write to it in order to communicate with the program.

(The specific use-case here is spawning WASM programs that essentially act like LSPs, communicating over a simple text interface rather than directly calling functions)

Benefit

Allows sending data through stdin, and reading data from stdout/stderr.

Implementation

Probably have to change MemoryInputPipe to use a BytesMut.
Could add standard std::io::Read/std::io::Write implementations to MemoryInputPipe (and MemoryOutputPipe, though that's readable though .content()) like the old ReadPipe/WritePipe from wasi-common?

Alternatives

Reimplement a version locally.
(Could be I've missed some alternative solution?)

view this post on Zulip Wasmtime GitHub notifications bot (Apr 01 2024 at 03:59):

MinusGix edited issue #8274:

Feature

When supplying a customMemoryInputPipe to WasiCtxBuilder as stdin it would be useful to have the ability to write to it in order to communicate with the program.

(The specific use-case here is spawning WASM programs that essentially act like LSPs, communicating over a simple text interface rather than directly calling functions)

Benefit

Allows sending data through stdin, along with reading data from stdout/stderr.

Implementation

Probably have to change MemoryInputPipe to use a BytesMut.
Could add standard std::io::Read/std::io::Write implementations to MemoryInputPipe (and MemoryOutputPipe, though that's readable though .content()) like the old ReadPipe/WritePipe from wasi-common?

Alternatives

Reimplement a version locally.
(Could be I've missed some alternative solution?)

view this post on Zulip Wasmtime GitHub notifications bot (Apr 01 2024 at 12:05):

bjorn3 commented on issue #8274:

Would wasmtime_wasi::pipe::AsyncReadStream work for you? It allows the guest to read from an AsyncRead you supply.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 01 2024 at 15:10):

alexcrichton commented on issue #8274:

To confirm, @MinusGix are you using the C API? If so then this implemented in the C API at this time. If you're using the Rust API, however, you can use WasiCtxBuilder::stdin with a custom implementation of StdinStream where the HostInputStream you're implementing would be backed by AsyncReadStream as @bjorn3 mentioned.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 01 2024 at 19:06):

MinusGix commented on issue #8274:

I am using the Rust API, updating a project that was last on 14.0.0.

I have not directly used async/tokio much in any past projects, which makes it unclear what type to use that implements AsyncRead + can be shared so that we can write to it from elsewhere. If there's some obvious choice here, I was unable to find it after some searching on the net/tokio docs.

If I'm needing a custom implementation, then it seems simpler to reuse a modified MemoryInputStream to implement Write (and if provided in wasmtime would make it simpler as a user).

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2024 at 18:35):

alexcrichton commented on issue #8274:

I think what you probably want is a DuplexStream

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2024 at 21:24):

MinusGix closed issue #8274:

Feature

When supplying a customMemoryInputPipe to WasiCtxBuilder as stdin it would be useful to have the ability to write to it in order to communicate with the program.

(The specific use-case here is spawning WASM programs that essentially act like LSPs, communicating over a simple text interface rather than directly calling functions)

Benefit

Allows sending data through stdin, along with reading data from stdout/stderr.

Implementation

Probably have to change MemoryInputPipe to use a BytesMut.
Could add standard std::io::Read/std::io::Write implementations to MemoryInputPipe (and MemoryOutputPipe, though that's readable though .content()) like the old ReadPipe/WritePipe from wasi-common?

Alternatives

Reimplement a version locally.
(Could be I've missed some alternative solution?)

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2024 at 21:24):

MinusGix commented on issue #8274:

That'll probably work.
Looking back, the primary issue is seemingly that I was confused about MemoryInputPipe/MemoryOutputPipe: I was interpreting them as "buffers to read/write from which are just missing utility functions", but they're actually for having some fixed data that you want to pass in or having a fixed size buffer to write data into.


Last updated: Nov 22 2024 at 17:03 UTC