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

how can i not check system-headers #22

Open
boluo250 opened this issue Jul 1, 2022 · 8 comments
Open

how can i not check system-headers #22

boluo250 opened this issue Jul 1, 2022 · 8 comments

Comments

@boluo250
Copy link

boluo250 commented Jul 1, 2022

always report
error: invalid argument '-std=c++17' not allowed with 'C' [clang-diagnostic-error] /root/.cache/bazel/_bazel_root/c0cc7bb48e68379f59a785b3d4b8baaf/execroot/__main__/bazel-out/k8-fastbuild/bin/external/com_github_google_glog/_virtual_includes/glog/glog/logging.h:42:10: error: 'iosfwd' file not found [clang-diagnostic-error] #include <iosfwd>
@erenon

@erenon
Copy link
Owner

erenon commented Jul 1, 2022

which source file is being processed when this error happens? (the source file that includes logging.h)

@boluo250
Copy link
Author

boluo250 commented Jul 1, 2022

i build this folder
image

@boluo250
Copy link
Author

boluo250 commented Jul 1, 2022

in this folder several .cpp and .h include <glog/logging.h> @erenon

@erenon
Copy link
Owner

erenon commented Jul 1, 2022

Why does bazel try to compile cpp files as C? How does your toolchain definition look like? What does aquery say (compile flags)?

@boluo250
Copy link
Author

boluo250 commented Jul 8, 2022

Why does bazel try to compile cpp files as C? How does your toolchain definition look like? What does aquery say (compile flags)?
i try to compile a demo. i test out the third party "glog" print this error.how can i not check third party?
image

@boluo250
Copy link
Author

boluo250 commented Jul 13, 2022

[https://github.com/google/glog/issues/839](google/glog#839) @erenon hi,I have raised this issue

@boluo250
Copy link
Author

boluo250 commented Jul 20, 2022

hi,@erenon this is my Minimized example,show error
clang-version:15
bazel-version:bazel 4.2.1
os:ubuntu20.04

WORKSPACE

# //:WORKSPACE
load(
    "@bazel_tools//tools/build_defs/repo:git.bzl",
    "git_repository",
)
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
git_repository(
       name = "bazel_clang_tidy",
       commit = "fe56d1f6f6d7c7f0d27b66c15935f8319918c542",
       remote = "https://github.com/boluo250/bazel_clang_tidy.git",
)

BUILD

filegroup(
       name = "clang_tidy_config",
       data = [".clang-tidy"],
       visibility = ["//visibility:public"],
)
`
**.bazelrc**
`# Required for bazel_clang_tidy to operate as expected
build:clang-tidy --aspects @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect
build:clang-tidy --output_groups=report
build:clang-tidy --@bazel_clang_tidy//:clang_tidy_config=//:clang_tidy_config

.clang-tidy

UseColor: true
  
Checks: '-*,
  abseil-*,
  -abseil-no-namespace'


HeaderFilterRegex: '*'
WarningsAsErrors: "*"
CheckOptions:
  - key:             readability-identifier-naming.IgnoreMainLikeFunctions
    value:           1
  - key:             readability-identifier-naming.IgnoreFailedSplit
    value:           0
  - { key: HeaderFileExtensions,          value: "x" }

es_cpp/BUILD

cc_binary(
    name = "main-es1",
    srcs = [ "testaaa.h"],
    visibility = ["//visibility:public"],
)

es_cpp/testaaa.h
#include <iostream> // NOLINT [build/c++17]

bazel build //es_cpp:main-es1 --config clang-tidy
print

root@44fa34cc27e3:~/test/2clang_tidy_test# bazel build //es_cpp:main-es1 --config clang-tidy
INFO: Analyzed target //es_cpp:main-es1 (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /root/test/2clang_tidy_test/es_cpp/BUILD:2:10: Run clang-tidy on es_cpp/testaaa.h failed: (Exit 1): clang_tidy failed: error executing command bazel-out/k8-fastbuild/bin/external/bazel_clang_tidy/clang_tidy/clang_tidy bazel-out/k8-fastbuild/bin/es_cpp/bazel_clang_tidy_es_cpp/testaaa.h.main-es1.clang-tidy.yaml --export-fixes ... (remaining 26 argument(s) skipped)
2 errors generated.
Error while processing /root/.cache/bazel/_bazel_root/c12c70d71c83a34d9ced4530ee069878/execroot/__main__/es_cpp/testaaa.h.
Found compiler error(s).
error: invalid argument '-std=c++0x' not allowed with 'C' [clang-diagnostic-error]
/root/.cache/bazel/_bazel_root/c12c70d71c83a34d9ced4530ee069878/execroot/__main__/es_cpp/testaaa.h:1:10: error: 'iostream' file not found [clang-diagnostic-error]
#include <iostream> // NOLINT [build/c++17]
         ^~~~~~~~~~
Aspect @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect of //es_cpp:main-es1 failed to build
Use --verbose_failures to see the command lines of failed build steps.

INFO: Elapsed time: 0.217s, Critical Path: 0.05s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully

@HappyCerberus
Copy link

I run into the same problem. It's actually an issue with clang treating .h files as C.

To fix it, change the run_clang_tidy.sh:

clang-tidy --extra-arg-before=-xc++ "$@"

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

No branches or pull requests

3 participants