]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mkosi: Add back support for running clangd within mkosi
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 21 Sep 2024 17:29:15 +0000 (19:29 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 22 Sep 2024 13:23:01 +0000 (15:23 +0200)
This allows hacking on systemd without installing any build
dependencies except mkosi on the host machine.

docs/HACKING.md
mkosi.clangd [new file with mode: 0755]
mkosi.images/build/mkosi.conf.d/arch/mkosi.build.chroot

index 4731dc05d403228d0a55f3ff392a7a809d7f3953..992004a58af396f3d3df7c1177d969a7b3c1a49a 100644 (file)
@@ -369,3 +369,19 @@ To debug systemd-boot in an IDE such as VSCode we can use a launch configuration
     ]
 }
 ```
+
+## mkosi + clangd
+
+[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.
+
+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:
+
+```json
+{
+    "clangd.path": "<path-to-systemd-repository>/mkosi.clangd",
+}
+```
diff --git a/mkosi.clangd b/mkosi.clangd
new file mode 100755 (executable)
index 0000000..80d5446
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+MKOSI_CONFIG="$(mkosi --json summary | jq -r .Images[-1])"
+DISTRIBUTION="$(jq -r .Distribution <<< "$MKOSI_CONFIG")"
+RELEASE="$(jq -r .Release <<< "$MKOSI_CONFIG")"
+ARCH="$(jq -r .Architecture <<< "$MKOSI_CONFIG")"
+
+exec mkosi \
+    --incremental=strict \
+    --format=none \
+    build \
+    clangd \
+    --compile-commands-dir=/work/build \
+    --path-mappings="\
+$(pwd)=/work/src,\
+$(pwd)/build/mkosi.builddir/$DISTRIBUTION~$RELEASE~$ARCH/=/work/build,\
+$(pwd)/build/mkosi.cache/$DISTRIBUTION~$RELEASE~$ARCH~build.cache/usr/include/=/usr/include" \
+    "$@"
+
index cafbafee668723be4252a0f0aa730a09c46023ab..1e3a74f9533818d23a2f1273d52232075c8faf38 100755 (executable)
@@ -2,6 +2,10 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 set -e
 
+if [[ "$1" == "clangd" ]]; then
+    exec "$@"
+fi
+
 if [[ ! -f "pkg/$PKG_SUBDIR/PKGBUILD" ]]; then
     echo "PKGBUILD not found at pkg/$PKG_SUBDIR/PKGBUILD, run mkosi once with -ff to make sure the PKGBUILD is cloned" >&2
     exit 1