mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.55k stars 1.61k forks source link

Compilation databases with unity builds #8146

Open robbert-vdh opened 3 years ago

robbert-vdh commented 3 years ago

Hi,

I'm not sure if this counts as a bug report or a feature request (since this is technically the correct behaviour). I was considering enabling unity builds on in my projects to speed up compiles, but then I realized that doing so causes the compile_commands.json compilation database to only contain the build commands for the unity build. This makes sense, but it also breaks all clang based tooling since all information about the original source files is now lost. Would it be possible to have Meson output the normal non-unity compilation database when using unity builds? Feel free to close this if this is out of scope or if it's too difficult to implement with Meson's current internals.

mensinda commented 3 years ago

EDIT: This comment is wrong' see my new comment below.


We do have an introspection API that always has the "correct" information for external tooling. It should be possible (with a bit of python) to automatically generate a working compile_commands.json from this.

So, we could implement something like this, but we already have an existing API and we just run ninja -t compdb <some fancy args> to generate the compile_commands.json. I wouldn't place this very high on our TODO list...

eli-schwartz commented 3 years ago

Err... intro-targets.json just contains the same unity info, naturally, since that is the "info about the build" and is correct for building the project, introspection or not. Not sure what you meant here?

mensinda commented 3 years ago

Ok nevermind I forgot to run meson --reconfigure when switching to unity=on in my current project, so the *.json files weren't updated...