Get Involved/development/Set up a development environment: Difference between revisions

From KDE Community Wiki
(→‎Set up kdesrc-build / kde-builder: Do not assume that project is going to be installed in the ~/kde/src dir, user may have several configurations and want to use script still. Also no need to repeat things. The readme describes installation variants already.)
(Now when kde-builder is fully ported, it is safe to switch from kdesrc-build)
Line 1: Line 1:
{{Info|'''Everything on this page only needs to be done once.''' Once you've done it, your development environment is set up and you can use it to submit patches and develop KDE Software!}}
{{Info|'''Everything on this page only needs to be done once.''' Once you've done it, your development environment is set up and you can use it to submit patches and develop KDE Software!}}


{{Note|This procedure will set up kdesrc-build for Qt6 and KDE Frameworks 6.<br/>
{{Note|This procedure will set up kde-builder.}}
Setting up kdesrc-build for Qt5 and KDE Frameworks 5 is an [[Get_Involved/development/More|advanced topic]].}}


Source code for KDE software lives on [https://invent.kde.org KDE Invent]. But before you can work on it, you'll need to set up a '''development environment''': a set of tools that allows you to access and edit the source code, compile it into a form that the computer can run, and deploy it to a safe location. We will now go through the process of setting one up. To accomplish these tasks, you will need to enter commands using a terminal program, such as KDE's [https://apps.kde.org/konsole Konsole].
Source code for KDE software lives on [https://invent.kde.org KDE Invent]. But before you can work on it, you'll need to set up a '''development environment''': a set of tools that allows you to access and edit the source code, compile it into a form that the computer can run, and deploy it to a safe location. We will now go through the process of setting one up. To accomplish these tasks, you will need to enter commands using a terminal program, such as KDE's [https://apps.kde.org/konsole Konsole].
Line 8: Line 7:
If you're not familiar with the command line interface, you can [[Get_Involved/development/Learn#Unix_command_line|find tutorials here]]. However, advanced command-line skills are not required, and you will learn what you need along the way!
If you're not familiar with the command line interface, you can [[Get_Involved/development/Learn#Unix_command_line|find tutorials here]]. However, advanced command-line skills are not required, and you will learn what you need along the way!


If you're a visual learner, we also provide [[Get_Involved/development/Video|video tutorials about setting up kdesrc-build]].
== Install basic tools ==


== Install basic tools ==
First you will need to use your operating system's package manager to install some basic tools:
First you will need to use your operating system's package manager to install some basic tools:
* KDE Neon/Kubuntu/Ubuntu/Debian: <code>sudo apt update && sudo apt install git</code>
* KDE Neon/Kubuntu/Ubuntu/Debian: <code>sudo apt update && sudo apt install git</code>
Line 18: Line 16:


== Configure Git ==
== Configure Git ==
We need to set your authorship information properly so that any changes you make can be properly attributed to you:
We need to set your authorship information properly so that any changes you make can be properly attributed to you:
{{Input|1=<nowiki>
{{Input|1=<nowiki>
Line 28: Line 27:
Next, in order to authenticate yourself when pushing code changes, you need to add an ssh key to your GitLab profile as [https://invent.kde.org/help/user/ssh.md described here].
Next, in order to authenticate yourself when pushing code changes, you need to add an ssh key to your GitLab profile as [https://invent.kde.org/help/user/ssh.md described here].


== Set up kdesrc-build / kde-builder ==
== Set up kde-builder ==


{{ic|kdesrc-build}} is the official KDE meta-build-system tool. It is used to manage the building of many software repositories in an automated fashion. Its primary purpose is to '''manage dependencies'''. Every software has dependencies: other pieces of software that provide lower-level functionality they rely on. In order to compile any piece of software, its dependencies must be available.
{{ic|kde-builder}} is the official KDE meta-build-system tool. It is used to manage the building of many software repositories in an automated fashion. Its primary purpose is to '''manage dependencies'''. Every software has dependencies: other pieces of software that provide lower-level functionality they rely on. In order to compile any piece of software, its dependencies must be available.


{{Info|'''kdesrc-build''' is planned to be replaced by the new utility '''[https://invent.kde.org/ashark/kde-builder kde-builder]'''. It is currently under testing. It has the same syntax and behavior as the kdesrc-build, so the wiki instructions you found here can be applied directly, except the fact that you change the executable name. The only difference is the installation procedure.
{{Info|'''[https://invent.kde.org/ashark/kde-builder kde-builder]''' is a successor of '''kdesrc-build'''. It has the same syntax and behavior, so the wiki instructions you found here can be applied directly, except the fact that you change the executable name. The only difference is the installation procedure.
Please try to use it and provide a feedback (by using gitlab issues or in matrix chat) in case you have some problems.|KDE Builder testing}}
}}


KDE software has two types of dependencies: dependencies on other pieces of KDE software, and dependencies on 3rd-party software. For example, the KDE application KCalc depends on more than 20 other KDE git repositories as well as the Qt toolkit.
KDE software has two types of dependencies: dependencies on other pieces of KDE software, and dependencies on 3rd-party software. For example, the KDE application KCalc depends on more than 20 other KDE git repositories as well as the Qt toolkit.


Some Linux distributions do not provide development packages for [https://develop.kde.org/products/frameworks/ KDE Frameworks] and of other libraries that are up-to-date enough for us to build from the "main" branch of the KDE git repositories (the branch where the development of the next software versions takes place), so we use {{ic|kdesrc-build}} to compile them ourselves. The goal is to avoid using KDE binaries, KDE libraries and other KDE files from the operating system where possible (in the Linux case, these files reside in the {{ic|/usr}} directory).
Some Linux distributions do not provide development packages for [https://develop.kde.org/products/frameworks/ KDE Frameworks] and of other libraries that are up-to-date enough for us to build from the "main" branch of the KDE git repositories (the branch where the development of the next software versions takes place), so we use {{ic|kde-builder}} to compile them ourselves. The goal is to avoid using KDE binaries, KDE libraries and other KDE files from the operating system where possible (in the Linux case, these files reside in the {{ic|/usr}} directory).


=== Installation ===
=== Installation ===
Install {{ic|kde-builder}}: https://invent.kde.org/ashark/kde-builder#installation


Install {{ic|kdesrc-build}}: https://invent.kde.org/sdk/kdesrc-build#install-kdesrc-build
Install {{ic|kdesrc-build}}: https://invent.kde.org/sdk/kdesrc-build#install-kdesrc-build
Install {{ic|kde-builder}}: https://invent.kde.org/ashark/kde-builder#installation


If you are using Arch Linux, you would prefer to install and update the script via AUR package:
If you are using Arch Linux, you would prefer to install and update the script via AUR package:
* [https://aur.archlinux.org/packages/kde-builder-git kde-builder-git]
* [https://aur.archlinux.org/packages/kdesrc-build-git kdesrc-build-git]
* [https://aur.archlinux.org/packages/kdesrc-build-git kdesrc-build-git]
* [https://aur.archlinux.org/packages/kde-builder-git kde-builder-git]


=== Setup ===
=== Setup ===
Line 65: Line 64:


{{bc|
{{bc|
./kdesrc-build --initial-setup
./kde-builder --initial-setup
source ~/.bashrc
source ~/.bashrc
}}
}}


The step {{ic|./kdesrc-build --initial-setup}} above installs the Linux binary packages that are needed such that {{ic|kdesrc-build}} can build all of the KDE Frameworks.
The step {{ic|./kde-builder --initial-setup}} above installs the Linux binary packages that are needed such that {{ic|kde-builder}} can build all of the KDE Frameworks.
 
{{Note|If you use zsh and you selected yes for auto-completions during {{ic|kdesrc-build --initial-setup}}, add the following two lines to {{ic|~/.zshrc}} if these two lines are not already there:
{{bc|autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit}}
If you use fish but only have it set up as an interactive shell (instead of a login shell set with chsh), in order for kdesrc-build to ask you whether you want to update fish, you will need to run initial setup while setting the SHELL environment variable to fish manually instead:
{{ic|1=SHELL=fish ./kdesrc-build --initial-setup}}
}}


For more details about installing the needed Linux binary packages, see [[Get_Involved/development/Install_the_dependencies]]
For more details about installing the needed Linux binary packages, see [[Get_Involved/development/Install_the_dependencies]]
Line 82: Line 74:
== Handling dependencies after setup ==
== Handling dependencies after setup ==


The {{ic|kdesrc-build --initial-setup}} command invokes {{ic|kdesrc-build --install-distro-packages}} as one of the steps. It installs 3rd-party dependencies once run. But they can change over time, and {{ic|kdesrc-build}} is currently not smart enough to track those changes and apply them later; see https://invent.kde.org/sdk/kdesrc-build/-/issues/9 for more details.
The {{ic|kde-builder --initial-setup}} command invokes {{ic|kde-builder --install-distro-packages}} as one of the steps. It installs 3rd-party dependencies once run. But they can change over time, and {{ic|kde-builder}} is currently not smart enough to track those changes and apply them later; see https://invent.kde.org/sdk/kdesrc-build/-/issues/9 for more details.


So after setup, if you want to ensure you do not miss some 3rd party dependency do the following:
So after setup, if you want to ensure you do not miss some 3rd party dependency do the following:
* Update kdesrc-build itself. This will update its {{ic|data/pkg/*.ini}}, which lists the required dependencies.
* Update kde-builder itself. This will update its {{ic|data/pkg/*.ini}}, which lists the required dependencies.
* Invoke installation command again: {{ic|kdesrc-build --install-distro-packages}}.
* Invoke installation command again: {{ic|kde-builder --install-distro-packages}}.


If you still find any external dependencies needed to build KDE software that were not installed with {{ic|kdesrc-build --install-distro-packages}}, then please send a merge request to the [https://invent.kde.org/sdk/kdesrc-build/-/tree/master/data/pkg kdesrc-build repository] to include the needed packages in the list.
If you still find any external dependencies needed to build KDE software that were not installed with {{ic|kde-builder --install-distro-packages}}, then please send a merge request to the [https://invent.kde.org/sdk/kdesrc-build/-/tree/master/data/pkg kdesrc-build repository] to include the needed packages in the list.


== Set up Qt ==
== Set up Qt ==
Line 94: Line 86:
Qt is the fundamental framework that is needed for pretty much all KDE development. A recent enough version of Qt 6, currently Qt version greater or equal to 6.6, is required to proceed.
Qt is the fundamental framework that is needed for pretty much all KDE development. A recent enough version of Qt 6, currently Qt version greater or equal to 6.6, is required to proceed.


The initial setup of kdesrc-build should have installed the required Qt6 packages for you already.
The initial setup of kde-builder should have installed the required Qt6 packages for you already.


If your Linux distribution does not provide recent versions of qt packages, it may be a good time to switch distros to something [[Get_Involved/development#Operating_system|better suited for building KDE software from source code]] either as the primary operating system or in a virtual machine. Building Qt6 using kdesrc-build or installing Qt6 using the Qt online installer are [[Get_Involved/development/More|advanced topics]].
If your Linux distribution does not provide recent versions of qt packages, it may be a good time to switch distros to something [[Get_Involved/development#Operating_system|better suited for building KDE software from source code]] either as the primary operating system or in a virtual machine.


== Disable indexing for your development environment ==
== Disable indexing for your development environment ==
You'll want to disable indexing for your development-related git repos and the files they will build and install. Add the directory <code>~/kde</code> to the exclusions list in System Settings > Workspace > Search > File Search, like so:
You'll want to disable indexing for your development-related git repos and the files they will build and install. Add the directory <code>~/kde</code> to the exclusions list in System Settings > Workspace > Search > File Search, like so:


Line 104: Line 97:


== Next Steps ==
== Next Steps ==
'''Reboot your computer''' and log back in so the package changes, and the <code>~/.bashrc</code> changes take effect on your user account. Once that's done, your development environment is set up and ready to build software. Time to learn how to use <code>kdesrc-build</code> tool to build software from source code!


{{CenteredButton|text=Start compiling KDE software using kdesrc-build|link=Get_Involved/development/Build_software_with_kdesrc-build}}
'''Reboot your computer''' and log back in so the package changes take effect on your user account. Once that's done, your development environment is set up and ready to build software. Time to learn how to use {{ic|kde-builder}} tool to build software from source code!
 
{{CenteredButton|text=Start compiling KDE software using kde-builder|link=Get_Involved/development/Build_software_with_kde-builder}}

Revision as of 22:35, 15 February 2024

Information

Everything on this page only needs to be done once. Once you've done it, your development environment is set up and you can use it to submit patches and develop KDE Software!


Note

This procedure will set up kde-builder.


Source code for KDE software lives on KDE Invent. But before you can work on it, you'll need to set up a development environment: a set of tools that allows you to access and edit the source code, compile it into a form that the computer can run, and deploy it to a safe location. We will now go through the process of setting one up. To accomplish these tasks, you will need to enter commands using a terminal program, such as KDE's Konsole.

If you're not familiar with the command line interface, you can find tutorials here. However, advanced command-line skills are not required, and you will learn what you need along the way!

Install basic tools

First you will need to use your operating system's package manager to install some basic tools:

  • KDE Neon/Kubuntu/Ubuntu/Debian: sudo apt update && sudo apt install git
  • Arch/Manjaro: sudo pacman -S git
  • Fedora: sudo dnf install git perl perl-IPC-Cmd perl-MD5 perl-FindBin
  • openSUSE Tumbleweed: sudo zypper refresh && sudo zypper install git

Configure Git

We need to set your authorship information properly so that any changes you make can be properly attributed to you:

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

The name you provide should be your actual name, not your KDE Identity username or a pseudonym. And the email address must be the same as the email address used for your https://bugs.kde.org account. If they don't match, then the BUG: and FEATURE: keywords won't work (see this page for more information).

Next, in order to authenticate yourself when pushing code changes, you need to add an ssh key to your GitLab profile as described here.

Set up kde-builder

kde-builder is the official KDE meta-build-system tool. It is used to manage the building of many software repositories in an automated fashion. Its primary purpose is to manage dependencies. Every software has dependencies: other pieces of software that provide lower-level functionality they rely on. In order to compile any piece of software, its dependencies must be available.

Information

kde-builder is a successor of kdesrc-build. It has the same syntax and behavior, so the wiki instructions you found here can be applied directly, except the fact that you change the executable name. The only difference is the installation procedure.


KDE software has two types of dependencies: dependencies on other pieces of KDE software, and dependencies on 3rd-party software. For example, the KDE application KCalc depends on more than 20 other KDE git repositories as well as the Qt toolkit.

Some Linux distributions do not provide development packages for KDE Frameworks and of other libraries that are up-to-date enough for us to build from the "main" branch of the KDE git repositories (the branch where the development of the next software versions takes place), so we use kde-builder to compile them ourselves. The goal is to avoid using KDE binaries, KDE libraries and other KDE files from the operating system where possible (in the Linux case, these files reside in the /usr directory).

Installation

Install kde-builder: https://invent.kde.org/ashark/kde-builder#installation

Install kdesrc-build: https://invent.kde.org/sdk/kdesrc-build#install-kdesrc-build

If you are using Arch Linux, you would prefer to install and update the script via AUR package:

Setup

Let's set it up now! First, create a new directory for all the KDE source code. You will need many gigabytes of free disk space. Budget 50 GB for KDE Frameworks + KDE Plasma, and 10-30 GB more for some apps as well.

Next, some distros need source repos enabled before you can install the development packages you need. Do that now, if needed:

  • KDE neon/Debian/Ubuntu/Kubuntu/etc: sudo sed -i '/^# deb-src/s/^# //' /etc/apt/sources.list && sudo apt update. Look at the content of the file /etc/apt/sources.list, e.g. cat /etc/apt/sources.list. Each line that starts with "deb " should be followed by an identical line but the line should start with "deb-src ", e.g.:
deb http://us.archive.ubuntu.com/ubuntu/ noble main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ noble main restricted
  • openSUSE Tumbleweed: sudo zypper mr -e $(zypper repos | awk '/source/{print $5}')

With that done, it's time to run the initial setup program, which will make some changes to your ~/.bashrc (or ~/.zshrc for zsh users) and install the necessary binary packages from your Linux operating system:

./kde-builder --initial-setup
source ~/.bashrc

The step ./kde-builder --initial-setup above installs the Linux binary packages that are needed such that kde-builder can build all of the KDE Frameworks.

For more details about installing the needed Linux binary packages, see Get_Involved/development/Install_the_dependencies

Handling dependencies after setup

The kde-builder --initial-setup command invokes kde-builder --install-distro-packages as one of the steps. It installs 3rd-party dependencies once run. But they can change over time, and kde-builder is currently not smart enough to track those changes and apply them later; see https://invent.kde.org/sdk/kdesrc-build/-/issues/9 for more details.

So after setup, if you want to ensure you do not miss some 3rd party dependency do the following:

  • Update kde-builder itself. This will update its data/pkg/*.ini, which lists the required dependencies.
  • Invoke installation command again: kde-builder --install-distro-packages.

If you still find any external dependencies needed to build KDE software that were not installed with kde-builder --install-distro-packages, then please send a merge request to the kdesrc-build repository to include the needed packages in the list.

Set up Qt

Qt is the fundamental framework that is needed for pretty much all KDE development. A recent enough version of Qt 6, currently Qt version greater or equal to 6.6, is required to proceed.

The initial setup of kde-builder should have installed the required Qt6 packages for you already.

If your Linux distribution does not provide recent versions of qt packages, it may be a good time to switch distros to something better suited for building KDE software from source code either as the primary operating system or in a virtual machine.

Disable indexing for your development environment

You'll want to disable indexing for your development-related git repos and the files they will build and install. Add the directory ~/kde to the exclusions list in System Settings > Workspace > Search > File Search, like so:

Next Steps

Reboot your computer and log back in so the package changes take effect on your user account. Once that's done, your development environment is set up and ready to build software. Time to learn how to use kde-builder tool to build software from source code!