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