BUSY icon indicating copy to clipboard operation
BUSY copied to clipboard

Generate JSON Compilation Database for clangd

Open ghost opened this issue 2 years ago • 15 comments

https://clang.llvm.org/docs/JSONCompilationDatabase.html

cmake supports this: https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html

Another Lua based build system also supports this: https://github.com/bkaradzic/genie

ghost avatar Jun 24 '23 10:06 ghost

I assume you would like the plain BUSY version to do incremental compilation also considering header dependencies (i.e. only rebuild changed implementation files, but also unchanged implementation files the header dependencies of which have changed). Ninja supports this based on a Makefile based format supported by GCC and CLANG. I assume the JSON format is meant for the same purpose, but it is CLANG specific.

The plain BUSY build system is meant for bootstrap, not for development. For use during development I originally intended to generate Ninja, but with LeanCreator I have a version of the BUSY engine which supports full header dependencies based on the build-in C++ parser of LeanCreator. From my perspective this is the recommended way to use BUSY during development.

Generating Ninja is still a planned option, but has no longer high priority (because I have a better solution with LeanCreator which I use for my daily work). I don't see tracking header dependencies as a core responsibility of BUSY.

rochus-keller avatar Jun 24 '23 11:06 rochus-keller

JSON Compilation Database has nothing to do with clang, it's for clangd to provide code completion. Clangd is a language server. I'm using it on Sublime Text via this plugin: https://github.com/sublimelsp/LSP-clangd

ghost avatar Jun 24 '23 11:06 ghost

Ok, I see, thanks. But then why should BUSY use it?

rochus-keller avatar Jun 24 '23 11:06 rochus-keller

Ok, I see, thanks. But then why should BUSY use it?

It's the users of clangd language server like me will use this JSON Compilation Database as clangd needs it to work right. I'm using Sublime Text with clangd to provide code completion for C++ (that is, pretty much turning Sublime Text into a light weight C++ IDE with the help of the clangd language server). clangd will work with the latest C++ version when the built-in C++ parser of LeanQt can't. On latest Qt Creator, they themselves also switched to use clangd for code completion. Latest Qt Creator also ditched qmake and qbs to go with cmake.

It's more convenient to have the build system generate this JSON Compilation Database for you. CMake supports this. There is also an external tool called Bear that supports generating this JSON Compilation Database. Recently, I found GENie, and it claimed to support the generation of this JSON Compilation Database too. I used to think only cmake as the build system supported this. It turned out that there are more build systems that support the generation of this JSON file than I previously thought.

ghost avatar Jun 24 '23 19:06 ghost

Well, then just add the necessary declarations; if it is a by-product of the compile step, then additional cflags will likely do; if a separate run is required, then maybe you can do it with a LuaScript declaration.

rochus-keller avatar Jun 24 '23 20:06 rochus-keller

https://clang.llvm.org/docs/JSONCompilationDatabase.html

cmake supports this: https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html

Please have a look at this to know what it's actually about. The compilers don't generate this file. It's the build system, that knows everything about include paths, compilation flags,... that will have to write this file.

ghost avatar Jun 24 '23 20:06 ghost

Ok, thanks; I will have a look at it when I have time. You're the first person asking for this and I didn't even know it exists, and likely don't have a demand for it, so it won't have high priority (if at all).

rochus-keller avatar Jun 24 '23 21:06 rochus-keller

Ok, thanks; I will have a look at it when I have time. You're the first person asking for this and I didn't even know it exists, and likely don't have a demand for it, so it won't have high priority (if at all).

Well, it will strongly push the popularity of BUSY if added.

ghost avatar Jun 24 '23 21:06 ghost

It's an open source project; if there is wide demand, someone will implement it; I can impossibly implement every requirement myself, so I have to focus on my priorities.

rochus-keller avatar Jun 24 '23 21:06 rochus-keller

This feature is super useful. Please have a look at this:

https://github.com/annacrombie/muon

It's an implementation of meson in C. It generates compile_commands.json out of the box.

Curculigo avatar Aug 12 '24 11:08 Curculigo

I had a look at muon and meson++ before I implemented BUSY, and couldn't use it because it is limited to Posix systems.

rochus-keller avatar Aug 12 '24 11:08 rochus-keller

I had a look at muon and meson++ before I implemented BUSY, and couldn't use it because it is limited to Posix systems.

muon compiled fine with mingw on Windows.

Curculigo avatar Aug 12 '24 11:08 Curculigo

That's too restricted for my projects; most people use MSVC on Windows.

rochus-keller avatar Aug 12 '24 11:08 rochus-keller

There is a nice trick to generate compile_commands.json when using clang. Can you integrate it into BUSY?

https://github.com/trailofbits/multiplier/blob/main/docs/INDEXING.md#getting-compile_commandsjson

Curculigo avatar Aug 12 '24 12:08 Curculigo

Not sure I understand. What exactly should BUSY do in this respect?

rochus-keller avatar Aug 12 '24 14:08 rochus-keller