DornerWorks

Navigate and Write seL4 Code like a Pro with clangd

Posted on June 26, 2023 by Robert VanVossen

Are you a C developer searching for a more efficient and intuitive way to write, test, and navigate your code?

DornerWorks embedded software engineer Robbie VanVossen

clangd is a Language Server Protocol (LSP) for the C language which can provide a code editor, such as vscode, neovim, or helix, with auto-complete, go to definition, warnings, errors, find all references, and quick access to documentation. This makes it much easier to browse, write, and test code.

An seL4 project is made up of multiple repositories that are configured with CMake and built with ninja. We can utilize CMake to generate a compilation database that clangd will use to understand your configuration and the code layout. To do this, after you have created your project, you will run the init-build.sh script. However, we need to run it with the

-DCMAKE_EXPORT_COMPILE_COMMANDS=ON

flag to generate the compilation database.

mkdir build
cd build
../init-build.sh -DCMAKE_EXPORT_COMPILE_COMMANDS=ON $(remaining_config)
cp compile_commands.json ../

If this was done outside a development container, then you are ready to use the LSP. If it was done in a container, then you need to correct the container paths to the actual paths.

sed -i "s|/host/|${PWD}/|g" compile_commands.json

Then follow your editors directions for enabling clangd and voila.


The previous steps only need to be repeated when your configuration changes or new files/libs get added.

As you delve into the potential of Clangd for product development, we invite you to consider taking the next step towards optimizing your embedded engineering endeavors. Whether you’re seeking assistance with seL4 projects, CMake configuration, or navigating the intricacies of embedded systems, the DornerWorks team is ready to support you every step of the way. Schedule a meeting with us when you are ready to turn your ideas into reality.

Robert VanVossen
by Robert VanVossen
Embedded Engineer
Robbie VanVossen is an embedded engineer at DornerWorks.