wasmerio / wasmer-go

🐹🕸️ WebAssembly runtime for Go
https://pkg.go.dev/github.com/wasmerio/wasmer-go
MIT License
2.82k stars 161 forks source link

Adding API for setting 'Stdout' and 'Stderr' #228

Open hassan-shahbazi opened 3 years ago

hassan-shahbazi commented 3 years ago

Motivation

The support of WASI has been added in the latest version of wasmer-go. It is now possible to capture Stdout and Stderr outputs using CaptureStdout and CaptureStderr APIs respectively. However, there is not yet any API for setting the custom pipes for them and thus, it is not yet possible to take the full advantage from WASI APIs.

Proposed solution

I am not an expert, but I can think of the following functions. The important point, however, is that they should accept both normal files and pipes. Currently, wasmtime has the same set of APIs, but it is unable to accept pipes and thus, it is not practical in many cases.

func (self *WasiStateBuilder) SetStdoutFile(path string) error
func (self *WasiStateBuilder) SetStderrFile(path string) error
Hywan commented 3 years ago

I think it's better to fit with the standard Go stream/pipe API if such thing exists, rather than developping more features inside the Wasmer C API. We already have wasi_env_read_stdout (and …_stderr) that allows to read data from stdout and stderr with a buffer already. It's pretty flexible.