summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/HACKING.md16
-rwxr-xr-xmkosi.clangd20
-rwxr-xr-xmkosi.images/build/mkosi.conf.d/arch/mkosi.build.chroot4
3 files changed, 40 insertions, 0 deletions
diff --git a/docs/HACKING.md b/docs/HACKING.md
index 4731dc05d4..992004a58a 100644
--- a/docs/HACKING.md
+++ b/docs/HACKING.md
@@ -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
index 0000000000..80d544677a
--- /dev/null
+++ b/mkosi.clangd
@@ -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" \
+ "$@"
+
diff --git a/mkosi.images/build/mkosi.conf.d/arch/mkosi.build.chroot b/mkosi.images/build/mkosi.conf.d/arch/mkosi.build.chroot
index cafbafee66..1e3a74f953 100755
--- a/mkosi.images/build/mkosi.conf.d/arch/mkosi.build.chroot
+++ b/mkosi.images/build/mkosi.conf.d/arch/mkosi.build.chroot
@@ -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