diff --git a/docs/HACKING.md b/docs/HACKING.md index 85adca5974..25ad0aa17e 100644 --- a/docs/HACKING.md +++ b/docs/HACKING.md @@ -309,14 +309,25 @@ To debug systemd-boot in an IDE such as VSCode we can use a launch configuration [clangd](https://clangd.llvm.org/) is a language server that provides code completion, diagnostics and more right in your editor of choice (with the right plugin installed). When using mkosi, we can run clangd in the -mkosi build container to avoid needing to build systemd on the host machine just to make clangd work. +mkosi tools tree to avoid needing to install clangd on the host machine. -All that is required is to run `mkosi` once to make sure cached images are available and to modify the path of the -clangd binary used by your editor to the `mkosi.clangd` script included in the systemd repository. For example, for -VScode, you'd have to add the following to the VSCode workspace settings of the systemd repository: +All that is required is to run `mkosi -f sandbox true` once to make sure the tools tree is available and to modify +the path of the clangd binary used by your editor to the `mkosi.clangd` script included in the systemd repository. +For example, for VScode, you'd have to add the following to the VSCode workspace settings of the systemd repository: ```json { "clangd.path": "/mkosi/mkosi.clangd", } ``` + +The script passes any arguments it receives directly to clangd which you can use +for example to tell clangd where the compilation database can be found using the +`--compile-commands-dir=` option. + +When using clangd, it's recommended to setup the build directory containing the +compilation database used by clangd to use clang as the compiler as well: + +```sh +$ mkosi sandbox -- env CC=clang CXX=clang++ meson setup build +``` diff --git a/mkosi/mkosi.clangd b/mkosi/mkosi.clangd index 44c1128a91..f2e741f0fa 100755 --- a/mkosi/mkosi.clangd +++ b/mkosi/mkosi.clangd @@ -8,17 +8,10 @@ else SPAWN=() fi -MKOSI_CONFIG="$("${SPAWN[@]}" mkosi --json summary | jq -r .Images[-1])" -BUILDDIR="$(jq -r .BuildDirectory <<< "$MKOSI_CONFIG")" -BUILDSUBDIR="$(jq -r .BuildSubdirectory <<< "$MKOSI_CONFIG")" - -exec "${SPAWN[@]}" mkosi \ - --rerun-build-scripts \ - build \ - -- \ - clangd \ - --compile-commands-dir=/work/build \ - --path-mappings="\ -$(pwd)=/work/src,\ -$BUILDDIR/$BUILDSUBDIR=/work/build"\ - "$@" +exec "${SPAWN[@]}" \ + mkosi sandbox -- \ + clangd \ + --compile-commands-dir=build \ + --path-mappings="\ +$(pwd)/mkosi.tools/usr/include=/usr/include" \ + "$@" diff --git a/mkosi/mkosi.images/build/mkosi.build.chroot b/mkosi/mkosi.images/build/mkosi.build.chroot deleted file mode 100755 index 4a3c977a78..0000000000 --- a/mkosi/mkosi.images/build/mkosi.build.chroot +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -e - -if [[ "$1" == "clangd" ]]; then - exec "$@" -fi