compiling_for_linuxbsd.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. .. _doc_compiling_for_linuxbsd:
  2. Compiling for Linux, \*BSD
  3. ==========================
  4. .. highlight:: shell
  5. .. seealso::
  6. This page describes how to compile Linux editor and export template binaries from source.
  7. If you're looking to export your project to Linux instead, read :ref:`doc_exporting_for_linux`.
  8. Requirements
  9. ------------
  10. For compiling under Linux or other Unix variants, the following is
  11. required:
  12. - GCC 7+ or Clang 6+.
  13. - `Python 3.6+ <https://www.python.org/downloads/>`_.
  14. - `SCons 3.0+ <https://scons.org/pages/download.html>`_ build system.
  15. .. note::
  16. If your distribution uses Python 2 by default, or you are using a version of SCons prior to 3.1.2,
  17. you will need to change the version of Python that SCons uses by changing the shebang
  18. (the first line) of the SCons script file to ``#! /usr/bin/python3``.
  19. Use the command ``which scons`` to find the location of the SCons script file.
  20. - pkg-config (used to detect the development libraries listed below).
  21. - Development libraries:
  22. - X11, Xcursor, Xinerama, Xi and XRandR.
  23. - MesaGL.
  24. - ALSA.
  25. - PulseAudio.
  26. - *Optional* - libudev (build with ``udev=yes``).
  27. .. seealso::
  28. To get the Godot source code for compiling, see :ref:`doc_getting_source`.
  29. For a general overview of SCons usage for Godot, see :ref:`doc_introduction_to_the_buildsystem`.
  30. .. _doc_compiling_for_linuxbsd_oneliners:
  31. Distro-specific one-liners
  32. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  33. .. tabs::
  34. .. tab:: Alpine Linux
  35. ::
  36. apk add \
  37. scons \
  38. pkgconf \
  39. gcc \
  40. g++ \
  41. libx11-dev \
  42. libxcursor-dev \
  43. libxinerama-dev \
  44. libxi-dev \
  45. libxrandr-dev \
  46. mesa-dev \
  47. libexecinfo-dev \
  48. eudev-dev \
  49. alsa-lib-dev \
  50. pulseaudio-dev
  51. .. tab:: Arch Linux
  52. ::
  53. pacman -S --needed \
  54. scons \
  55. pkgconf \
  56. gcc \
  57. libxcursor \
  58. libxinerama \
  59. libxi \
  60. libxrandr \
  61. mesa \
  62. glu \
  63. libglvnd \
  64. alsa-lib \
  65. pulseaudio
  66. .. tab:: Debian/Ubuntu
  67. ::
  68. apt-get install \
  69. build-essential \
  70. scons \
  71. pkg-config \
  72. libx11-dev \
  73. libxcursor-dev \
  74. libxinerama-dev \
  75. libgl1-mesa-dev \
  76. libglu-dev \
  77. libasound2-dev \
  78. libpulse-dev \
  79. libudev-dev \
  80. libxi-dev \
  81. libxrandr-dev
  82. .. tab:: Fedora
  83. ::
  84. dnf install \
  85. scons \
  86. pkgconfig \
  87. libX11-devel \
  88. libXcursor-devel \
  89. libXrandr-devel \
  90. libXinerama-devel \
  91. libXi-devel \
  92. mesa-libGL-devel \
  93. mesa-libGLU-devel \
  94. alsa-lib-devel \
  95. pulseaudio-libs-devel \
  96. libudev-devel \
  97. gcc-c++ \
  98. libstdc++-static \
  99. libatomic-static
  100. .. tab:: FreeBSD
  101. ::
  102. pkg install \
  103. py37-scons \
  104. pkgconf \
  105. xorg-libraries \
  106. libXcursor \
  107. libXrandr \
  108. libXi \
  109. xorgproto libGLU \
  110. alsa-lib \
  111. pulseaudio
  112. .. tab:: Gentoo
  113. ::
  114. emerge -an \
  115. dev-util/scons \
  116. x11-libs/libX11 \
  117. x11-libs/libXcursor \
  118. x11-libs/libXinerama \
  119. x11-libs/libXi \
  120. media-libs/mesa \
  121. media-libs/glu \
  122. media-libs/alsa-lib \
  123. media-sound/pulseaudio
  124. .. tab:: Mageia
  125. ::
  126. urpmi \
  127. scons \
  128. task-c++-devel \
  129. pkgconfig \
  130. "pkgconfig(alsa)" \
  131. "pkgconfig(glu)" \
  132. "pkgconfig(libpulse)" \
  133. "pkgconfig(udev)" \
  134. "pkgconfig(x11)" \
  135. "pkgconfig(xcursor)" \
  136. "pkgconfig(xinerama)" \
  137. "pkgconfig(xi)" \
  138. "pkgconfig(xrandr)"
  139. .. tab:: OpenBSD
  140. ::
  141. pkg_add \
  142. python \
  143. scons \
  144. llvm
  145. .. tab:: openSUSE
  146. ::
  147. zypper install \
  148. scons \
  149. pkgconfig \
  150. libX11-devel \
  151. libXcursor-devel \
  152. libXrandr-devel \
  153. libXinerama-devel \
  154. libXi-devel \
  155. Mesa-libGL-devel \
  156. alsa-devel \
  157. libpulse-devel \
  158. libudev-devel \
  159. gcc-c++ \
  160. libGLU1
  161. .. tab:: NetBSD
  162. ::
  163. pkg_add \
  164. pkg-config \
  165. py37-scons
  166. .. hint::
  167. For audio support, you can optionally install ``pulseaudio``.
  168. .. tab:: Solus
  169. ::
  170. eopkg install -c \
  171. system.devel \
  172. scons \
  173. libxcursor-devel \
  174. libxinerama-devel \
  175. libxi-devel \
  176. libxrandr-devel \
  177. mesalib-devel \
  178. libglu \
  179. alsa-lib-devel \
  180. pulseaudio-devel
  181. Compiling
  182. ---------
  183. Start a terminal, go to the root dir of the engine source code and type:
  184. ::
  185. scons platform=linuxbsd
  186. .. note::
  187. Prior to Godot 4.0, the Linux/\*BSD target was called ``x11`` instead of
  188. ``linuxbsd``. If you are looking to compile Godot 3.x, make sure to use the
  189. `3.x branch of this documentation <https://docs.godotengine.org/en/3.6/development/compiling/compiling_for_x11.html>`__.
  190. If all goes well, the resulting binary executable will be placed in the
  191. "bin" subdirectory. This executable file contains the whole engine and
  192. runs without any dependencies. Executing it will bring up the Project
  193. Manager.
  194. .. note::
  195. If you wish to compile using Clang rather than GCC, use this command:
  196. ::
  197. scons platform=linuxbsd use_llvm=yes
  198. Using Clang appears to be a requirement for OpenBSD, otherwise fonts
  199. would not build.
  200. .. note:: If you are compiling Godot for production use, then you can
  201. make the final executable smaller and faster by adding the
  202. SCons options ``target=template_release production=yes``.
  203. If you are compiling Godot with GCC, you can make the binary
  204. even smaller and faster by adding the SCons option ``lto=full``.
  205. As link-time optimization is a memory-intensive process,
  206. this will require about 7 GB of available RAM while compiling.
  207. .. note:: If you want to use separate editor settings for your own Godot builds
  208. and official releases, you can enable
  209. :ref:`doc_data_paths_self_contained_mode` by creating a file called
  210. ``._sc_`` or ``_sc_`` in the ``bin/`` folder.
  211. Running a headless/server build
  212. -------------------------------
  213. To run in *headless* mode which provides editor functionality to export
  214. projects in an automated manner, use the normal build::
  215. scons platform=linuxbsd target=editor
  216. And then use the ``--headless`` command line argument::
  217. ./bin/godot.linuxbsd.editor.x86_64 --headless
  218. To compile a debug *server* build which can be used with
  219. :ref:`remote debugging tools <doc_command_line_tutorial>`, use::
  220. scons platform=linuxbsd target=template_debug
  221. To compile a *server* build which is optimized to run dedicated game servers,
  222. use::
  223. scons platform=linuxbsd target=template_release production=yes
  224. Building export templates
  225. -------------------------
  226. .. warning:: Linux binaries usually won't run on distributions that are
  227. older than the distribution they were built on. If you wish to
  228. distribute binaries that work on most distributions,
  229. you should build them on an old distribution such as Ubuntu 16.04.
  230. You can use a virtual machine or a container to set up a suitable
  231. build environment.
  232. To build Linux or \*BSD export templates, run the build system with the
  233. following parameters:
  234. - (32 bits)
  235. ::
  236. scons platform=linuxbsd target=template_release arch=x86_32
  237. scons platform=linuxbsd target=template_debug arch=x86_32
  238. - (64 bits)
  239. ::
  240. scons platform=linuxbsd target=template_release arch=x86_64
  241. scons platform=linuxbsd target=template_debug arch=x86_64
  242. Note that cross-compiling for the opposite bits (64/32) as your host
  243. platform is not always straight-forward and might need a chroot environment.
  244. To create standard export templates, the resulting files in the ``bin/`` folder
  245. must be copied to:
  246. ::
  247. $HOME/.local/share/godot/export_templates/<version>/
  248. and named like this (even for \*BSD which is seen as "Linux/X11" by Godot):
  249. ::
  250. linux_x11_32_debug
  251. linux_x11_32_release
  252. linux_x11_64_debug
  253. linux_x11_64_release
  254. However, if you are writing your custom modules or custom C++ code, you
  255. might instead want to configure your binaries as custom export templates
  256. here:
  257. .. image:: img/lintemplates.png
  258. You don't even need to copy them, you can just reference the resulting
  259. files in the ``bin/`` directory of your Godot source folder, so the next
  260. time you build, you automatically have the custom templates referenced.
  261. Using Clang and LLD for faster development
  262. ------------------------------------------
  263. You can also use Clang and LLD to build Godot. This has two upsides compared to
  264. the default GCC + GNU ld setup:
  265. - LLD links Godot significantly faster compared to GNU ld or gold. This leads to
  266. faster iteration times.
  267. - Clang tends to give more useful error messages compared to GCC.
  268. To do so, install Clang and the ``lld`` package from your distribution's package manager
  269. then use the following SCons command::
  270. scons platform=linuxbsd use_llvm=yes linker=lld
  271. After the build is completed, a new binary with a ``.llvm`` suffix will be
  272. created in the ``bin/`` folder.
  273. It's still recommended to use GCC for production builds as they can be compiled using
  274. link-time optimization, making the resulting binaries smaller and faster.
  275. If this error occurs::
  276. /usr/bin/ld: cannot find -l:libatomic.a: No such file or directory
  277. There are two solutions:
  278. - In your SCons command, add the parameter ``use_static_cpp=no``.
  279. - Follow `these instructions <https://github.com/ivmai/libatomic_ops#installation-and-usage>`__ to configure, build, and
  280. install ``libatomic_ops``. Then, copy ``/usr/lib/libatomic_ops.a`` to ``/usr/lib/libatomic.a``, or create a soft link
  281. to ``libatomic_ops`` by command ``ln -s /usr/lib/libatomic_ops.a /usr/lib/libatomic.a``. The soft link can ensure the
  282. latest ``libatomic_ops`` will be used without the need to copy it everytime when it is updated.
  283. Using mold for faster development
  284. ---------------------------------
  285. For even faster linking compared to LLD, you can use `mold <https://github.com/rui314/mold>`__.
  286. mold can be used with either GCC or Clang.
  287. As of January 2023, mold is not readily available in Linux distribution
  288. repositories, so you will have to install its binaries manually.
  289. - Download mold binaries from its `releases page <https://github.com/rui314/mold/releases/latest>`__.
  290. - Extract the ``.tar.gz`` file, then move the extraced folder to a location such as ``.local/share/mold``.
  291. - Add ``$HOME/.local/share/mold/bin`` to your user's ``PATH`` environment variable.
  292. For example, you can add the following line at the end of your ``$HOME/.bash_profile`` file:
  293. ::
  294. PATH="$HOME/.local/share/mold/bin:$PATH"
  295. - Open a new terminal (or run ``source "$HOME/.bash_profile"``),
  296. then use the following SCons command when compiling Godot::
  297. scons platform=linuxbsd linker=mold
  298. Using system libraries for faster development
  299. ---------------------------------------------
  300. `Godot bundles the source code of various third-party libraries. <https://github.com/godotengine/godot/tree/master/thirdparty>`__
  301. You can choose to use system versions of third-party libraries instead.
  302. This makes the Godot binary faster to link, as third-party libraries are
  303. dynamically linked. Therefore, they don't need to be statically linked
  304. every time you build the engine (even on small incremental changes).
  305. However, not all Linux distributions have packages for third-party libraries
  306. available (or they may not be up-to-date).
  307. Moving to system libraries can reduce linking times by several seconds on slow
  308. CPUs, but it requires manual testing depending on your Linux distribution. Also,
  309. you may not be able to use system libraries for everything due to bugs in the
  310. system library packages (or in the build system, as this feature is less
  311. tested).
  312. To compile Godot with system libraries, install these dependencies *on top* of the ones
  313. listed in the :ref:`doc_compiling_for_linuxbsd_oneliners`:
  314. +------------------+-----------------------------------------------------------------------------------------------------------+
  315. | **Fedora** | :: |
  316. | | |
  317. | | sudo dnf install embree3-devel enet-devel glslang-devel graphite2-devel harfbuzz-devel libicu-devel \ |
  318. | | libsquish-devel libtheora-devel libvorbis-devel libwebp-devel libzstd-devel mbedtls-devel \ |
  319. | | miniupnpc-devel |
  320. +------------------+-----------------------------------------------------------------------------------------------------------+
  321. After installing all required packages, use the following command to build Godot:
  322. .. NOTE: Some `builtin_` options aren't used here because they break the build as of January 2023
  323. (tested on Fedora 37).
  324. ::
  325. scons platform=linuxbsd builtin_embree=no builtin_enet=no builtin_freetype=no builtin_graphite=no builtin_harfbuzz=no builtin_libogg=no builtin_libpng=no builtin_libtheora=no builtin_libvorbis=no builtin_libwebp=no builtin_mbedtls=no builtin_miniupnpc=no builtin_pcre2=no builtin_zlib=no builtin_zstd=no
  326. You can view a list of all built-in libraries that have system alternatives by
  327. running ``scons -h``, then looking for options starting with ``builtin_``.
  328. .. warning::
  329. When using system libraries, the resulting library is **not** portable
  330. across Linux distributions anymore. Do not use this approach for creating
  331. binaries you intend to distribute to others, unless you're creating a
  332. package for a Linux distribution.
  333. Using Pyston for faster development
  334. -----------------------------------
  335. You can use `Pyston <https://www.pyston.org/>`__ to run SCons. Pyston is a JIT-enabled
  336. implementation of the Python language (which SCons is written in). It is currently
  337. only compatible with Linux. Pyston can speed up incremental builds significantly,
  338. often by a factor between 1.5× and 2×. Pyston can be combined with Clang and LLD
  339. to get even faster builds.
  340. - Download the `latest portable Pyston release <https://github.com/pyston/pyston/releases/latest>`__.
  341. - Extract the portable ``.tar.gz`` to a set location, such as ``$HOME/.local/opt/pyston/`` (create folders as needed).
  342. - Use ``cd`` to reach the extracted Pyston folder from a terminal,
  343. then run ``./pyston -m pip install scons`` to install SCons within Pyston.
  344. - To make SCons via Pyston easier to run, create a symbolic link of its wrapper
  345. script to a location in your ``PATH`` environment variable::
  346. ln -s ~/.local/opt/pyston/bin/scons ~/.local/bin/pyston-scons
  347. - Instead of running ``scons <build arguments>``, run ``pyston-scons <build arguments>``
  348. to compile Godot.
  349. If you can't run ``pyston-scons`` after creating the symbolic link,
  350. make sure ``$HOME/.local/bin/`` is part of your user's ``PATH`` environment variable.
  351. .. note::
  352. Alternatively, you can run ``python -m pip install pyston_lite_autoload``
  353. then run SCons as usual. This will automatically load a subset of Pyston's
  354. optimizations in any Python program you run. However, this won't bring as
  355. much of a performance improvement compared to installing "full" Pyston.