Developing Krita in Visual Studio Code, part 1
Hi all! As part of our Community Bonding period, I wanted to share my experience setting up a development environment for Krita. We already have David Revoy’s post and the official, updated documentation. However, they only cover the setup process in Linux.
I’ll show you how to set Krita up in Visual Studio Code, under the three major desktop OSes: Linux, Windows, and macOS. For the latter two, I’ll show you how to use the same build scripts maintainers use for building the releases. We’ll take advantage of Visual Studio Code’s Tasks, so you do the hard work once, and then you’ll be able to compile dependencies AND run Krita in a few keystrokes!
Today’s post will tell you how to set Visual Studio Code up in Linux.
In the spirit of David’s post and Krita’s docs, this post has the following sections:
- Preparing your development environment
- Getting the Source Code
- Getting the Libraries
- Configuring the Build
- Running Krita
- Updating
- Troubleshooting
So, without further ado, let’s begin with Linux!
A warning: this is a distilled version of the official, updated documentation. It’s optimized to set you up under Visual Studio Code.
Preparing your development environment
As I’ve said previously, the process in Linux is really well documented, so I’ll go straight into the itty bits.
We’ll set up a main folder called krita
in our home directory. Inside it, we’ll create the following subfolders:
-
$HOME/krita/build
– the build files -
$HOME/krita/install
– the installation directory
mkdir ~/krita
cd ~/krita
mkdir ./build
mkdir ./install
Getting the Source Code
We’ll grab a copy of the source code from KDE’s GitLab instance. Install Git from your package manager, e.g. for Debian or Ubuntu,
sudo apt-get install git
, and sudo pacman -Syu git
for Manjaro and Arch). Then, let’s go to our krita
folder
cd ~/krita
and run:
git clone https://invent.kde.org/kde/krita.git src
Getting the Libraries
Each Linux distribution has its own way to get Krita’s dependencies. In Debian-based distros, you should be able to pull them all at once, by running:
sudo apt-get build-dep krita
For others, like Manjaro (the one I’m using right while writing this post), you’ll need to get the list of dependencies from your package manager. For instance, in Manjaro you can use the expac
tool:
expac -S "%D %o" krita
We set the -S
option to query the sync database itself, and the string
"%D %o"
tells expac
to list all dependencies, both required (%d
) and optional (%o
). Now, you can feed the list to pacman
for installation by running:
sudo pacman -Sy $(expac -S "%D %o" krita)
Before moving on, make sure you have a working compiler! In Debian-based distros, run:
sudo apt-get install build-essential
In Arch and derivatives,
sudo pacman -Sy base-devel
should do the trick.
Configuring the Build
This is, by far, the most difficult part of our journey. You must install first the CMake build system (sudo apt-get install cmake
,
sudo pacman -Sy cmake
), and inside Visual Studio Code, the CMake Tools extension.
Now, open our krita
folder under Visual Studio Code,
code ~/krita
open the Command Palette (Ctrl+Shift+P), and select Preferences: Open Workspace Settings (JSON).
A JSON file will open, where you can set this workspace’s preferences. These are its contents on my machine:
{
"cmake.configureSettings": {
"BUILD_TESTING": false,
//"PYQT_SIP_DIR_OVERRIDE": "/usr/lib/python3.8/site-packages/PyQt5/bindings/",
"BUILD_KRITA_QT_DESIGNER_PLUGINS": true,
},
"cmake.parallelJobs": 12,
"cmake.configureOnOpen": true,
"cmake.clearOutputBeforeBuild": true,
"cmake.installPrefix": "${workspaceFolder}/install",
"cmake.sourceDirectory": "${workspaceFolder}/src"
}
- The
cmake.configureSettings
variable sets configuration-time environment variables.-
BUILD_TESTING
tells CMake to build Krita’s testing suite. I’ve set it tofalse
so that it’s skipped. -
PYQT_SIP_DIR_OVERRIDE
is a fix you’ll need if you want to build Krita with Python support. Since Manjaro moves Python libraries where Krita cannot find them, I have to tell it where they are first. If you find this error:sip: Unable to find file "QtCore/QtCoremod.sip"
, uncomment this line. -
BUILD_KRITA_QT_DESIGNER_PLUGINS
tells CMake to build Krita’s UI components so that you can use them with Qt Designer. Disable if you won’t do UX development.
-
-
cmake.parallelJobs
sets how many parallel jobs you want your CPU to run. Mine is a 8-core, 16-thread Ryzen box, so I set 12 to have some breathing space. Set to0
if you want to let CMake decide. -
cmake.configureOnOpen
runs the configuration step every time you open this workspace. -
cmake.clearOutputBeforeBuild
cleans the Output tab before starting the build. -
cmake.installPrefix
tells CMake to install Krita to the~/krita/install
directory we created earlier. -
cmake.sourceDirectory
tells CMake where we cloned Krita’s repository to.
With everything set, open the Command Palette again, select CMake: Build Target, install, and off you go!
Running Krita
You’ll probably want to run Krita inside a debugger. Good news is that you can do it from the comfort of Visual Studio Code, through a Launch task!
Open the Command Palette again, and select Debug: Open launch.json. My configuration adds a target called (gdb) Start
:
{
// https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Start",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/install/bin/krita",
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{
"name": "LD_LIBRARY_PATH",
"value": "${workspaceFolder}/install/lib/"
}
],
"externalConsole": false,
"internalConsoleOptions": "openOnSessionStart",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty printing for GDB",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
}
]
}
The most important bits are:
-
program
: it points to thekrita
executable, installed inside ourinstall
subdirectory; -
environment
: we have to show our debugger the right path to Krita’s libraries, through theLD_LIBRARY_PATH
environment variable.
After this, you can launch Krita by just pressing F5! Or also by opening the Command Palette, and selecting Debug: Start Debugging.
Updating
Thanks to Git, this is really easy. Go to our src
folder and pull the last changes:
cd ~/krita/src
git pull
If you have a branch, check it out first:
cd ~/krita/src
git checkout MY_BRANCH
git pull
Then build and install Krita. Open the Command Palette, select CMake: Build Target, install.
Troubleshooting
- Sometimes, you’ll be unable to set Build tasks up. If this option doesn’t appear, it’s usually because your Visual Studio Code has User tasks already configured. Try opening the suggested “echo” task, delete it, and try again.
Tomorrow, I will tell you how to do these steps under macOS. If you experience any issues, please do ping me! amyspark @ #krita on Freenode.
Cheers,
~amyspark