what_is_gdextension.rst 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. .. _doc_what_is_gdextension:
  2. What is GDExtension?
  3. ====================
  4. Introduction
  5. ------------
  6. **GDExtension** is a Godot-specific technology that lets the engine interact with
  7. native `shared libraries <https://en.wikipedia.org/wiki/Library_(computing)#Shared_libraries>`__
  8. at runtime. You can use it to run native code without compiling it with the engine.
  9. .. note:: GDExtension is *not* a scripting language and has no relation to
  10. :ref:`GDScript <doc_gdscript>`.
  11. Differences between GDExtension and C++ modules
  12. -----------------------------------------------
  13. You can use both GDExtension and :ref:`C++ modules <doc_custom_modules_in_cpp>` to
  14. run C or C++ code in a Godot project.
  15. They also both allow you to integrate third-party libraries into Godot. The one
  16. you should choose depends on your needs.
  17. .. warning::
  18. GDExtension is currently *experimental*, which means that we may
  19. break compatibility in order to fix major bugs or include critical features.
  20. Advantages of GDExtension
  21. ^^^^^^^^^^^^^^^^^^^^^^^^^
  22. Unlike modules, GDExtension doesn't require compiling the engine's source code,
  23. making it easier to distribute your work. It gives you access to most of the API
  24. available to GDScript and C#, allowing you to code game logic with full control
  25. regarding performance. It's ideal if you need high-performance code you'd like
  26. to distribute as an add-on in the :ref:`asset library <doc_what_is_assetlib>`.
  27. Also:
  28. - GDExtension is not limited to C and C++. Thanks to :ref:`third-party bindings
  29. <doc_what_is_gdnative_third_party_bindings>`, you can use it with many other
  30. languages.
  31. - You can use the same compiled GDExtension library in the editor and exported
  32. project. With C++ modules, you have to recompile all the export templates you
  33. plan to use if you require its functionality at runtime.
  34. - GDExtension only requires you to compile your library, not the whole engine.
  35. That's unlike C++ modules, which are statically compiled into the engine.
  36. Every time you change a module, you need to recompile the engine. Even with
  37. incremental builds, this process is slower than using GDExtension.
  38. Advantages of C++ modules
  39. ^^^^^^^^^^^^^^^^^^^^^^^^^
  40. We recommend :ref:`C++ modules <doc_custom_modules_in_cpp>` in cases where
  41. GDExtension isn't enough:
  42. - C++ modules provide deeper integration into the engine. GDExtension's access
  43. is not as deep as static modules.
  44. - You can use C++ modules to provide additional features in a project without
  45. carrying native library files around. This extends to exported projects.
  46. .. note::
  47. If you notice that specific systems are not accessible via GDExtension
  48. but are via custom modules, feel free to open an issue on the
  49. `godot-cpp repository <https://github.com/godotengine/godot-cpp>`__
  50. to discuss implementation options for exposing the missing functionality.
  51. Supported languages
  52. -------------------
  53. The Godot developers officially support the following language bindings for
  54. GDExtension:
  55. - C++ :ref:`(tutorial) <doc_gdextension_cpp_example>`
  56. .. note::
  57. There are no plans to support additional languages with GDExtension officially.
  58. That said, the community offers several bindings for other languages (see
  59. below).
  60. .. _doc_what_is_gdnative_third_party_bindings:
  61. The bindings below are developed and maintained by the community:
  62. .. Binding developers: Feel free to open a pull request to add your binding if it's well-developed enough to be used in a project.
  63. .. Please keep languages sorted in alphabetical order.
  64. - `D <https://github.com/godot-dlang/godot-dlang>`__
  65. - `Go <https://github.com/grow-graphics/gd>`__
  66. - `Nim <https://github.com/godot-nim/gdext-nim>`__
  67. - `Rust <https://github.com/godot-rust/gdext>`__
  68. - `Swift <https://github.com/migueldeicaza/SwiftGodot>`__
  69. .. note::
  70. Not all bindings mentioned here may be production-ready. Make sure to
  71. research options thoroughly before starting a project with one of those.
  72. Also, double-check whether the binding is compatible with the Godot version
  73. you're using.
  74. .. _doc_what_is_gdextension_version_compatibility:
  75. Version compatibility
  76. ---------------------
  77. Usually, GDExtensions targeting an earlier version of Godot will work in later
  78. minor versions, but not vice-versa. For example, a GDExtension targeting Godot 4.2
  79. should work just fine in Godot 4.3, but one targeting Godot 4.3 won't work in Godot 4.2.
  80. For this reason, when creating GDExtensions, you may want to target the lowest version of
  81. Godot that has the features you need, *not* the most recent version of Godot. This can
  82. save you from needing to create multiple builds for different versions of Godot.
  83. However, GDExtension is currently *experimental*, which means that we may
  84. break compatibility in order to fix major bugs or include critical features.
  85. For example, GDExtensions created for Godot 4.0 aren't compatible with Godot
  86. 4.1 (see :ref:`updating_your_gdextension_for_godot_4_1`).
  87. GDExtensions are also only compatible with engine builds that use the same
  88. level of floating-point precision the extension was compiled for. This means
  89. that if you use an engine build with double-precision floats, the extension must
  90. also be compiled for double-precision floats and use an ``extension_api.json``
  91. file generated by your custom engine build. See :ref:`doc_large_world_coordinates`
  92. for details.
  93. Generally speaking, if you build a custom version of Godot, you should generate an
  94. ``extension_api.json`` from it for your GDExtensions, because it may have some differences
  95. from official Godot builds.