WebAssembly with C: Emscripten Tutorial from Hello World to Instantiation

Added:

WebAssembly Basics
Core Concepts
Setup And Compile
First Compile
Custom Module
Instantiation
Memory Setup
Calling Function
Results & Future

WebAssembly Basics

0:00
Playing Section
  • 1

    Introduces the goal of compiling C/C++ to WebAssembly for browser execution.

  • 2

    Explains the toolchain, including Emscripten, Clang, and LLVM.

  • 3

    Defines core concepts like modules, memory, tables, and instances.

Fundamental C programming concepts, including pointers, manual memory management (malloc and free), and the standard C library.
Basic JavaScript proficiency, particularly asynchronous operations (Promises, async/await) which are crucial for loading and instantiating Wasm modules.
Familiarity with the command-line interface (CLI) for executing compilation commands and navigating directories.
Conceptual understanding of how web browsers run code, including the distinction between interpreted languages like JavaScript and compiled machine code.
Advanced Emscripten interoperability, specifically utilizing ccall, cwrap, and the EM_ASM macros for complex bidirectional communication.
WebAssembly memory sharing and optimization, focusing on direct manipulation of the Emscripten HEAP via JavaScript TypedArrays.
Multi-threading in WebAssembly using Web Workers and POSIX threads (pthreads) compiled through Emscripten.
Integration of WebAssembly modules into modern web application bundlers (such as Webpack, Vite, or Rollup) and front-end frameworks.
Introduction to the WebAssembly System Interface (WASI) for executing compiled C code in non-browser runtimes like Node.js, Wasmer, or Wasmtime.
1.7K views31likes16:36@howdevyouOriginal Release: 2023-09-06

WebAssembly is a binary instruction format that enables browsers to execute code compiled from low-level languages like C/C++, and Emscripten (emsdk) provides the toolchain to compile C/C++ programs into WebAssembly modules using Clang for the front-end and LLVM for the back-end, where modules contain exported functions, memories (linear memory similar to JavaScript typed arrays), and tables (function reference arrays), and these modules can be instantiated in JavaScript using WebAssembly.instantiate() with an import object defining the memory and other external resources.