syrusakbary/clang-old

wasi

Public
wasmer run syrusakbary/clang-old

Clang in WASM

This repo demonstrates how to run clang & it's linker using only WebAssembly and Wasmer.

This repo is showcasing the great work from Ben Smith exposed in his CppCon 2019 WebAssembly talk.

The WebAssembly binaries are copied from Ben's fork of llvm-project.

Compile the C file to a WASM WASI file

First, clone this repo:

git clone https://github.com/wapm-packages/clang.git
cd clang

Then you will need to create a source file example.c, so we can compile it to WebAssembly.

Note: You can take the source from here.

# Compile example.c to an object file (example.o)
wapm run clang --dir=. -- -cc1 -triple wasm32-unkown-wasi -isysroot /sys -internal-isystem /sys/include -emit-obj -o ./example.o ./example.c

# Compile example.o to example.wasm
wapm run wasm-ld --dir=. -- -L/sys/lib/wasm32-wasi /sys/lib/wasm32-wasi/crt1.o ./example.o -lc -o ./example.wasm

And last, but not least... run it with Wasmer!

wasmer run example.wasm

CLANG


Github