compiling_for_web.rst 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.22+ <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::
  24. On Windows, make sure to escape backslashes of paths within the Emscripten
  25. configuration file as double backslashes ``\\`` or use Unix-style paths with a
  26. single forward slash ``/``.
  27. Open a terminal and navigate to the root directory of the engine source code.
  28. Then instruct SCons to build the JavaScript platform. Specify ``target`` as
  29. either ``release`` for a 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. By default, the :ref:`JavaScript singleton <doc_javascript_eval>` will be built
  33. into the engine. Since ``eval()`` calls can be a security concern, the
  34. ``javascript_eval`` option can be used to build without the singleton::
  35. scons platform=javascript tools=no target=release javascript_eval=no
  36. scons platform=javascript tools=no target=release_debug javascript_eval=no
  37. The engine will now be compiled to WebAssembly by Emscripten. Once finished,
  38. the resulting file will be placed in the ``bin`` subdirectory. Its name is
  39. ``godot.javascript.opt.zip`` for release or ``godot.javascript.opt.debug.zip``
  40. for debug.
  41. Finally, rename the zip archive to ``webassembly_release.zip`` for the
  42. release template::
  43. mv bin/godot.javascript.opt.zip bin/webassembly_release.zip
  44. And ``webassembly_debug.zip`` for the debug template::
  45. mv bin/godot.javascript.opt.debug.zip bin/webassembly_debug.zip
  46. Building per asm.js translation or LLVM backend
  47. -----------------------------------------------
  48. WebAssembly can be compiled in two ways: The default is to first compile to
  49. asm.js, a highly optimizable subset of JavaScript, using Emscripten's
  50. *fastcomp* fork of LLVM. This code is then translated to WebAssembly using a
  51. tool called ``asm2wasm``. Emscripten automatically takes care of both
  52. processes, we simply run SCons.
  53. The other method uses LLVM's WebAssembly backend. This backend is available
  54. starting with LLVM 8 or in development builds.
  55. Emscripten manages this process as well, so we just invoke SCons.
  56. In order to choose one of the two methods, the ``LLVM_ROOT`` variable in the
  57. Emscripten configuration file is used. If it points to a directory containing
  58. binaries of Emscripten's *fastcomp* fork of clang, ``asm2wasm`` is used.
  59. This is the default in a normal Emscripten installation. Otherwise,
  60. LLVM binaries built with the WebAssembly backend will be expected and
  61. the LLVM's WebAssembly backend is used.