compiling_for_web.rst 4.0 KB

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