Skip to content

Instantly share code, notes, and snippets.

@halferty
Created September 19, 2017 01:30
Show Gist options
  • Save halferty/5b43d0e09df8e7e54344b4022e558236 to your computer and use it in GitHub Desktop.
Save halferty/5b43d0e09df8e7e54344b4022e558236 to your computer and use it in GitHub Desktop.
Compile C++ to webassembly. Uses LLVM, binaryen, and wabt. This sequence of commands is ridiculous, but if you want the memory buffer exported from your C++ code, you'll need this.
#!/bin/bash
/Users/ehalferty/objc/build/bin/clang++ -emit-llvm --target=wasm32 -Oz src/cxx/test.cxx -c -o src/cxx/test.ll
llc src/cxx/test.ll -march=wasm32 -filetype=asm -o src/cxx/test.s
s2wasm src/cxx/test.s > src/cxx/test.wat
wat2wasm src/cxx/test.wat -o src/wasm/test.wasm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment