Skip to content

DeShrike/c-wasm

Repository files navigation

Compile C to WebAssembly Experiment

Dependencies

  • LLVM - at least version 8
  • WABT
  • cmake - to build WABT, at least version 3.16

Getting started

Tested on Ubuntu 18.04.1 LTS

Install dependencies, see below.

Clone this repo and build:

$ git clone https://github.com/DeShrike/c-wasm.git
$ cd c-wasm
$ ./build.sh

Browser

Start a local webserver:

$ python3 -m http.server 8000

Point your browser to http://localhost:8000/index.html

Screenshot

NodeJS

Tested with v16.20.1

$ node node-app.js

Install LLVM

$ sudo apt-get install llvm-8 clang-8 lld-8

Build cmake

$ mkdir ~/temp
$ cd ~/temp
$ wget https://cmake.org/files/v3.16/cmake-3.16.0.tar.gz
$ tar -xzvf cmake-3.16.0.tar.gz
$ cd cmake-3.16.0/
$ ./bootstrap
$ make -j$(nproc)
$ sudo make install
$ cmake --version

Clone and build WABT

$ git clone --recursive https://github.com/WebAssembly/wabt
$ cd wabt
$ git submodule update --init
$ mkdir build
$ cd build
$ cmake ..
$ cmake --build
$ sudo make install

Usefull commands

$ wasm-objdump -x main.o
$ wasm2wat main.wasm