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

Write a compile_commands.json from build_ext #4358

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

godlygeek
Copy link

Summary of changes

Produce a JSON database of the compiler commands executed while building extension modules as build/compile_commands.json. This is usable by various C and C++ language servers, linters, and IDEs, like clangd, clang-tidy, and CLion. These tools need to understand the header search path and macros passed on the compiler command line in order to correctly interpret source files. In the case of Python extension modules, the developer might not even know all of the compiler flags that are being used, since some are inherited from the interpreter via sysconfig.

Closes #1975

Pull Request Checklist

@godlygeek
Copy link
Author

Let's call this a proof-of-concept. There are no tests yet. This implementation changes both the setuptools build_ext command and the vendored distutils.unixccompiler module.

If this seems like a reasonable approach to the problem, I guess the changes to unixccompiler would need to be done in https://github.com/pypa/distutils/ instead, and tested there.

Perhaps it should also apply to non-Unix compilers as well, but I'm not sure. compile_commands.json originated from the Clang/LLVM world, and I think most tools that use it expect clang- or gcc-compatible flags.

I'm not very familiar with the architecture of setuptools, so if this approach seems fundamentally wrong or there's a cleaner way to do it (especially one that doesn't require modifying the vendored distutils), please point me in the right direction.

Produce a JSON database of the compiler commands executed while building
extension modules as `build/compile_commands.json`. This is usable by
various C and C++ language servers, linters, and IDEs, like `clangd`,
`clang-tidy`, and CLion. These tools need to understand the header
search path and macros passed on the compiler command line in order to
correctly interpret source files. In the case of Python extension
modules, the developer might not even know all of the compiler flags
that are being used, since some are inherited from the interpreter via
`sysconfig`.
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

Successfully merging this pull request may close these issues.

Option to Generate Compilation Databases
1 participant