syrusakbary/clang - wapm
Wapm logo
search

The search results will appear here

syrusakbary/clangWASI

0.0.1 Public • Published 4 months ago17.5 MB

CLANG

Copy and paste to install this package
wapm install syrusakbary/clang

launchGithub (grade - call_split - error_outline - open issues/PRs)

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