IDE Setup

IDE

In this part of the tutorial, we'll go over setting up the development environment using different IDEs/Code editors. The editors used here are recommended but if you have an editor/IDE which you're more comfortable with you're free to use them.

Visual Studio Code

Visual Studio Code is one of the recommended editors for sysrepo plugin development due to its extension library, helpful tools and great documentation. We'll point out some useful extensions for working inside a virtual machine such as a CMake extension, remote SSH extension, C/C++ code completion and navigation extension and a C/C++ code debugger.

Remote access extension

Recommended extension for accessing the virtual machine filesystem and writing/debugging code remotely is the Remote - SSH (opens in a new tab) extension. You can use the documentation to set up remote access to the virtual machine you configured as a prerequisite. You'll probably need to forward the SSH port 22 and use Remote - SSH command to add a new SSH host:

After that, add your virtual machine, for example ssh user@localhost -p 3000 if you're using port forwarding from port 3000 on your local machine to the port 22 on your virtual machine. After adding the host, you can check the configuration by using the command Remote-SSH: Open Configuration File and checking that your added host matches what you've written in the command prompt.

CMake extensions

For setting up CMake with VSCode you can use the following extensions:

The first extension is used for CMake syntax highlighting and the second extension is used for adding useful commands to your VSCode command prompt, such as CMake: Configure and CMake: Quick Start.

clangd extension

clangd (opens in a new tab) extension can be used for developing C/C++ applications. It provides syntax highlighting, code completion, navigation between header files etc. You can follow the instructions on the extension website to set up the extension.

Useful feature of this extension is using CMake generated compile_commands.json for parsing clang commands and getting full code completion support. Once the extension is installed and set up, you can open the extension settings and edit the commands file location - for the arguments list, add the following argument:

Since most of the sysrepo related projects use the build/ directory for CMake project building, compile_commands.json file will end up in that directory after configuring CMake.

When building projects with CMake, make sure you set the CMAKE_EXPORT_COMPILE_COMMANDS option to ON, for example:

cmake -S . -B build/ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

Code debugger - CodeLLDB extension

Recommended extension for C/C++ code debugging is CodeLLDB (opens in a new tab). The only needed thing on your machine for this extension is the lldb debug tool.

As for the project build, you need to make sure you're building the project using the CMake Debug mode, for example you can set the build type of the project to be Debug:

cmake -S . -B build/ -DCMAKE_BUILD_TYPE=Debug

Once enabled, your code will be compiled with debug symbols included in the final executable/library and you will be able to debug the applications using CodeLLDB extension.

Format on save

You can enable format on save in your VSCode settings to enable clangd extension to use clang-format to format your C/C++ files once the file is saved.

Conclusion

After you've set up your development environment you can continue to the next step which is developing your first plugin!