compiling_for_web.rst 4.3 KB

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