rochus-keller / BUSY

BUSY is a lean, statically typed, cross-platform, easily bootstrappable build system for GCC, CLANG and MSVC inspired by Google GN
GNU General Public License v2.0
81 stars 6 forks source link

Generate JSON Compilation Database for clangd #11

Open ghost opened 1 year ago

ghost commented 1 year ago

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

rochus-keller commented 1 year ago

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.

ghost commented 1 year ago

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

rochus-keller commented 1 year ago

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

ghost commented 1 year ago

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.

rochus-keller commented 1 year ago

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.

ghost commented 1 year ago

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.

rochus-keller commented 1 year ago

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).

ghost commented 1 year ago

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.

rochus-keller commented 1 year ago

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.

Curculigo commented 2 months ago

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.

rochus-keller commented 2 months ago

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

Curculigo commented 2 months ago

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.

rochus-keller commented 2 months ago

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

Curculigo commented 2 months ago

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

rochus-keller commented 2 months ago

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