Techfiora

WebAssembly – Getting Started with Wasm for Emscripten 

In order to translate code written in C or C++ into web assembly so that it can be executed in the browser, we need Emsrcipten as a compiler. In this chapter we will show you how to install Emscripten so that we can create a Hello World in C in the next chapter.

Installing Emscripten

To install Emscripten, the following steps from the installation instructions must be followed. First we clone the repo and go to the directory.

pip install diffusers transformers torch
pip install huggingface_hub

We then install the latest Software Development Kit (SDK):

# On Windows
emsdk install latest

# On Linux
./emsdk install latest

After installation, the SDK can be activated with the following command:

# On Windows
emsdk activate latest

# On Linux 
./emsdk activate latest

The following script can be executed to set the PATH and environment variables automatically:

# On Windows
emsdk_env.bat

# On Linux 
source ./emsdk_env.sh

After these steps you should be able to use Emscripten C and C++ code. In the next Chapter we will show you how to write a simple Hello World program in C. We will compile it into .wasm and run it in your browser.