WebAssembly’s binary format is designed to be executable efficiently on a variety of operating systems and instruction set architectures, on the Web and off the Web.
Execution environments which, despite limited, local, nondeterminism, don’t offer the following characteristics may be able to execute WebAssembly modules nonetheless. In some cases they may have to emulate behavior that the host hardware or operating system don’t offer so that WebAssembly modules execute as-if the behavior were supported. This sometimes will lead to poor performance.
As WebAssembly’s standardization goes forward we expect to formalize these requirements, and how WebAssembly will adapt to new platforms that didn’t necessarily exist when WebAssembly was first designed.
WebAssembly portability assumes that execution environments offer the following characteristics:
WebAssembly does not specify any APIs or syscalls, only an import mechanism where the set of available imports is defined by the host environment. In a Web environment, functionality is accessed through the Web APIs defined by the Web Platform. Non-Web environments can choose to implement standard Web APIs, standard non-Web APIs (e.g. POSIX), or invent their own.
Portability at the C/C++ level can be achieved by programming to
a standard API (e.g., POSIX) and relying on the compiler and/or libraries to map
the standard interface to the host environment’s available imports either at
compile-time (via #ifdef
) or run-time (via feature detection
and dynamic loading/linking).