Setting up our environment

To program in WebAssembly, we need to get the wat2wasm program on our machine. The best way to do this is to download the repository for the WebAssembly suite of programs and get them compiled for our computer. Follow these steps to do so:

  1. We need to get a program called CMake onto our system. For Linux/OS X, this just means going to https://cmake.org/download/ and running the installer. For those of you who are on Windows, this is a bit lengthier. Go to https://visualstudio.microsoft.com/vs/ and get Visual Studio. Make sure to get the C/C++ modules for it. With both CMake and Visual Studio on our machines, we can now move on and compile the WebAssembly suite of tools.
  2. Head to https://github.com/WebAssembly/wabt and clone to an easily accessible location.
  3. Open the CMake GUI tool. It should look similar to the following:

  1. For the source code, go to the wabt folder that we downloaded from GitHub.
  2. The location of the binaries should be in the build directory that we created in the wabt folder.
  3. With this, we can hit the Configure button. This should populate the panel in the middle of the screen.
  4. Now, just hit the Generate button. This should generate the files that we need to build our application.
  5. Finally, we will go into Visual Studio and build the project.
  6. Open Visual Studio and open the project from the File dropdown at the top left.
  7. Once the project is in, we can hit Build. This should build all of the binaries that we need for working with WebAssembly. The screen should look something like this:

If you are having trouble, the repository at https://github.com/WebAssembly/wabt contains some excellent documentation on how to get the build done. The preceding instructions try to streamline the build process, but it can be difficult to get these projects up and running.

Now that we have built out our binaries, let's make sure that we put them on our path so that we have easy access to them. On Windows, we can do the following:

  1. Go to the search bar and type path variables. The first option should allow us to set up our environment variables:

  1. Click on the bottom right option called Environment Variables...:

  1. For the bottom box, find the Path variable and click Edit...:

  1. Click on New and find the directory where all of the binaries are being held:

Once we've done this, we should be able to type wat2wasm into our command line and get the help documentation for the tool. Now, we are able to compile the text format of WebAssembly into a format that our browser expects!

Now that we've added the WebAssembly binary toolkit to our system and can compile/decompile WebAssembly programs, let's start writing our first program in WebAssembly!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.45.162