Implement a WASI instantiation C API.#977
Implement a WASI instantiation C API.#977peterhuene merged 10 commits intobytecodealliance:masterfrom
Conversation
This commit implements an initial WASI C API that can be used to instantiate and configure a WASI instance from C. This also implements a `WasiBuilder` for the C# API enabling .NET hosts to bind to Wasmtime's WASI implementation.
Close the file descriptors before attempting to reopen the files.
Remove unnecessary loop when marshaling lists of strings as pointers to UTF-8 bytes.
alexcrichton
left a comment
There was a problem hiding this comment.
I'm not one really for reviewing much of the C#, but I can at least take a look at the Rust parts :)
| impl wasi_config_t {} | ||
|
|
||
| #[no_mangle] | ||
| pub unsafe extern "C" fn wasi_config_new() -> *mut wasi_config_t { |
There was a problem hiding this comment.
FWIW for new APIs we may want to explore updating how we write bindings. For example we could make all functions safe ideally, and this function could, for example, return Box<wasi_config_t> instead of *mut which would avoid extra boilerplate.
Another example would be that wasi_config_delete would be safe and take a Box<wasi_config_t> as well perhaps. I've been meaning to see how far we can take this because it'd be great to avoid so much unsafety in the bindings, but it definitely breaks down at some point, for example when handling *const c_char
There was a problem hiding this comment.
That would be interesting to do. I don't like the unsafety of this layer either and while it needs to exist at some level to interact with C, perhaps we could make it much more difficult for us to introduce leaks and use-after-frees by generating the unsafe boilerplate.
4f66875 to
d0a8e57
Compare
This commit makes `WasiCtxBuilder` take `&mut Self` and return `&mut Self` for its methods. This is needed to allow for the same (unmoved) `WasiCtxBuilder` to be used when building a WASI context. Also fixes up the C API to remove the unnecessary `Box::from_raw` and `forget` calls which were previously needed for the moving version of `WasiCtxBuilder`.
This commit renames `wasi_config_set_std[in|out|err]` to `wasi_config_set_std[in|out|err]_file` so we can reserve the former for when the C API supports a stream abstraction.
d0a8e57 to
c92bf4d
Compare
This PR implements an initial WASI C API that can be used to instantiate
and configure a WASI instance from C.
This also implements a
WasiBuilderfor the C# API enabling .NET hosts to bindto Wasmtime's WASI implementation.