compiling_with_mono.rst 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. .. _doc_compiling_with_mono:
  2. Compiling with Mono
  3. ===================
  4. .. highlight:: shell
  5. Requirements
  6. ------------
  7. - Mono 5.12.0 or greater
  8. - MSBuild
  9. - pkg-config
  10. Environment variables
  11. ---------------------
  12. By default, SCons will try to find Mono in the Windows Registry on Windows or via ``pkg-config`` on other platforms. You can specify a different installation directory by using the following environment variables for the respective ``bits`` option: ``MONO32_PREFIX`` and ``MONO64_PREFIX``.
  13. The specified directory must contain the subdirectories ``bin``, ``include``, and ``lib``.
  14. Enable the Mono module
  15. ----------------------
  16. By default, the mono module is disabled for builds. To enable it you can pass the option ``module_mono_enabled=yes`` to your SCons command.
  17. Generate the glue
  18. -------------------
  19. The glue sources are the wrapper functions that will be called by managed methods. These source files must be generated before building your final binaries. In order to generate them, first, you must build a temporary Godot binary with the options ``tools=yes`` and ``mono_glue=no``:
  20. ::
  21. scons p=<platform> tools=yes module_mono_enabled=yes mono_glue=no
  22. After the build finishes, you need to run the compiled executable with the parameter ``--generate-mono-glue`` followed by the path to an output directory. This path must be ``modules/mono/glue`` in the Godot directory.
  23. ::
  24. <godot_binary> --generate-mono-glue modules/mono/glue
  25. This command will tell Godot to generate the file ``modules/mono/glue/mono_glue.gen.cpp``.
  26. Once this file is generated, you can build Godot for all the desired targets without the need to repeat this process.
  27. ``<godot_binary>`` refers to the tools binary you compiled above with the Mono module enabled.
  28. Its exact name will differ based on your system and configuration, but should be of the form ``bin/godot.<platform>.tools.<bits>.mono``, e.g. ``bin/godot.x11.tools.64.mono`` or ``bin/godot.windows.tools.64.exe``.
  29. Be especially aware of the **.mono** suffix! If you compiled Godot without Mono support previously, you might have similarly named binaries without this suffix which can't be used to generate the Mono glue.
  30. Notes
  31. ^^^^^
  32. - **Do not** build your final binaries with ``mono_glue=no``. This disables C# scripting. This option must be used only for the temporary binary that will generate the glue. Godot will print a warning at startup if it was built without the glue sources.
  33. - The glue sources must be regenerated every time the ClassDB bindings changes. That is, for example, when a new method is added to ClassDB or one of the parameter of such a method changes. Godot will print an error at startup if there is an API mismatch between ClassDB and the glue sources.
  34. Rebuild with Mono glue
  35. ----------------------
  36. Once you have generated the Mono glue, you can build the final binary with ``mono_glue=yes``.
  37. It's the default value for ``mono_glue`` so you can also omit it. You can build the Mono-enabled editor:
  38. ::
  39. scons p=<platform> tools=yes module_mono_enabled=yes mono_glue=yes
  40. And Mono-enabled export templates:
  41. ::
  42. scons p=<platform> tools=no module_mono_enabled=yes mono_glue=yes
  43. Examples
  44. --------
  45. Example (Windows)
  46. ^^^^^^^^^^^^^^^^^
  47. ::
  48. # Build temporary binary
  49. scons p=windows tools=yes module_mono_enabled=yes mono_glue=no
  50. # Generate glue sources
  51. bin\godot.windows.tools.64.mono --generate-mono-glue modules/mono/glue
  52. ### Build binaries normally
  53. # Editor
  54. scons p=windows target=release_debug tools=yes module_mono_enabled=yes
  55. # Export templates
  56. scons p=windows target=debug tools=no module_mono_enabled=yes
  57. scons p=windows target=release tools=no module_mono_enabled=yes
  58. Example (X11)
  59. ^^^^^^^^^^^^^
  60. ::
  61. # Build temporary binary
  62. scons p=x11 tools=yes module_mono_enabled=yes mono_glue=no
  63. # Generate glue sources
  64. bin/godot.x11.tools.64.mono --generate-mono-glue modules/mono/glue
  65. ### Build binaries normally
  66. # Editor
  67. scons p=x11 target=release_debug tools=yes module_mono_enabled=yes
  68. # Export templates
  69. scons p=x11 target=debug tools=no module_mono_enabled=yes
  70. scons p=x11 target=release tools=no module_mono_enabled=yes
  71. If everything went well, apart from the normal output, SCons should have also built the *GodotSharpTools.dll* assembly and copied it together with the mono runtime shared library to the ``bin`` subdirectory.
  72. Command-line options
  73. --------------------
  74. The following is the list of command-line options available when building with the mono module:
  75. - **module_mono_enabled**: Build Godot with the mono module enabled (yes|no)
  76. default: no
  77. - **mono_glue**: Whether to include the glue source files in the build and define `MONO_GLUE_DISABLED` as a preprocessor macro (yes|no)
  78. default: yes
  79. - **xbuild_fallback**: Whether to fallback to xbuild if MSBuild is not available (yes|no)
  80. default: no
  81. - **mono_static**: Whether to link the mono runtime statically (yes|no)
  82. default: no
  83. - **mono_assemblies_output_dir**: Path to the directory where all the managed assemblies will be copied to. The '#' token indicates de top of the source directory, the directory in which SConstruct is located
  84. default: #bin