Developing Krita in Visual Studio Code, part 3

Hi again, everyone! This is the final post for this series, in which I’ll show you how to set Krita up in Visual Studio Code. For this post, we’ll cover the Windows operating system. I’ll show you how to take advantage of the same build scripts maintainers use for building the Windows releases.
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 Compiler and Python
- Configuring the Whole Build
- Running Krita
- Updating
- Troubleshooting
So, without further ado, let’s begin!
A warning: this is a distilled version of the official, updated documentation, ported to Windows. It’s optimized to set you up under Visual Studio Code.
Preparing your development environment

We’ll set up a main folder called krita
in one of our drives, for instance C:\
.
mkdir C:\krita
Getting the Source Code

We’ll grab a copy of the source code from KDE’s GitLab instance. Install the Windows version of Git from git-scm.com. Then, let’s go to our krita
folder,
cd C:\krita
and run:
git clone https://invent.kde.org/kde/krita.git src
If you already have a copy, skip the above and let’s check it’s properly updated:
cd src
git pull
Getting the Compiler and Python

Compiling in Windows is special, because Krita doesn’t use Microsoft’s compiler. We use instead a port of GCC called mingw-w64
. We’ll grab version 7.3 (by mingw-builds) from the KDE FTP site. Uncompress this file to a subdirectory named toolchain
inside our krita
folder.
Next, we’ll set up Python. As of the writing of this post, we use version 3.8.1 exactly. Go to its download page, download the installer that matches the architecture you’ll compile for (which is almost always 64-bit), and install it.
Finally, the most difficult of our prerequisites is… Windows SDK. You can get it through the Visual Studio Installer, or by going to the Windows Dev Center. After installation, make sure the following environment variables are set:
-
WindowsSdkDir
: typically set toC:\Program Files (x86)\Windows Kits\10
; -
WindowsSdkVerBinPath
: typically set toC:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0
, where 10.0.18362.0 is the version of the SDK that you installed.
Configuring the Build

This was the most difficult part in our Linux journey. However, in Windows, we can skip a lot of the hard work by setting up Build tasks! You must install first the CMake build system.
Do not use the CMake Tools extension here; it will really complicate things.
Now, open our krita
folder under Visual Studio Code,
code ~/krita
open the Command Palette (Ctrl+Shift+P), select Tasks: Configure Tasks, then Create tasks.json file from template.
A JSON file will open. Replace its contents with the following:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Krita",
"type": "shell",
"args": [
"--no-interactive",
"--skip-deps",
"--jobs",
"12",
],
"options": {
"cwd": "${workspaceFolder}",
"shell": {
"executable": "${env:SYSTEMROOT}\\system32\\cmd.exe",
"args": [
"/C"
]
},
"env": {
"PATH": "${workspaceFolder}\\toolchain\\bin;${env:PATH}"
},
},
"command": "${workspaceFolder}\\src\\build-tools\\windows\\build.cmd",
"detail": "Compile Krita with the official script",
"group": "build"
},
{
"label": "Dependencies",
"type": "shell",
"args": [
"--no-interactive",
"--skip-krita",
"--jobs",
"12",
],
"options": {
"cwd": "${workspaceFolder}",
"shell": {
"executable": "${env:SYSTEMROOT}\\system32\\cmd.exe",
"args": [
"/C"
]
},
"env": {
"PATH": "${workspaceFolder}\\toolchain\\bin;${env:PATH}"
},
},
"command": "${workspaceFolder}\\src\\build-tools\\windows\\build.cmd",
"detail": "Compile dependencies with the official script",
"group": "build"
}
]
}
We have added two tasks called “Dependencies” and “Krita”, that use the script, build.cmd
.
- We have added our MinGW installation to the
PATH
by setting it in the task’soptions.env
value. - We have set the working directory (
cwd
) to${workspaceFolder}, because
build.cmdexpects to be run from the
krita` folder. - The script has the following arguments:
-
--no-interactive
uses default paths and goes straight to the build process. -
--skip-krita
and--skip-deps
skips building Krita and dependencies, respectively. -
--jobs 12
tells CMake to build dependencies using 12 threads. You can adjust it to your tastes, or remove it to let the script autodetect the number of available threads.
-

That’s it! Open the Command Palette again, select Tasks: Run Build Task (or press Ctrl+Shift+B), and run:
- First, the Dependencies task.
- Then, the Krita task. 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}\\i\\bin\\krita.exe",
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{
"name": "PATH",
"value": "${workspaceFolder}\\i_deps\\bin\\;${workspaceFolder}\\toolchain\\bin;${env:PATH}"
}
],
"MIMode": "gdb",
"miDebuggerPath": "${workspaceFolder}\\toolchain\\bin\\gdb.exe",
"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 thePATH
environment variable. -
miDebuggerPath
: we have to use thegdb
executable that comes bundled with our copy of MinGW.
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

- Building dependencies through the scripts need a working Internet connection. Please check you have one before trying!
- 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.
- To set environment variables, open the Start menu, then select Run, and enter
rundll32 sysdm.cpl,EditEnvironmentVariables
. - Make sure that the version of Python we’re using comes first in your
PATH
, for instance, by setting it up in the Build task. Do not set thePYTHONHOME
orPYTHONPATH
environment variables. - Make sure all the variables are properly set! If not, the dependencies build process WILL fail with the most strange errors.
That is all for this process! Remember, if you experience any issues, please do ping me, amyspark @ #krita on Freenode.
Cheers,
~amyspark