Compared to previous examples, we need to add -lc
(libc
) to the linker flags. The WebAssembly
build now depends on imports like fd_close
, fd_write
, etc., which are equivalent to operating
system calls. Such a System Interface API for WebAssembly programs will have to be supplied in the
WebAssembly runtime environment, e.g. WASI.
The JavaScript library
@wasmer/wasi provides such a WASI
implementation. stdout
is implemented as a file, just like on Unix, and
@wasmer/wasmfs is a suitable implementation in JavaScript.
The WebAssembly build grows to about 4 kB.