Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support setting bytes for stdin #405

Open
tiziano88 opened this issue Feb 4, 2024 · 4 comments
Open

support setting bytes for stdin #405

tiziano88 opened this issue Feb 4, 2024 · 4 comments
Labels
🎉 enhancement New feature or request

Comments

@tiziano88
Copy link

Motivation

It is quite common to have to provide a pre-determined stdin value to a Wasm module, without having to expose a full file system to it.

Proposed solution

leverage this function:

https://docs.wasmtime.dev/c-api/wasi_8h.html#a525abd98ade58887a969b796ea05468e

would require modifying

#if defined(WASMER_WASI_ENABLED)
void wasi_config_inherit_stdin(struct wasi_config_t *config);
#endif

and

wasmer-go/wasmer/wasi.go

Lines 196 to 202 in ca60a45

// InheritStdin configures the WASI module to inherit the stdin from
// the host.
func (self *WasiStateBuilder) InheritStdin() *WasiStateBuilder {
C.wasi_config_inherit_stdin(self.inner())
return self
}

Alternatives

The best alternative at the moment is passing the value as argument on the command line, but that's not great for large and / or binary values.

@tiziano88 tiziano88 added the 🎉 enhancement New feature or request label Feb 4, 2024
@jaime-amate
Copy link

jaime-amate commented Feb 15, 2024

I'm currently facing the same issue on my project. It would be quite handy having somehow a setStdIn function.

Could you explain on more further details about the workaround to pass input data to the wasi module execution?

@tiziano88
Copy link
Author

For the time being I just serialize the data as a string (base64 if necessary) and pass it as the first command line argument to the Wasm module, which then reads it as argv[1]

@jaime-amate
Copy link

Thanks for the explanation, I think this wouldn't even work in my use case :(

I'm trying to embed a .wasm module compiled by Javy and according to this issue, it doesn't currently expose APIs to read environment variables or command line arguments.

@tiziano88
Copy link
Author

Right, in that case fixing this issue wouldn't help you, since this is specific to WASI, which AFAICT you are not using. I think your best bet is to declare a custom function for the Wasm module to read the data into its own memory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎉 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants