Skip to content

Add SetStdout SetStdin #34

Open
Open

Description

@c0mm4nd

I saw that I cannot easily convert the string path in SetStdoutFile(path string) to the io.ReadWriter on wasmtime-go, so this is a suggestion to wasmtime.

io.ReadWriter is an interface which implemented by os.File and bytes.Buffer. With an io.ReadWriter as the parameter for WASI config, golang can operate its favor bytes without filesystem-level io, which means the WASI call will be more easy safe and stable.

buf := bytes.NewBuffer(nil)
config := wasmtime.NewWasiConfig()	
config.SetStdin(buf)
config.SetStdout(buf)

// then instaniate the wasi with the config

go func(){
	b, err buf.ReadBytes('\n')
	// handle this
}()
go instance.GetExport("_start").Func().Call()
// now intance request a stdin
buf.Write("continue exec")

Activity

  1. alexcrichton commented on Jul 20, 2020

    @alexcrichton
    Member

    This is similar to bytecodealliance/wasmtime-py#34 where there's support for this in the Rust wasmtime API but support has yet to be added to the C API

  2. cohix commented on Oct 20, 2022

    @cohix

    Bumping this, as it would be extremely useful to be able to pass stdin and get stdout from modules :)

    @alexcrichton if you have any advice on how we could help implement this, we'd love to contribute.

  3. alexcrichton commented on Oct 20, 2022

    @alexcrichton
    Member

    Implementing this would first need to start out at the Wasmtime C API layer. There's not a ton of Wasmtime-specific prior art to choose from unfortunately, so the APIs for this at the C layer need to be designed from scratch and implemented. Once that's landed then the Go support can be built on top of that.

  4. jaime-amate commented on Feb 15, 2024

    @jaime-amate

    Bumping this as well, I think it would be pretty handy to have this functionality implemented as in the Rust implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址