Skip to content

DeShrike/c-wasm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

4f7d454 · Jul 30, 2023

History

10 Commits
Jul 29, 2023
Jul 30, 2023
Jul 30, 2023
Jul 29, 2023
Jul 30, 2023
Jul 29, 2023
Jul 29, 2023
Jul 30, 2023
Jul 29, 2023
Jul 30, 2023
Jul 30, 2023
Jul 30, 2023

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