ggokka / helloworld-webassembly

A quick documented hello world app using webassembly, with C as the compile source

Home Page:https://dariusstrasel.github.io/helloworld-webassembly/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

helloworld-webassembly

Made posibble by: https://webassembly.org/getting-started/developers-guide/

Summary: This project contains the output from the getting started guide in the above link. I had to setup my environment for this, and so I will document the pre-reqs in addition to compilation steps.

General Pre-Reqs: Git, CMake, Host system compiler, python

Tool Chain Pre-Requisites:

choco install cmake

Installing the tool chain (Using c/c++)

git clone https://github.com/juj/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest

Entering the compiler environment:

source ./emsdk_env.sh --build=Release

Compiling a webassembly program:

mkdir hello
cd hello

touch hello.c

Use your preferred text editor to enter the following:

#include <stdio.h>
int main(int argc, char ** argv) {
  printf("Hello, world!\n");
}

To compile into webassebly, run the following:

emcc hello.c -s WASM=1 -o hello.html

emcc: emscriptem compiler executable
hello.c: Your c or c++ source file
-s WASM=1: linker flag which tells emcc to produce wasm instead of asm.js
-o hello.html: flag which tells emcc to produce an html file in addition to the necessary files

To verify your output, run a webserver in the current directory. emcc provides a command for us:

emrun --no_browser --port 8080 .

About

A quick documented hello world app using webassembly, with C as the compile source

https://dariusstrasel.github.io/helloworld-webassembly/


Languages

Language:HTML 50.3%Language:JavaScript 49.7%Language:C 0.0%