Chapter 2. Introducing WebAssembly

WebAssembly is a portable binary code format that is delivered to the browser as modules using the .wasm file extension. It also defines a corresponding textual assembly language, called WebAssembly Text Format, which uses the .wat (WAT) extension. There is a close correspondence between the binary and textual formats, with the latter simply making it easier for humans to read .wasm modules.

Although it is relatively straightforward to write .wasm modules directly using this text format, it is primarily designed as a compilation target. The first demonstrations of this technology used the Emscripten compiler, allowing compilation of C/C++ to WebAssembly.

This chapter explores the structure of WebAssembly modules, through a few simple examples. Following this, we take a look at the WebAssembly runtime and how it integrates with its host environment. Finally, we look at the various languages that you can use to write applications in WebAssembly.

WebAssembly Modules

WebAssembly applications are written using a variety of different programming languages (C, C++, Rust, Python), each with their respective toolchains, with the ultimate output of the compilation process being one or more WebAssembly modules. These modules are delivered to the browser over HTTP as .wasm files. This section takes a look at this compilation process via a simple example and the modules it creates. The example itself will be quite trivial; it is the tools and processes that ...

Get What Is WebAssembly? now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.