/Assembling-WebAssembly

A book by Claude Code Sonnet 4.5 about WASM

Creative Commons Zero v1.0 UniversalCC0-1.0

Assembling WebAssembly

A comprehensive guide to building WebAssembly from multiple programming languages. This book is designed for advanced developers who want to master WASM across web, server, embedded, and edge computing contexts.

About This Book

This book assumes you already know the programming languages we'll be using. Our focus is on teaching you WebAssembly itself—how to compile to it, optimize for it, and deploy it effectively across different environments.

Status: Complete - All 52 chapters written, covering foundations through advanced topics to real-world practice projects.

Table of Contents

Part 1: Foundations

  1. Introduction - Why WASM exists, use cases, and the problems it solves
  2. Architecture - Stack machine model, instruction set architecture, specification overview
  3. Text Format - Deep dive into WAT (WebAssembly Text format) syntax
  4. Binary Format - Understanding WASM bytecode structure and encoding
  5. Type System - Value types, function signatures, and type validation
  6. Memory Model - Linear memory, pages, limits, and memory operations
  7. Module Anatomy - Module sections, structure, and validation rules

Part 2: Runtime & Execution

  1. Instantiation - Module loading, compilation, and linking process
  2. Imports and Exports - Interface patterns and module composition
  3. Tables - Indirect calls, function references, and dynamic dispatch
  4. Security Model - Sandboxing, capability-based security, and isolation

Part 3: Toolchain & Ecosystem

  1. Compilers Overview - Landscape of WASM compilation targets
  2. Runtimes - wasmtime, wasmer, wasm3, and browser engines
  3. WASI - WebAssembly System Interface specification
  4. Debugging - Tools, source maps, profiling, and troubleshooting
  5. Testing - Unit testing WASM modules and integration testing strategies

Part 4: Language Deep Dives

  1. Rust Fundamentals - Using rustc with wasm32 target, basics
  2. Rust Advanced - wasm-bindgen, wasm-pack, and optimization techniques
  3. Go Official - Go's official WASM support and its limitations
  4. TinyGo - Better Go WASM compilation and tradeoffs
  5. C/C++ - Emscripten ecosystem and toolchain
  6. Clang WASM - Direct LLVM-based compilation without Emscripten
  7. AssemblyScript - TypeScript-like language designed for WASM
  8. .NET and Blazor - C# and the .NET approach to WebAssembly

Part 5: Language Survey

  1. Zig - Modern systems language with excellent WASM support
  2. Swift - SwiftWasm project and Swift's WASM capabilities
  3. Kotlin - Kotlin/Wasm and the JVM ecosystem approach
  4. Python - Pyodide, limitations, and Python in the browser
  5. Experimental Languages - Grain, Moonbit, and emerging WASM-first languages
  6. Barely There - Languages with minimal or experimental WASM support

Part 6: Web Integration

  1. Browser APIs - The WebAssembly JavaScript API
  2. JavaScript Interop - Calling conventions and data marshalling
  3. DOM Access - Patterns for DOM manipulation from WASM
  4. Web Workers - Threading and parallel execution in browsers
  5. Streaming - Streaming compilation and instantiation

Part 7: Server & CLI

  1. WASI Deep Dive - Filesystem, networking, and system interfaces
  2. CLI Tools - Building command-line tools with WASM
  3. Server-Side - Fastly Compute, Cloudflare Workers, and server runtimes
  4. Plugin Systems - Extending applications with WASM plugins

Part 8: Embedded & Edge

  1. Embedded Runtimes - wasm3, WAMR for IoT and microcontrollers
  2. Edge Computing - CDN edge, distributed computing patterns
  3. Resource Constraints - Optimizing for memory and CPU-constrained targets

Part 9: Advanced Topics

  1. SIMD - Vector instructions and parallel data processing with v128 types
  2. Threads - Shared memory threading model and atomics
  3. Component Model - Next-generation composition with WIT interfaces
  4. Garbage Collection - GC proposal for managed languages (Java, Kotlin, Dart)
  5. Exception Handling - First-class exceptions with try/catch/throw
  6. Tail Calls - Tail call optimization for functional programming patterns

Part 10: Practice

  1. Building an Image Processor - Complete image processing app with SIMD and Web Workers
  2. Building a Game Engine - 2D platformer with ECS architecture
  3. Cryptography and Data Processing - SHA-256, PBKDF2, AES-256 implementation
  4. Real-Time Audio Synthesis - Polyphonic synthesizer with AudioWorklet

Appendices

License

See LICENSE for details.

How to Read This Book

  • Sequential reading: Parts 1-3 build foundational knowledge. Read these in order.
  • Language chapters: Pick the languages relevant to your work (Parts 4-5).
  • Context-based reading: Choose Part 6 (Web), Part 7 (Server), or Part 8 (Embedded) based on your deployment target.
  • Advanced readers: Parts 9-10 can be read independently once you understand the foundations.

Prerequisites

This book assumes:

  • Strong programming background in at least one systems or application language
  • Familiarity with concepts like memory management, types, and compilation
  • Basic understanding of how code executes on hardware
  • No prior WASM knowledge required