Hands-On Game Development with WebAssembly
上QQ阅读APP看书,第一时间看更新

Installing Emscripten on Windows

I am going to keep this section brief because these instructions are subject to change. You can supplement these instructions with the official Emscripten download and install instructions found on the Emscripten website: https://emscripten.org/docs/getting_started/downloads.html.

We will need to download and build Emscripten from the emsdk source files on GitHub. First, we will walk through what to do on Windows.

Python 2.7.12 or higher is a prerequisite. If you do not have a version of Python higher than 2.7.12 installed, you will need to get the windows installer from python.org and install that first: https://www.python.org/downloads/windows/.

If you have installed Python and you are still getting errors telling you that Python is not found, you may need to add Python to your Windows PATH variable. For more information, refer to this tutorial:  https://www.pythoncentral.io/add-python-to-path-python-is-not-recognized-as-an-internal-or-external-command/.

If you have Git installed already, cloning the repository is relatively simple:

  1. Run the following command to clone the repository:
git clone https://github.com/emscripten-core/emsdk.git
  1. Wherever you run this command, it will create an emsdk directory. Enter that directory using the following:
cd emsdk

You may not have Git installed, in which case, the following steps will bring you up to speed:

  1. Go to the following URL in a web browser: https://github.com/emscripten-core/emsdk.
  2. You will see a green button on the right-hand side that says Clone or download. Download the ZIP file:
  1. Unzip the downloaded file to the c:\emsdk directory.
  2. Open up a Windows Command Prompt by typing cmd into the start menu and pressing Enter.
  3. From there, you can change to the c:\emsdk\emsdk-master directory by typing the following:
 cd \emsdk\emsdk-master

At this point, it does not matter whether you had Git installed or not. Let's move forward:

  1. Install emsdk from the source code running the following command:
emsdk install latest
  1. Then activate the latest emsdk:
emsdk activate latest
  1. Finally, set up our path and environment variables:
emsdk_env.bat
This last step will need to be rerun from your install directory every time you open a new command-line window. Unfortunately, it does not permanently set the Windows environment variables. Hopefully, that will change in the future.