intellij icon indicating copy to clipboard operation
intellij copied to clipboard

CLion doesn’t sync header files under `includes` dirs from `implementation_deps`

Open sfc-gh-abalik opened this issue 2 years ago • 4 comments

Description of the bug:

  • Given a cc_library (lib1) that includes another cc_library (lib2) via implementation_deps
  • lib2 exposes lib2.h via includes
cc_library(
    name = "lib2",
    srcs = ["lib2.cc"],
    hdrs = ["include/lib2.h"],
    includes = ["include"],
)

cc_library(
    name = "lib1",
    srcs = ["lib1.cc"],
    hdrs = ["lib1.h"],
    implementation_deps = [
        ":lib2",
    ],
)

cc_binary(
    name = "helloworld",
    srcs = ["main.cc"],
    deps = [
        ":lib1",
    ],
)

CLion will not find lib2.h when syncing files in lib1

# File: lib1.cc

#include "main/lib1.h"
#include "lib2.h"     // => red squiggly here with "'lib2.h' file not found"   

std::string get_string() {
  print_something();  // => function from lib2.h not found  
  return "Hello world";
}

As a result intellisense, go to definition, etc don’t work for lib2.h.

A couple workarounds that fix this

  • Changing from implementation_deps to deps
  • Changing the #include to "include/lib2.h" (e.g. not relying on the include dir)

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Here's a full workspace with the example above. Just open the .bazelproject and look at lib1.cc. repro.tar.gz

Which Intellij IDE are you using? Please provide the specific version.

CLion 2023.1.2

What programming languages and tools are you using? Please provide specific versions.

C++

What Bazel plugin version are you using?

Bazel for CLion 2023.07.04.0.1-api-version-231

Have you found anything relevant by searching the web?

https://github.com/bazelbuild/intellij/issues/3352 seems similar, but for cc_binary

Any other information, logs, or outputs that you want to share?

No response

sfc-gh-abalik avatar Jul 26 '23 04:07 sfc-gh-abalik

I debugged this in the intellij_info_aspect and the problem seems to be that the include paths are not propagated from the implementation_deps to the target here. If I update the aspect to propagate includes from ctx.rule.attr.implementation_deps, then everything works as expected. I can put up a patch for this if it seems like the right fix.

NOTE - For deps this is not needed b/c all include paths are already propagated to downstream targets.

sfc-gh-abalik avatar Jul 26 '23 04:07 sfc-gh-abalik

Exactly, so it could be caused because implementation_deps is missing here https://github.com/bazelbuild/intellij/blob/556dbd68047825a1a2313f121b0704b016520b70/aspect/intellij_info_impl.bzl#L30-L35

tpasternak avatar Aug 02 '23 07:08 tpasternak

@tpasternak I added a PR for this - https://github.com/bazelbuild/intellij/pull/5220. Let me know if this approach makes sense.

sfc-gh-abalik avatar Aug 09 '23 00:08 sfc-gh-abalik

Hi,

To up here, it's still relevant. If above code is working, can we consider please adding this to the plugin?

auzhva avatar Oct 20 '24 09:10 auzhva