Would it be difficult to create a WASI implementation that virtualizes some parts (file system) and no-op's on the rest that doesn't make sense without an actual OS (like networking)? Ideally, this implementation should yield a wasm module that I can link any WASI-dependent wasm application against, resulting in a freestanding wasm binary without any function imports.
Background: I'm working on a project which deploys pure compute binaries without any system interface. So far, we compield existing code against our own libc which virtualizes some parts (the file system) and no-op's (returns failures) on the rest. I'm adding WASM support for this, so I would like to do something similar for WASI, then we could simply rely on wasi-libc.
I couldn't find something like this, but if I missed it or if there are other works which could make this easy I would highly appreciate some pointers.
Well you need at least one export for a component to do anything useful :smile:
but this is what you'd be looking for: https://github.com/bytecodealliance/WASI-Virt/
thank you! I didn't specify that I'm looking for mainly supporting WASI preview 1, as most things I'd like to compile are currently using preview 1. Is there something like this for preview 1?
Or maybe is there an easy way to reliably convert preview 1 things to preview 2 components? I'm generally not very familiar with the preview 2 ecosystem at the moment.
Yes, wit-component
plus https://github.com/bytecodealliance/wasmtime/tree/main/crates/wasi-preview1-component-adapter may be used to convert a Preview 1 module into a Preview 2 component, and then use wasi-virt
to virtualize all its imports. However, the output of that process is a component, not a module, so only hosts with component model support (basically Wasmtime and Jco at this point) will be able to run it.
Interesting, thanks for the clarification. I'm currently relying on a wasm-to-native compilation toolchain which does not implement components, just WebAssembly. Did wasi-virt (or something like it) exist for preview 1?
There's https://github.com/kateinoigakukun/wasi-vfs for the filesystem part, but I'm not aware of anything that covers all of preview 1.
Last updated: Nov 22 2024 at 16:03 UTC