tensorflow / build

Build-related tools for TensorFlow
Apache License 2.0
272 stars 113 forks source link

compile_commands.json #11

Open bhack opened 4 years ago

bhack commented 4 years ago

It could be nice if we could generate/distribute compile_commands.json to better interact with some IDE and our c++ code.

I.e. In Bazel and also in Vscode the the official Bazel team vscode plugin we don't have in tree support to generate compile_commands: https://github.com/bazelbuild/bazel/issues/258 https://github.com/bazelbuild/vscode-bazel/issues/179

I've tried some quite popular community workaround like: https://github.com/grailbio/bazel-compilation-database

But the problem is that we are using --action_env for build when we generate our .bazelrc with python configure.py and so these arguments not supported in other command like e.g. bazel query https://github.com/bazelbuild/bazel/issues/10226. This is going to invalidate the official bazel vscode plugin that need to execute query command but also the bazel-compilation-database workaround cause we have problem to retrieve our env variable.

bhack commented 4 years ago

/cc @gunan This could be interesting to have in Tensorflow itself but I don't want to duplicate the ticket there. I don't know if you have an internal route on the Bazel team.

gunan commented 4 years ago

I am not sure what compile_commands.json file is. Is this file generated by bazel? Could you provide more details?

bhack commented 4 years ago

@gunan compile_commands.json Is https://clang.llvm.org/docs/JSONCompilationDatabase.html and It is used by many IDEs for integrating with c++ project. If you see I've mentioned two Bazel issues (one for Basel itself and the other one for the Bazel team official plugin for Vscode) cause currently you need to use some external tools/workarounds) to generate/distribuire compile_commands.json with Bazel projects.

mihaimaruseac commented 4 years ago

This is also useful for clangd and Clang Tooling based refactorings.

bhack commented 4 years ago

@mihaimaruseac are you using the tool or not? :wink: See https://github.com/tensorflow/addons/pull/1808#issuecomment-636217541

mihaimaruseac commented 4 years ago

clang-tidy is used, but on the imported code.

What I meant above is other tooling (clang_query and related) and directly on the open source code

gunan commented 4 years ago

From what I can tell, then we would need to update this file every time a new file is added, or a BUILD file is modified?

bhack commented 4 years ago

@gunan I've already mentioined two bazel bugs: bazelbuild/bazel#258 bazelbuild/vscode-bazel#179

mihaimaruseac commented 4 years ago

I think I might be able to do it, if I really need this for a security analysis I'm running. No promises yet.

bhack commented 4 years ago

As Bazel team seems is not interested to put resources on this at upstream level many projects are using https://github.com/grailbio/bazel-compilation-database

mihaimaruseac commented 4 years ago

Yes, but I think I have a solution which uses Bazel and a minimal number of additions to the projects .bazelrc

bhack commented 4 years ago

Ok but check to not reinvet the wheel of alternative approaches: https://github.com/grailbio/bazel-compilation-database#alternatives

mihaimaruseac commented 4 years ago

Yes, I'm only trying to get the solution that is most stable and requires fewer changes

bhack commented 4 years ago

@mihaimaruseac Do you think that we could track this issue in the SIG build repo?

mihaimaruseac commented 4 years ago

Yes, let's do that there. Can you open an issue for me please?

I got preempted from working on this, apologies for the delay

bhack commented 4 years ago

Sorry I have no superpowers to migrate this issue.

mihaimaruseac commented 4 years ago

Oh, I meant creating a new one and then we can either close this or just mention this in the other

bhack commented 4 years ago

@gunan So fast. Too fast :wink:

mihaimaruseac commented 4 years ago

Umm, now this should be opened again?

bhack commented 4 years ago

Yup!

bhack commented 3 years ago

Check https://github.com/bazelbuild/vscode-bazel/issues/179#issuecomment-773107198

bhack commented 2 years ago

Just to add a new resource on this thread:

https://github.com/hedronvision/bazel-compile-commands-extractor

bhack commented 2 years ago

Do you think that this could be scheduled in any roadmap?

JsBlueCat commented 2 years ago

so how to generate the compile_commands.json?

wyg031113 commented 1 month ago

I generated compile_commands.json sucessfully by use Bazel_and_CompileCommands with tensorflow version v2.17.0-rc1 And I comipled it with clang, and using tensorflow devel docker.