compiling_for_web.rst 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.38.27+ <http://kripken.github.io/emscripten-site>`__: 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/getting_started/downloads.html>`__
  11. - `Python 2.7+ or Python 3.5+ <https://www.python.org/>`__
  12. - `SCons <https://www.scons.org>`__ build system
  13. .. seealso:: For a general overview of SCons usage for Godot, see
  14. :ref:`doc_introduction_to_the_buildsystem`.
  15. Building export templates
  16. -------------------------
  17. Before starting, confirm that the Emscripten configuration file exists and
  18. specifies all settings correctly. This file is available as ``~/.emscripten``
  19. on UNIX-like systems and ``%USERPROFILE%\.emscripten`` on Windows. It's usually
  20. written by the Emscripten SDK, e.g. when invoking ``emsdk activate latest``,
  21. or by your package manager. It's also created when starting Emscripten's
  22. ``emcc`` program if the file doesn't exist.
  23. .. attention:: On Windows, make sure to escape backslashes of paths within the Emscripten
  24. configuration file as double backslashes ``\\`` or use Unix-style paths with a
  25. single forward slash ``/``.
  26. Open a terminal and navigate to the root directory of the engine source code.
  27. Then instruct SCons to build the JavaScript platform. Specify ``target`` as
  28. either ``release`` for a release build or ``release_debug`` for a debug build::
  29. scons platform=javascript tools=no target=release
  30. scons platform=javascript tools=no target=release_debug
  31. By default, the :ref:`JavaScript singleton <doc_javascript_eval>` will be built
  32. into the engine. Since ``eval()`` calls can be a security concern, the
  33. ``javascript_eval`` option can be used to build without the singleton::
  34. scons platform=javascript tools=no target=release javascript_eval=no
  35. scons platform=javascript tools=no target=release_debug javascript_eval=no
  36. The engine will now be compiled to WebAssembly by Emscripten. Once finished,
  37. the resulting file will be placed in the ``bin`` subdirectory. Its name is
  38. ``godot.javascript.opt.zip`` for release or ``godot.javascript.opt.debug.zip``
  39. for debug.
  40. Finally, rename the zip archive to ``webassembly_release.zip`` for the
  41. release template::
  42. mv bin/godot.javascript.opt.zip bin/webassembly_release.zip
  43. And ``webassembly_debug.zip`` for the debug template::
  44. mv bin/godot.javascript.opt.debug.zip bin/webassembly_debug.zip
  45. Building per asm.js translation or LLVM backend
  46. -----------------------------------------------
  47. WebAssembly can be compiled in two ways: The default is to first compile to
  48. asm.js, a highly optimizable subset of JavaScript, using Emscripten's
  49. *fastcomp* fork of LLVM. This code is then translated to WebAssembly using a
  50. tool called ``asm2wasm``. Emscripten automatically takes care of both
  51. processes, we simply run SCons.
  52. The other method uses LLVM's WebAssembly backend. This backend is available
  53. starting with LLVM 8 or in development builds.
  54. Emscripten manages this process as well, so we just invoke SCons.
  55. In order to choose one of the two methods, the ``LLVM_ROOT`` variable in the
  56. Emscripten configuration file is used. If it points to a directory containing
  57. binaries of Emscripten's *fastcomp* fork of clang, ``asm2wasm`` is used.
  58. This is the default in a normal Emscripten installation. Otherwise,
  59. LLVM binaries built with the WebAssembly backend will be expected and
  60. the LLVM's WebAssembly backend is used.