-
Notifications
You must be signed in to change notification settings - Fork 55
Added Wasi2Configuration
#339
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@kpreisser @BasGeertsema want to give a review?
using var store = new Store(engine); | ||
|
||
var config = new Wasi2Configuration(); | ||
config.WithInheritedStandardInput(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to not test the other configs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have a look at adding some more tests later today
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added some more coverage (just calling other WithInheritedX
methods).
I'm not really happy about these tests though - they don't actually assert anything!
Ideally I guess we'd need a WASI2.wat
test file that reads some input, logs some out and logs some error output. Then we could assert that all of that is written to the correct outputs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked around for an easy way to test this but could not find it and I wonder what the right approach is to test this.
The WASI preview 2 is quite an API surface. In the stdio test in wasi-testsuite a lot more functionality is tested than just stdin/stdout/stderr. On the surface, it seems difficult to test just the stdin/stdout in isolation with a simple .wat file. For example, the WASI 0.2 WIT for the CLI contains references to the output-stream
and input-stream
types and other WASI specs. The WASI 0.2 tests in the test-suite are compiled to .wasm
via build scripts and I have not yet seen a simple stable .wat
file that can only test stdin/stdout.
This however got me thinking what the proposition is of wasmtime-dotnet
. The wasmtime
project links to this project as a way to embed wasmtime
as a library. I guess historically the use case was primarily around embedding an engine capable of executing WASM modules. But with the advent of WASI, wasmtime
offers a runtime with rich functionality that can interact with its environment through these system interfaces. So, whole applications (CLI applications and web applications for example) can be compiled to wasm and executed directly by invoking wasmtime
with the wasm file as argument. Kind of like an application server.
In contrast, wasmtime-dotnet
is a library (NuGet package) and does not have a standalone executable. So it is not possible to directly execute a WASM application, rather you´d have to write the dotnet program yourself that uses wasmtime-dotnet
.
If wasmtime-dotnet
would offer such an executable, we could utilize the wasi-testsuite to test the whole WASI surface. Which would cover the stdin/stdout functionality of this pull request, and a whole lot more. But at the same time it would be ´just' a thin wrapper around wasmtime
where all of the WASI interfaces are implemented by the wasmtime
runtime. Which is not a very good use case, because why not directly use wasmtime
in that case?
Imho the value proposition of wasmtime-dotnet
is that .NET applications can enhance their applications with WASM modules/components (possibly user-supplied) in a safe way that feels native to .NET (i.e. ergonomic to use). But that also implies more control over the system interfaces. For example, if a WASM component is loaded that uses wasi-cli or wasi-sockets do we want to use .NET streams and sockets or it is offloaded completely to the wasmtime (Rust) runtime, over which the .NET application has very little control? Integration with .NET streams and sockets would be ideal imo, but is also a huge endeavour.
I'm relatively new to the WASM ecosystem so I might be very confused here but imo there should be a clear proposition for wasmtime-dotnet that can guide the development of wasmtime-dotnet, which would also direct questions such as how to test WASI functionality.
Added
Wasi2Configuration
which mirrorsWasiConfiguration
for WASI preview2.