The code within these folders represents the examples discussed in Chapter 10.
- Unless otherwise specified, all terminal commands should be run from within their example folder (e.g.
/compile-with-llvm
). - To remove existing built files, run the following command:
make clean
Each of the links below corresponds with a section of Chapter 10. Click to navigate to the section code.
Describes how to compile C/C++ files using LLVM instead of Emscripten. Ensure you cd
into /compile-with-llvm
before running any commands.
Run the following command to install webassembly
globally:
npm install -g webassembly
Once complete, ensure the installation was successful by running the following command:
wa
Run the following command to compile the C++ file using LLVM:
wa compile main.cpp -o main.wasm
Alternatively, you can run the following command:
make
Run the following command to start the example:
serve -l 8080
Navigate to http://127.0.0.1:8080/index.html
and ensure what you see matches the book.
Example application that uses Web Workers. Ensure you cd
into /parallel-wasm
before running any commands.
Run the following command to install the required dependencies:
npm install
Run the following command to build:
emcc -Os -s WASM=1 -s SIDE_MODULE=1 -s BINARYEN_ASYNC_COMPILATION=0 lib/add.c -o src/calc-add.wasm \
&& emcc -Os -s WASM=1 -s SIDE_MODULE=1 -s BINARYEN_ASYNC_COMPILATION=0 lib/subtract.c -o src/calc-subtract.wasm
Alternatively, you can run the following command:
make
Run the following command to start the application:
serve -l 8080 src
Navigate to http://127.0.0.1:8080/index.html
and ensure what you see matches the book.