compiling_for_linuxbsd.rst 16 KB

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