Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clangd always chooses debug config compile commands with Ninja Multi-Config #2026

Open
Kaltxi opened this issue Apr 30, 2024 · 5 comments
Open

Comments

@Kaltxi
Copy link

Kaltxi commented Apr 30, 2024

When building the project with cmake generator Ninja Multi-Config compile_commands are emitted with commands for all configs for each file (in my case Debug, Release, RelWithDebInfo in that order). Looking at clangd logs it is apparent that clangd always chooses commands for debug config (probably because it is the first one encountered). This leads to various problems, such as loss of includes (qt generated ui_<widget>.h files are not found in the debug autogen folder, as they are in release folder) and might lead to other problems if configs differ significantly.

Can this somehow be solved on the side of clang to determine the correct config to search for?

System information

Output of clangd --version:

clangd version 18.1.3
Features: windows
Platform: x86_64-pc-windows-msvc

Editor/LSP plugin:

  • VS Code v1.88.1
  • clangd extension v0.1.28

Operating system: Windows 11

@HighCommander4
Copy link

To clarify, you have a single compile_commands.json file with multiple entries for the same source file?

@Kaltxi
Copy link
Author

Kaltxi commented May 1, 2024

Correct, an entry for each config.

@HighCommander4
Copy link

Clangs does not currently have any way to control which of multiple entries for a given file in compile_commands.json is selected.

There was one suggestion made in #1288; please feel free to share other ideas there.

My understanding is that users currently handle situations like this by (1) arranging for there to be a compile_commands.json file with only entries for the current configuration, and (2) updating that when switching configurations.

The ways to achieve (1) can range from the build system having a way to directly generate the intended compile_commands.json file, to post-processing a compile_commands.json file with a tool like jq.

For (2), it can be done manually, though I have also come across tools that automate this such as:

@Kaltxi
Copy link
Author

Kaltxi commented May 3, 2024

@HighCommander4 Thanks for the references! Post-processing seems like an ok compromise to manage the state yourself. A more automated solution I suppose would be to extend compile_commands.json format with config field (like this) and additionally on the side of build system (cmake in this case) to emit a build-time file like current_config.txt with a single entry of the current config corresponding to the last build command which clangd can try to find. This would require changes in both clangd and cmake though...

@HighCommander4
Copy link

A more automated solution I suppose would be to extend compile_commands.json format with config field (like this) and additionally on the side of build system (cmake in this case) to emit a build-time file like current_config.txt with a single entry of the current config corresponding to the last build command which clangd can try to find. This would require changes in both clangd and cmake though...

Just to add to this, clangd is not the only tool that consumes compile_commands.json, it's sort of a standard for clang-based tooling in general, as specified at https://clang.llvm.org/docs/JSONCompilationDatabase.html.

So an extension to the compile_commands.json format would probably need to start with an RFC in the LLVM Discourse to update the specification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants