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

Viewed 1909

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 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. Thank you so much for your time!!

1 Answers

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 also add 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 its uses under the hood.

Related