Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

generate.py doesn't filter out unsupported flag #93

Closed
asparagii opened this issue Feb 17, 2022 · 5 comments
Closed

generate.py doesn't filter out unsupported flag #93

asparagii opened this issue Feb 17, 2022 · 5 comments

Comments

@asparagii
Copy link

As of version 13.0.1, clang doesn't support the flag -fno-canonical-system-headers.
The generated compile_commands.json might contain this flag, since the generation script doesn't filter it out.

We should filter out this flag.

@siddharthab
Copy link
Collaborator

If the compiler does not support the flag, then bazel should not be using the flag. And if bazel is not using the flag, then compile_commands.json would not have it. Is that not the case? Can you check the exact command line as used by bazel and compare with what is in compile_commands.json?

@asparagii
Copy link
Author

asparagii commented Mar 8, 2022

We are using gcc to compile our codebase, so Bazel is using it - and of course the flag is supported in gcc.
Since this utility tries to generate a compile_commands even from Bazel configurations using gcc instead of clang, it would be useful if it filtered out unsupported options (as in, flags gcc supports but clang doesn't).
In this particular case, the no-canonical-system-headers flag doesn't really affect the compilation in any way, so I'm proposing to at least filter this one out (since it's a very common flag to have in gcc, mainly for historical reasons).

@siddharthab
Copy link
Collaborator

siddharthab commented Mar 8, 2022

I see. I think the proper solution here would be to generate the compile commands file with a clang toolchain instead of gcc, because we don't want to get into the business of maintaining a list of supported flags or unsupported flags. You can do this by exporting the CC environment variable to clang when generating the compile commands. In general, we do run tests using gcc and they do seem to work fine.

This specific flag that you are referring to, looks like should not really be in use except for very old gcc compilers (see this issue and this change).

@asparagii
Copy link
Author

Makes sense. I'm working on a project that can be compiled only with a specific version of gcc, I cannot change compiler at will (because of a dependency). Without the flag filtering, this generates an error message in each file when using clangd. Using my fork removing the flag there's no such error, of course.
If you don't want to take care of unsupported flags (reasonable choice) you can close this issue.
Thanks for your time.

@siddharthab
Copy link
Collaborator

Thanks for the response. Closing this issue because the recommended solution here would be to generate the compile_commands.json file with CC=clang in the environment, which will get bazel to output the right compile commands. And so even if the project does not compile with clang, at least the compile commands will have the right flags for libclang.

Alternatively, this could be set as the default env when calling bazel inside generate.py, but people might have different choices for what they want to use here.

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

Successfully merging a pull request may close this issue.

2 participants