compiling_for_web.rst 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.9+ <https://emscripten.org>`__.
  9. - `Python 3.5+ <https://www.python.org/>`__.
  10. - `SCons 3.0+ <https://www.scons.org>`__ build system.
  11. .. seealso:: To get the Godot source code for compiling, see
  12. :ref:`doc_getting_source`.
  13. 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 ``emcc`` is available in your PATH. This is
  18. usually configured by the Emscripten SDK, e.g. when invoking ``emsdk activate``
  19. and ``source ./emsdk_env.sh``/``emsdk_env.bat``.
  20. Open a terminal and navigate to the root directory of the engine source code.
  21. Then instruct SCons to build the JavaScript platform. Specify ``target`` as
  22. either ``release`` for a release build or ``release_debug`` for a debug build::
  23. scons platform=javascript tools=no target=release
  24. scons platform=javascript tools=no target=release_debug
  25. By default, the :ref:`JavaScript singleton <doc_javascript_eval>` will be built
  26. into the engine. Official export templates also have the JavaScript singleton
  27. enabled. Since ``eval()`` calls can be a security concern, the
  28. ``javascript_eval`` option can be used to build without the singleton::
  29. scons platform=javascript tools=no target=release javascript_eval=no
  30. scons platform=javascript tools=no target=release_debug javascript_eval=no
  31. The engine will now be compiled to WebAssembly by Emscripten. Once finished,
  32. the resulting file will be placed in the ``bin`` subdirectory. Its name is
  33. ``godot.javascript.opt.zip`` for release or ``godot.javascript.opt.debug.zip``
  34. for debug.
  35. Finally, rename the zip archive to ``webassembly_release.zip`` for the
  36. release template::
  37. mv bin/godot.javascript.opt.zip bin/webassembly_release.zip
  38. And ``webassembly_debug.zip`` for the debug template::
  39. mv bin/godot.javascript.opt.debug.zip bin/webassembly_debug.zip
  40. Threads and GDNative
  41. --------------------
  42. The default export templates do not include threads and GDNative support for
  43. performance and compatibility reasons. See the
  44. :ref:`export page <doc_javascript_export_options>` for more info.
  45. You can build the export templates using the option ``threads_enabled=yes`` or
  46. ``gdnative_enabled=yes`` to enable threads or GDNative support::
  47. scons platform=javascript tools=no threads_enabled=yes target=release
  48. scons platform=javascript tools=no threads_enabled=yes target=release_debug
  49. scons platform=javascript tools=no gdnative_enabled=yes target=release
  50. scons platform=javascript tools=no gdnative_enabled=yes target=release_debug
  51. Once finished, the resulting file will be placed in the ``bin`` subdirectory.
  52. Its name will have either the ``.threads`` or ``.gdnative`` suffix.
  53. Finally, rename the zip archives to ``webassembly_release_threads.zip`` and
  54. ``webassembly_release_gdnative.zip`` for the release template::
  55. mv bin/godot.javascript.opt.threads.zip bin/webassembly_threads_release.zip
  56. mv bin/godot.javascript.opt.gdnative.zip bin/webassembly_gdnative_release.zip
  57. And ``webassembly_debug_threads.zip`` and ``webassembly_debug_gdnative.zip`` for
  58. the debug template::
  59. mv bin/godot.javascript.opt.debug.threads.zip bin/webassembly_threads_debug.zip
  60. mv bin/godot.javascript.opt.debug.gdnative.zip bin/webassembly_gdnative_debug.zip
  61. Building the editor
  62. -------------------
  63. It is also possible to build a version of the Godot editor that can run in the
  64. browser. The editor version requires threads support and is not recommended
  65. over the native build. You can build the editor with::
  66. scons platform=javascript tools=yes threads_enabled=yes target=release_debug
  67. Once finished, the resulting file will be placed in the ``bin`` subdirectory.
  68. Its name will be ``godot.javascript.opt.tools.threads.zip``. You can upload the
  69. zip content to your web server and visit it with your browser to use the editor.
  70. Refer to the :ref:`export page <doc_javascript_export_options>` for the web
  71. server requirements.