compiling_for_web.rst 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. .. _doc_compiling_for_web:
  2. Compiling for the Web
  3. =====================
  4. .. highlight:: shell
  5. Requirements
  6. ------------
  7. To compile export templates for the Web, the following is required:
  8. - `Emscripten 1.37.9+ <http://emscripten.org/>`__: If the version available
  9. per package manager is not recent enough, the best alternative is to install
  10. using the `Emscripten SDK <http://kripken.github.io/emscripten-site/docs/gettng_started/downloads.html>`__
  11. (Install in a path without spaces, i.e. not in ``Program Files``)
  12. - `Python 2.7+ or Python 3.5+ <https://www.python.org/>`__
  13. - `SCons <http://www.scons.org>`__ build system
  14. Building export templates
  15. -------------------------
  16. Start a terminal and set the environment variable ``EMSCRIPTEN_ROOT`` to the
  17. installation directory of Emscripten:
  18. If you installed Emscripten via the Emscripten SDK, declare the variable with a
  19. path to the downloaded folder::
  20. export EMSCRIPTEN_ROOT=~/emsdk/emscripten/master
  21. If you installed Emscripten via package manager, the path can be retrieved with
  22. the ``em-config`` command::
  23. export EMSCRIPTEN_ROOT=`em-config EMSCRIPTEN_ROOT`
  24. On Windows you can set the environment variable in the system settings or in
  25. the command prompt::
  26. set EMSCRIPTEN_ROOT="C:\emsdk\emscripten\master"
  27. Now go to the root directory of the engine source code and instruct SCons to
  28. build the JavaScript platform. Specify ``target`` as either ``release`` for a
  29. release build or ``release_debug`` for a debug build::
  30. scons platform=javascript tools=no target=release
  31. scons platform=javascript tools=no target=release_debug
  32. The engine will now be compiled to WebAssembly by Emscripten. If all goes well,
  33. the resulting file will be placed in the ``bin`` subdirectory. Its name is
  34. ``godot.javascript.opt.zip`` for release or ``godot.javascript.opt.debug.zip``
  35. for debug.
  36. Finally, rename the zip archive to ``webassembly_release.zip`` for the
  37. release template::
  38. mv bin/godot.javascript.opt.zip bin/webassembly_release.zip
  39. And ``webassembly_debug.zip`` for the debug template::
  40. mv bin/godot.javascript.opt.debug.zip bin/webassembly_debug.zip
  41. Building per asm.js translation or LLVM backend
  42. -----------------------------------------------
  43. WebAssembly can be compiled in two ways: The default is to first compile to
  44. asm.js, a highly optimizable subset of JavaScript, using Emscripten's
  45. *fastcomp* fork of LLVM. This code is then translated to WebAssembly using a
  46. tool called ``asm2wasm``. Emscripten automatically takes care of both
  47. processes, we simply run SCons.
  48. The other method uses LLVM's WebAssembly backend. This backend is not yet
  49. available in release versions of LLVM, only in development builds built with
  50. ``LLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly``.
  51. Compiling with this backend outputs files in LLVM's ``.s`` format, which is
  52. translated into actual WebAssembly using a tool called ``s2wasm``.
  53. Emscripten manages these processes as well, so we just invoke SCons.
  54. In order to choose one of the two methods, the ``LLVM_ROOT`` variable in the
  55. Emscripten configuration file ``~/.emscripten`` is set. If it points to a
  56. directory containing binaries of Emscripten's *fastcomp* fork of clang,
  57. ``asm2wasm`` is used. This is the default in a normal Emscripten installation.
  58. Otherwise, LLVM binaries built with the WebAssembly backend will be expected
  59. and ``s2wasm`` is used. On Windows, make sure to escape backslashes of paths
  60. within this file as double backslashes ``\\`` or use Unix-style paths with
  61. a single forward slash ``/``.