diff mbox series

[1/3] clangd: add compile_commands.bbclass

Message ID 20250803010422.21838-3-anakin@childerhose.ca
State New
Headers show
Series Automatically add compile_commands.json to ${S} | expand

Commit Message

Anakin Childerhose Aug. 3, 2025, 1:04 a.m. UTC
Add a class to link the ${B}/compile_commands.json file to
${S}/compile_commands.json to automatically configure the clangd
language server for build systems that generate a compile_commands.json
file.

Signed-off-by: Anakin Childerhose <anakin@childerhose.ca>
---
 meta/classes-recipe/compile_commands.bbclass | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
 create mode 100644 meta/classes-recipe/compile_commands.bbclass

Comments

Alexander Kanavin Aug. 4, 2025, 10:42 a.m. UTC | #1
On Sun, 3 Aug 2025 at 03:04, Anakin Childerhose via
lists.openembedded.org <anakin=childerhose.ca@lists.openembedded.org>
wrote:
> Add a class to link the ${B}/compile_commands.json file to
> ${S}/compile_commands.json to automatically configure the clangd
> language server for build systems that generate a compile_commands.json
> file.

I don't understand this description. What does this json file do, what
does clangd language server do, why can't it find the original file in
${S} and should that be fixed instead? Having different directories
for source and build artefacts is common, and we shouldn't be fixing
it up for others.

Alex
Khem Raj Aug. 4, 2025, 3:52 p.m. UTC | #2
On 8/4/25 3:42 AM, Alexander Kanavin via lists.openembedded.org wrote:
> On Sun, 3 Aug 2025 at 03:04, Anakin Childerhose via
> lists.openembedded.org <anakin=childerhose.ca@lists.openembedded.org>
> wrote:
>> Add a class to link the ${B}/compile_commands.json file to
>> ${S}/compile_commands.json to automatically configure the clangd
>> language server for build systems that generate a compile_commands.json
>> file.
> 
> I don't understand this description. What does this json file do, what
> does clangd language server do,

It will be good to summarize that it implements LSP for C/C++ and 
reference to https://microsoft.github.io/language-server-protocol/

  why can't it find the original file in
> ${S} and should that be fixed instead? Having different directories
> for source and build artefacts is common, and we shouldn't be fixing
> it up for others.
> 

Clangd tries several search paths in S and B as well, but perhaps
something is unique about OE build structure that it is not able to
find it ?

clangd has --compile-commands-dir=<...> option which might be of 
interest here

Aside from this, I think it will be good to add 
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON via cmake.bbclass if someone wants
LSP at distro level.

> Alex
> 
> 
> 
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#221424): https://lists.openembedded.org/g/openembedded-core/message/221424
> Mute This Topic: https://lists.openembedded.org/mt/114509177/1997914
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [raj.khem@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
diff mbox series

Patch

diff --git a/meta/classes-recipe/compile_commands.bbclass b/meta/classes-recipe/compile_commands.bbclass
new file mode 100644
index 0000000000..da8795647c
--- /dev/null
+++ b/meta/classes-recipe/compile_commands.bbclass
@@ -0,0 +1,18 @@ 
+#
+# Copyright Anakin Childerhose
+#
+# SPDX-License-Identifier: MIT
+#
+
+do_generate_compile_commands[doc] = "Add compile_commands.json to S for clangd language server"
+do_generate_compile_commands() {
+    if ! [ -f "${B}/compile_commands.json" ]; then
+        bbwarn "no compile_commands.json found"
+        return
+    fi
+
+    ln -sf ${B}/compile_commands.json ${S}/compile_commands.json || {
+        bbwarn "failed to link compile_commands.json to \${S}"
+    }
+}
+addtask generate_compile_commands after do_compile