compiling_for_linuxbsd.rst 17 KB

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