build.rst 7.2 KB

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