This repository contains a tiny hello world example for compiling cppfront (aka C++ Syntax 2) to WASM, using clang or optionally zig.
Requires that cppfront is in the path. The Makefile also needs to be modified at the top to point the include directory for cppfront to the right place.
Install LLVM via Homebrew and link
brew install llvm \
&& echo 'export PATH="$(brew --prefix)/opt/llvm/bin:$PATH"' >> ~/.zshrc \
&& source ~/.zshrc
Download releases from WebAssembly/wasi-sdk:
wget "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sysroot-19.0.tar.gz" \
&& wget "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/libclang_rt.builtins-wasm32-wasi-19.0.tar.gz" \
&& tar xf wasi-sysroot-19.0.tar.gz \
&& tar xf libclang_rt.builtins-wasm32-wasi-19.0.tar.gz
Move the lib/wasi
directory extracted to clang lib (note: versions may differ):
mv lib/wasi $(brew --prefix)/Cellar/llvm/15.0.7_1/lib/clang/15.0.7/lib/ \
&& rm -d lib
Then
make
Run it with bytecodealliance/wasmtime:
wasmtime cart.wasm
# Hello world from cppfront!
Use Zig target (none of the above required, only needs zig in PATH
):
make zig