Skip to main content Skip to navigation

Developing Krita in Visual Studio Code, part 2

Categories:
Everyone uses deevad's pics for Krita's building instructions 😄 Credits: David Revoy, CC-BY-4.0

Hi again! This is the second installment of this series. Today’s post will cover how to set Krita up in Visual Studio Code, under macOS. I’ll show you how to take advantage of the same build scripts Iván and Boudewijn use for building the Mac releases.


Again, in the spirit of David’s post and Krita’s docs, this post has the following sections:

So, without further ado, let’s begin!

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

Credits: David Revoy, CC-BY-4.0

We’ll set up a main folder called krita-mac in our home directory.

mkdir ~/krita-mac

Getting the Source Code

Credits: David Revoy, CC-BY-4.0

We’ll grab a copy of the source code from KDE’s GitLab instance. Git should already come with macOS, otherwise you can install a (newer) version by using Homebrew and issuing:

brew install git

Then, let’s go to our krita-mac folder

cd ~/krita-mac

and run:

git clone https://invent.kde.org/kde/krita.git krita

Getting the Compiler

Credits: David Revoy, CC-BY-4.0

To compile Krita, you will need a copy of Apple’s Xcode. You can install it through the Mac App Store, or by going to the Apple Developer site and clicking on “View in Mac App Store”.

To check if it’s properly installed (it’s a big download), you can use the xcode-select tool:

xcode-select --print-path

It should output: /Applications/Xcode.app/Contents/Developer

Configuring the Build

Credits: David Revoy, CC-BY-4.0

This was the most difficult part in our Linux journey. However, like we did on 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": [
                "buildinstall"
            ],
            "options": {
                "cwd": "${workspaceFolder}",
                "env": {
                    "BUILDROOT": "${workspaceFolder}",
                    "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
                }
            },
            "command": "${workspaceFolder}/krita/packaging/macos/osxbuild.sh",
            "detail": "Compile Krita with the official script",
            "group": "build",
        },
        {
            "label": "Dependencies",
            "type": "shell",
            "args": [
                "builddeps"
            ],
            "options": {
                "cwd": "${workspaceFolder}",
                "env": {
                    "BUILDROOT": "${workspaceFolder}",
                    "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
                }
            },
            "command": "${workspaceFolder}/krita/packaging/macos/osxbuild.sh",
            "detail": "Compile dependencies with the official script",
            "group": "build",
        }
    ]
}

We have added two tasks called “Dependencies” and “Krita”, that use Iván’s script, osxbuild.sh.

  • We have cleaned the PATH by setting it to Apple’s defaults. This helps prevent conflicts with dependencies you may have installed through Homebrew.
  • We have set the working directory (cwd) and the BUILDROOT to ${workspaceFolder}, because osxbuild.sh expects to be run from the krita` folder.
  • The script has only two subcommands:
    • builddeps builds dependencies,
    • buildinstall builds and installs Krita.
Credits: David Revoy, CC-BY-4.0

That’s it! Open the Command Palette again, select Tasks: Run Build Task (or press Ctrl+Shift+B), and run:

  1. First, the Dependencies task.
  2. Then, the Krita task. And off you go!

Running Krita

Credits: David Revoy, CC-BY-4.0

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": "(lldb) Start",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/i/bin/krita.app/Contents/MacOS/krita",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb"
        }
    ]
}

The most important bit is:

  • program: it points to the krita executable, installed inside our install subdirectory.

After this, you can launch Krita by just pressing F5! Or also by opening the Command Palette, and selecting Debug: Start Debugging.

Credits: David Revoy, CC-BY-4.0

Updating

Credits: David Revoy, CC-BY-4.0

Thanks to Git, this is really easy. Go to our src folder and pull the last changes:

cd ~/krita-mac/krita
git pull

If you have a branch, check it out first:

cd ~/krita-mac/krita
git checkout MY_BRANCH
git pull

Then build and install Krita. Open the Command Palette, select CMake: Build Target, install.

Troubleshooting

Credits: David Revoy, CC-BY-4.0
  • Building dependencies through the scripts need a working Internet connection. Please check you have one before trying!
  • Currently, osxbuild.sh doesn’t print anything to console. You can, however, look at the build progress by tail -f ~/krita-mac/osxbuild.log.
  • 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.
  • Do not try to build Krita with dependencies installed through Homebrew, because they will conflict with the build script.

In the final post of this series, tomorrow, we will cover Windows. Remember, if you experience any issues, please do ping me! amyspark @ #krita on Freenode.

Cheers,

~amyspark