create every day - 福野泰介の一日一創

Write in C language! The fast web with WebAssembly

2017/04/14 23:55:00
#js #web #english 

Chrome and Firefox support WebAssembly to make fast application on the web!
You can write your web application in C language also!
This is simple demo using shared memory on both JavaScript and WebAssembly.

"WebAssembly test" (src on GitHub)

To set up WebAssembly to your Mac (taking 2 hours and 20GB storage space!!)

1. binaryen (compiler for WebAssembly)

cd *** git clone cd binaryen cmake . && make

*** : your bin path
2. wabt (assembler for WebAssembly)

git clone --recursive cd wabt make cd ..

3. LLVM (takes long time and big storage space!)

git clone cd llvm/tools git clone cd ../projects git clone cd ../.. mkdir llvmtmp cd llvmtmp cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr/local -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly ../llvm make -j 8 sudo make install

4. edit PATH (.profile etc...)

export PATH=***/wabt/out/clang/Debug/:***/binaryen/bin/:$PATH

5. done! Let's make web an app in C!

#define SIZE 10 int mem[SIZE]; int* getMemory() { return mem; } int getMemorySize() { return SIZE; } int calc() { int sum = 0; for (int i = 0; i < SIZE; i++) { sum += mem[i]; } return sum; }

"WebAssembly test on GitHub"

この作品は「Creative Commons — CC BY 4.0」の下に提供されています。
CC BY 福野泰介 - Taisuke Fukuno / @taisukef / high-res profile image