build.rst 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. Build from source
  2. ==================
  3. .. image:: https://github.com/kovidgoyal/kitty/workflows/CI/badge.svg
  4. :alt: Build status
  5. :target: https://github.com/kovidgoyal/kitty/actions?query=workflow%3ACI
  6. .. note::
  7. If you just want to test the latest changes to kitty, you don't need to build
  8. from source. Instead install the :ref:`latest nightly build <nightly>`.
  9. .. highlight:: sh
  10. |kitty| is designed to run from source, for easy hack-ability. All you need to
  11. get started is a C compiler and the `go compiler
  12. <https://go.dev/doc/install>`__. After installing those, run the following commands::
  13. git clone https://github.com/kovidgoyal/kitty.git && cd kitty
  14. ./dev.sh build
  15. That's it, kitty will be built from source, magically. You can run it as
  16. :file:`kitty/launcher/kitty`.
  17. This works, because the :code:`./dev.sh build` command downloads all the major
  18. dependencies of kitty as pre-built binaries for your platform and builds kitty
  19. to use these rather than system libraries. The few required system libraries
  20. are mostly X11 and DBUS on Linux, as can be seen in the `linux-dev
  21. <https://github.com/kovidgoyal/kitty/blob/master/.github/workflows/ci.yml>`__
  22. CI job.
  23. If you make changes to kitty code, simply re-run :code:`./dev.sh build`
  24. to build kitty with your changes.
  25. .. note::
  26. If you plan to run kitty from source long-term, there are a couple of
  27. caveats to be aware of. You should occasionally run ``./dev.sh deps``
  28. to have the dependencies re-downloaded as they are updated periodically.
  29. Also, the built kitty executable assumes it will find source in whatever
  30. directory you first ran :code:`./dev.sh build` in. If you move/rename the
  31. directory, run :code:`make clean && ./dev.sh build`. You should also create
  32. symlinks to the :file:`kitty` and :file:`kitten` binaries from somewhere
  33. in your PATH so that they can be conveniently launched.
  34. .. note::
  35. On macOS, you can use :file:`kitty/launcher/kitty.app` to run kitty as well,
  36. but note that this is an unsigned kitty.app so some functionality such as
  37. notifications will not work as Apple disallows this. If you need this
  38. functionality, you can try signing the built :file:`kitty.app` with a self
  39. signed certificate, see for example, `here
  40. <https://stackoverflow.com/questions/27474751/how-can-i-codesign-an-app-without-being-in-the-mac-developer-program/27474942>`__.
  41. Building in debug mode
  42. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  43. The following will build with debug symbols::
  44. ./dev.sh build --debug
  45. To build with sanitizers and debug symbols::
  46. ./dev.sh build --debug --sanitize
  47. For more help on the various options supported by the build script::
  48. ./dev.sh build -h
  49. Building the documentation
  50. -------------------------------------
  51. To have the kitty documentation available locally, run::
  52. ./dev.sh deps -for-docs && ./dev.sh docs
  53. To develop the docs, with live reloading, use::
  54. ./dev.sh deps -for-docs && ./dev.sh docs -live-reload
  55. Dependencies
  56. ----------------
  57. These dependencies are needed when building against system libraries only.
  58. Run-time dependencies:
  59. * ``python`` >= 3.8
  60. * ``harfbuzz`` >= 2.2.0
  61. * ``zlib``
  62. * ``libpng``
  63. * ``liblcms2``
  64. * ``libxxhash``
  65. * ``openssl``
  66. * ``freetype`` (not needed on macOS)
  67. * ``fontconfig`` (not needed on macOS)
  68. * ``libcanberra`` (not needed on macOS)
  69. * ``libsystemd`` (optional, not needed on non systemd systems)
  70. * ``ImageMagick`` (optional, needed to display uncommon image formats in the terminal)
  71. Build-time dependencies:
  72. * ``gcc`` or ``clang``
  73. * ``simde``
  74. * ``go`` >= _build_go_version (see :file:`go.mod` for go packages used during building)
  75. * ``pkg-config``
  76. * Symbols NERD Font Mono either installed system-wide or placed in :file:`fonts/SymbolsNerdFontMono-Regular.ttf`
  77. * For building on Linux in addition to the above dependencies you might also
  78. need to install the following packages, if they are not already installed by
  79. your distro:
  80. - ``libdbus-1-dev``
  81. - ``libxcursor-dev``
  82. - ``libxrandr-dev``
  83. - ``libxi-dev``
  84. - ``libxinerama-dev``
  85. - ``libgl1-mesa-dev``
  86. - ``libxkbcommon-x11-dev``
  87. - ``libfontconfig-dev``
  88. - ``libx11-xcb-dev``
  89. - ``liblcms2-dev``
  90. - ``libssl-dev``
  91. - ``libpython3-dev``
  92. - ``libxxhash-dev``
  93. - ``libsimde-dev``
  94. Build and run from source with Nix
  95. -------------------------------------------
  96. On NixOS or any other Linux or macOS system with the Nix package manager
  97. installed, execute `nix-shell
  98. <https://nixos.org/guides/nix-pills/developing-with-nix-shell.html>`__ to create
  99. the correct environment to build kitty or use ``nix-shell --pure`` instead to
  100. eliminate most of the influence of the outside system, e.g. globally installed
  101. packages. ``nix-shell`` will automatically fetch all required dependencies and
  102. make them available in the newly spawned shell.
  103. Then proceed with ``make`` or ``make app`` according to the platform specific
  104. instructions above.
  105. .. _packagers:
  106. Notes for Linux/macOS packagers
  107. ----------------------------------
  108. The released |kitty| source code is available as a `tarball`_ from
  109. `the GitHub releases page <https://github.com/kovidgoyal/kitty/releases>`__.
  110. While |kitty| does use Python, it is not a traditional Python package, so please
  111. do not install it in site-packages.
  112. Instead run::
  113. make linux-package
  114. This will install |kitty| into the directory :file:`linux-package`. You can run
  115. |kitty| with :file:`linux-package/bin/kitty`. All the files needed to run kitty
  116. will be in :file:`linux-package/lib/kitty`. The terminfo file will be installed
  117. into :file:`linux-package/share/terminfo`. Simply copy these files into
  118. :file:`/usr` to install |kitty|. In other words, :file:`linux-package` is the
  119. staging area into which |kitty| is installed. You can choose a different staging
  120. area, by passing the ``--prefix`` argument to :file:`setup.py`.
  121. You should probably split |kitty| into three packages:
  122. :code:`kitty-terminfo`
  123. Installs the terminfo file
  124. :code:`kitty-shell-integration`
  125. Installs the shell integration scripts (the contents of the
  126. shell-integration directory in the kitty source code), probably to
  127. :file:`/usr/share/kitty/shell-integration`
  128. :code:`kitty`
  129. Installs the main program
  130. This allows users to install the terminfo and shell integration files on
  131. servers into which they ssh, without needing to install all of |kitty|. The
  132. shell integration files **must** still be present in
  133. :file:`lib/kitty/shell-integration` when installing the kitty main package as
  134. the kitty program expects to find them there.
  135. .. note::
  136. You need a couple of extra dependencies to build linux-package. :file:`tic`
  137. to compile terminfo files, usually found in the development package of
  138. :file:`ncurses`. Also, if you are building from a git checkout instead of the
  139. released source code tarball, you will need to install the dependencies from
  140. :file:`docs/requirements.txt` to build the kitty documentation. They can be
  141. installed most easily with ``python -m pip -r docs/requirements.txt``.
  142. This applies to creating packages for |kitty| for macOS package managers such as
  143. Homebrew or MacPorts as well.
  144. Cross compilation
  145. -------------------
  146. While cross compilation is neither officially supported, nor recommended, as it
  147. means the test suite cannot be run for the cross compiled build, there is some
  148. support for cross compilation. Basically, run::
  149. make prepare-for-cross-compile
  150. Then setup the cross compile environment (CC, CFLAGS, PATH, etc.) and run::
  151. make cross-compile
  152. This will create the cross compiled build in the :file:`linux-package`
  153. directory.