Stream: wasmtime

Topic: Using a file as the stdin stream


view this post on Zulip Jeff Charles (Jun 05 2025 at 18:57):

:wave: does wasmtime-wasi's WasiCtxBuilder have an equivalent API to wasi-common's File for use with WasiCtxBuilder's stdin method?

I noticed stdout and stderr both support OutputFile but there does not appear to be an equivalent struct for a file for use with stdin. I did find FileInputStream but outside crates don't have access to the &File type which is one of the parameters for its public new function (that seems like the new function shouldn't be public or the File type it requires should be public) and FileInputStream doesn't implement StdinStream which is what WasiCtxBuilder needs for the stdin method.

view this post on Zulip Pat Hickey (Jun 05 2025 at 19:27):

theres no InputFile corresponding to OutputFile, but as best i can tell, thats just an oversight. you can make a PR to add one if youd like

view this post on Zulip Pat Hickey (Jun 05 2025 at 19:29):

like OutputFile, the inner should be an Arc<std::fs::File>

view this post on Zulip Pat Hickey (Jun 05 2025 at 19:29):

the deal with the stdio streams is that there can be multiple resources pointing to stdout, but all of those instances should be pointing to the same underlying state. same for stdin

view this post on Zulip Pat Hickey (Jun 05 2025 at 19:31):

you should also be able to define and implement InputFile in any library, but since its an oversight that its not provided in wasmtime-wasi we can provide it there as well

view this post on Zulip Jeff Charles (Jun 05 2025 at 19:32):

Makes sense to me! Any thoughts on what to do with the new method on FileInputStream since it seems to me like that either shouldn't be public or that the File type it expects should be public?

view this post on Zulip Pat Hickey (Jun 05 2025 at 19:46):

thats also a bug: that should be pub(crate) instead of pub

view this post on Zulip Pat Hickey (Jun 05 2025 at 19:47):

or, actually, FileInputStream should itself only be pub(crate). its an implementation detail and shouldnt be part of the crates api.

view this post on Zulip Jeff Charles (Jun 05 2025 at 19:51):

Yeah that makes sense to me too


Last updated: Dec 06 2025 at 06:05 UTC