Stream: wasi

Topic: virtualizing wasi (preview 1)


view this post on Zulip Leon Thomm (Dec 14 2023 at 21:44):

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.

view this post on Zulip Lann Martin (Dec 14 2023 at 22:13):

Well you need at least one export for a component to do anything useful :smile:

view this post on Zulip Lann Martin (Dec 14 2023 at 22:14):

but this is what you'd be looking for: https://github.com/bytecodealliance/WASI-Virt/

Virtual implementations of WASI APIs. Contribute to bytecodealliance/WASI-Virt development by creating an account on GitHub.

view this post on Zulip Leon Thomm (Dec 14 2023 at 22:41):

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?

view this post on Zulip Leon Thomm (Dec 14 2023 at 22:42):

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.

view this post on Zulip Joel Dice (Dec 14 2023 at 22:45):

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.

view this post on Zulip Leon Thomm (Dec 14 2023 at 22:48):

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?

view this post on Zulip Joel Dice (Dec 14 2023 at 23:03):

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.

A virtual filesystem layer for WASI. Contribute to kateinoigakukun/wasi-vfs development by creating an account on GitHub.

Last updated: Nov 22 2024 at 16:03 UTC