Skip to content

How to build webassembly files with nothing other than standard Clang/llvm.

Notifications You must be signed in to change notification settings

PetterS/clang-wasm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Webassemly with only Clang 8+ (tested with 11, 14)

I did not find instructions for this anywhere online, so here they are. We can now build small wasm files with nothing other than Clang (e.g. Emscripten is not needed).

  1. Install Clang 8 or later. Linux packages are here.
  2. make
  3. To try the built wasm file, run python3 server.py.

Optional: To disassemble the wasm file, you can install wabt and run make wat.

Docker (not required)

The following command builds an ubuntu:18.04 image containing the dependencies needed to build the working example.

$ docker build -t clang-wasm-ubuntu:18.04 .

Then, you can mount the source files in a container running the image and follow the instructions above.

docker run --rm -it -v`pwd`:/opt/src -w /opt/src -p4242:4242 clang-wasm-ubuntu:18.04

root@74a067d2c9e6:/opt/src# make
.... <snip> ...
root@74a067d2c9e6:/opt/src# python3 server.py
serving at port 4242