--Originally published at Python learning
Georgina González Enríquez
Sebastián Cedeño González
Web Applications Development Laboratory
Basic
- Imagine what kind of applications you can do using WebAssembly
Some applications that can be done using WebAssembly are interactive pages for a business or academic entity, game applications, or streaming of content.
- Do you see a future for WebAssembly?
Yes, because since it can be implemented along with web developing languages, it can bring together the advantages of the language WebAssembly is compiling, like C, with the advantages of web languages, like javascript.
Research
- Write a mini-tutorial for using WebAssembly with another language. You must write at least three simple examples.
Compile and run a hello world program in C
- Clone precompiled Toolchain repo to compile C to WebAssembly:
$ git clone https://github.com/emscripten-core/emsdk.git
$ cd emsdk
$ ./emsdk install latest
$ ./emsdk activate latest
2. In current command prompt, setup an Emscripten compiler environment (variables and directory entries):
$ source ./emsdk_env.sh –build=Release
3. Create our hello world program in C:
$ mkdir hello
$ cd hello
$ cat << EOF > hello.c
#include <stdio.h>
int main(int argc, char ** argv) {
printf(“Hello, world!\n”);
}
EOF
4. Compile our program to WebAssembly:
$ emcc hello.c -o hello.html
5. Serve compiled files over HTTP:
$ emrun –no_browser –port 8080 .
6. Open http://localhost:8080/hello.html in your browser. The result should display “Hello, World!”:
Reference: https://webassembly.org/getting-started/developers-guide/
Compile and run a hello world program in C++
Note: since the toolchain used in the previous lesson works also with c++, the steps are almost the same.
- Clone precompiled Toolchain repo to compile C to WebAssembly
$ git clone https://github.com/emscripten-core/emsdk.git
$ cd emsdk
$ ./emsdk install latest
$ ./emsdk activate latest
2. In current command prompt, setup an Emscripten compiler environment (variables Continue reading "Laboratory WebAssembly"