Search code examples
clangllvmwebassemblyemscriptenwasi

What is the difference between Emscripten and Clang in terms of WebAssembly compilation?


I know both Clang (by use target=wasm32) and Emscripten can compile C code into WebAssembly, but how are they different?

It looks like they both use LLVM as the backend. Actually, I do not even quite understand the relation between LLVM and Clang...

I have been reading WebAssembly for a while, but I lack low-level understanding of it.


Solution

  • Clang is a compiler built on LLVM technology, so you often hear clang and LLVM used interchangeably. Clang is a just one component of the LLVM project.

    Emscripten is a compiler that uses Clang for most of the heavy lifting of actually compiling to WebAssembly, but it also adds a lot of features and functionality on top of that, mostly related to seamless integration with JavaScript and the web and emulation of POSIX and other standards.

    Emscripten runs Clang internally with --target=wasm32-unknown-emscripten which has some very minor differences to the regular --target=wasm32.

    If you run Emscripten with -v, it will print the full Clang command line it uses under the hood.