erenon / bazel_clang_tidy

Run clang-tidy on Bazel C++ targets directly, efficiently, with caching enabled
MIT License
109 stars 58 forks source link

Conflict with rules proto: "cannot load '@rules_cc//cc:action_names.bzl': no such file" #8

Closed gioannidis closed 3 years ago

gioannidis commented 3 years ago

Overview

bazel_clang_tidy seems to conflict with protobuf rules from rules_proto. The error I am getting is:

clang_tidy/clang_tidy.bzl: cannot load '@rules_cc//cc:action_names.bzl': no such file

Details below.

Steps to reproduce

  1. Clone the bazel_clang_tidy repository (as of this commit).

  2. Apply the 0001-Added-protobuf-external-dependency-and-sample-proto.patch.gz patch.

    • This inserts the rules dependencies from the rules_proto repository, updated to the latest commit.
    • It also adds a sample test.proto file.
  3. Build without invoking clang-tidy: works normally

    $ bazel build //example:app

  4. Build with clang-tidy aspect: raises error (see below)

    bazel build //example:app \ --aspects clang_tidy/clang_tidy.bzl%clang_tidy_aspect \ --output_groups=report

Detailed error message

Invoking the clang-tidy aspect with protobuf rules generates the following errors:

ERROR: in /path/to/bazel_clang_tidy/clang_tidy/clang_tidy.bzl: cannot load '@rules_cc//cc:action_names.bzl': no such file
ERROR: Analysis of aspect '//clang_tidy:clang_tidy.bzl%clang_tidy_aspect of //example:app' failed; build aborted: in /path/to/bazel_clang_tidy/clang_tidy/clang_tidy.bzl: cannot load '@rules_cc//cc:action_names.bzl': no such file
INFO: Elapsed time: 0.090s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)

Offending line

Removing the following rule from WORKSPACE fixes the clang-tidy error, but breaks of course the compilation of //example:test.proto:

rules_proto_dependencies()
gioannidis commented 3 years ago

Investigating this further, the root cause is at the rules_proto repository end, which fetches an older commit from rules_cc.

The rules_proto_dependencies() loads the rules_cc dependencies at commit b7fe969 (2019-07-22). However, the action_names.bzl (history) was created at a later point: 4a1c578 (2019-08-21).

One workaround is to add the following to the WORKSPACE file, after rules_proto_toolchains(), which resolves the issue by fetching the latest commit.

http_archive(
    name = "rules_cc",
    sha256 = "3cde212ccda3ba152897e7fd354c42eba275878b6d98fe4f2125c684a73f3842",
    strip_prefix = "rules_cc-d66a13e2a01630afcafc4ba411d83e291ecf02bd",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_cc/archive/d66a13e2a01630afcafc4ba411d83e291ecf02bd.tar.gz",
        "https://github.com/bazelbuild/rules_cc/archive/d66a13e2a01630afcafc4ba411d83e291ecf02bd.tar.gz",
    ],
)

I am not very experienced with the bazel rules, though. Is there a cleaner way to apply a patch to the rules_cc dependency?

JulianNeeleman commented 3 years ago

I ran into the same issue. Thanks @gioannidis for figuring out the root cause. For me, the build only succeeded after including your WORKSPACE snippet and the git_repository declaration for bazel_clang_tidy before declaring protobuf/gRPC dependencies.

erenon commented 3 years ago

Thanks for reporting this. As a tactical measure, we can drop the dependency on "CPP_COMPILE_ACTION_NAME", and hardcode its current value.