https://github.com/fjebaker/cppfront-to-wasm
Hello World example for compiling cppfront to WASM using either clang or zig.
https://github.com/fjebaker/cppfront-to-wasm
clang cpp cppfront llvm wasm zig zig-wasm
Last synced: about 1 month ago
JSON representation
Hello World example for compiling cppfront to WASM using either clang or zig.
- Host: GitHub
- URL: https://github.com/fjebaker/cppfront-to-wasm
- Owner: fjebaker
- License: mit
- Created: 2023-01-26T18:03:42.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-26T18:04:35.000Z (over 3 years ago)
- Last Synced: 2025-12-04T22:43:49.665Z (6 months ago)
- Topics: clang, cpp, cppfront, llvm, wasm, zig, zig-wasm
- Language: Makefile
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cppfront to WASM
This repository contains a tiny hello world example for compiling [cppfront](https://github.com/hsutter/cppfront) (aka C++ Syntax 2) to WASM, using clang or optionally [zig](https://ziglang.org/).
Requires that [cppfront](https://github.com/hsutter/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.
## Setup (no zig)
Install LLVM via Homebrew and link
```bash
brew install llvm \
&& echo 'export PATH="$(brew --prefix)/opt/llvm/bin:$PATH"' >> ~/.zshrc \
&& source ~/.zshrc
```
Download releases from [WebAssembly/wasi-sdk](https://github.com/WebAssembly/wasi-sdk/releases):
```bash
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):
```bash
mv lib/wasi $(brew --prefix)/Cellar/llvm/15.0.7_1/lib/clang/15.0.7/lib/ \
&& rm -d lib
```
Then
```bash
make
```
Run it with [bytecodealliance/wasmtime](https://github.com/bytecodealliance/wasmtime):
```bash
wasmtime cart.wasm
# Hello world from cppfront!
```
## Cool and nice and fast with zig
Use Zig target (none of the above required, only needs zig in `PATH`):
```bash
make zig
```
## Recommended tools
- [WebAssembly/wabt](https://github.com/WebAssembly/wabt)