webassemblywasi

Why use WASI if WASM supported languages have their own standard libraries?


I might have a fundamental misunderstanding about WASM, tried to google it and read some of the docs, but it is not clear to me yet.

As far as I understand, WASI is an language agnostic API for many features present in the standard library of the languages that support WASM compilation (has file system access functions, manual memory allocation, etc).

But, before WASI, languages targeting WASM could make full use of their standard libraries functionalities already. Is that correct?

I'm worried this is not the case, and I will find roadblocks and limitations when using WASM if my language also does not support WASI.

I'm developing a web Browser application. In my research, I found you need a runtime (like Wasmer) to run WASM bytecode natively, so I'm fine here. But, found nothing about WASI in that regard.


Solution

  • In order to implement many standard library functions (e.g. filesystem), languages need to target some kind of system API. WASI is a standard set of APIs that can be used either by language runtimes, or directly by user code.

    The WASI API is somewhat analogous to the system call layer in an operating system. Without WASI you would need to design your own system call layer and then somehow implement that in all the runtimes you care about. This may be technically feasible but it has many downsides compared to using a standard such as WASI.