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

FR: Add option to disable warnings from external C++ headers #12009

Closed
devjgm opened this issue Aug 26, 2020 · 13 comments
Closed

FR: Add option to disable warnings from external C++ headers #12009

devjgm opened this issue Aug 26, 2020 · 13 comments
Assignees
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: feature request

Comments

@devjgm
Copy link

devjgm commented Aug 26, 2020

I work on https://github.com/googleapis/google-cloud-cpp and we use CMake and bazel. Our project has several external dependencies defined in our WORKSPACE file. This is all working, but we'd like to be able to compile our own code with a high-level of compiler warnings, like -Wconversion, and we don't want to be bothered by errors in our external dependencies (because we cannot fix those errors).

In our CMake builds, our deps get "installed", and we include them with angle-brackets and they're found by some -isystem dir flags. This works fine with CMake.

However, this doesn't work with Bazel, because bazel encourages all code to be compiled with the same flags, so there's no distinction between my project's code and the code of our external dependencies. The issue is that if I want to compile with -Wconversion, I'll be warned about all my deps' problems that I cannot fix.

WANT: I'd like bazel to provide some supported mechanism to let users compile their own code different warnings flags than their dependencies.

Can bazel already do this? If so, what's the right way to disable warnings from external deps with Bazel?

We have some ideas that seem to work (maybe) that rely on the includes = [ "." ] attribute. We think this might be working, but it also seems like maybe the wrong thing. Is there some other recommended good solution that we should be considering?

@devjgm
Copy link
Author

devjgm commented Aug 26, 2020

Tagging @hicksjoseph

@oquenchil oquenchil self-assigned this Aug 27, 2020
@oquenchil oquenchil added P2 We'll consider working on this in future. (Assignee optional) team-Rules-CPP Issues for C++ rules type: feature request labels Aug 27, 2020
@ulfjack
Copy link
Contributor

ulfjack commented Sep 7, 2020

How do you identify which code is first-party and which is third-party?

@devjgm
Copy link
Author

devjgm commented Sep 8, 2020

I'm not sure who @ulfjack 's question is intended for, but I'll say that any dep that bazel thinks is an external dep should likely be considered third-party.

@devjgm
Copy link
Author

devjgm commented Sep 21, 2020

Any update on this?

@oquenchil
Copy link
Contributor

@ulfjack would Greg's suggestion work?

Make anything starting with external be included as /external? Would that mean flattening the headers nested set in analysis?

Regarding when to tackle this Greg, it would help a lot if you can provide a Windows repro. Also if you could try out replacing /I with /external yourself to verify that that it would work, I could take it from there and check it in the change.

@oquenchil oquenchil added the help wanted Someone outside the Bazel team could own this label Oct 14, 2020
@ulfjack
Copy link
Contributor

ulfjack commented Oct 14, 2020

I think the proposal makes sense. I'm not sure how it would be implemented though. We did something like this in google3, but I'm not sure how it currently works.

@derekmauro
Copy link

derekmauro commented Oct 14, 2020

google3 basically says

--system-header-prefix=third_party/
# Projects in third_party to opt back in:
--no-system-header-prefix=third_party/absl/
...

--system-header-prefix is unfortunately a Clang-only thing. I believe an equivalent exists for MSVC, but I don't know of any good way to do it for GCC.

I agree with @devjgm that external deps are a good start as to what should be considered third party, though I guess it would also be nice if we could control that in some way.

@oquenchil oquenchil added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed P2 We'll consider working on this in future. (Assignee optional) help wanted Someone outside the Bazel team could own this labels Nov 19, 2020
@erenon
Copy link
Contributor

erenon commented Jan 18, 2021

Would you take a PR that makes headers of external libraries referenced using -isystem instead of -I?

erenon added a commit to erenon/bazel that referenced this issue Feb 25, 2021
Projects with strict warnings level experience issues when they
depend on third party libraries with less-strict warnings:
The compiler will emit warnings for external sources.
See bazelbuild#12009 for more.

This change optionally silences those warnings, by changing -I flags to
-isystem flags and by adding -isystem flags for each -iquote flag, in
case of external dependencies, i.e: those targets that come from a
non-main workspace.

The new behavior can be enabled by --features=external_include_paths,
otherwise there's no functional change.

The default flag_group in unix_cc_toolchain_config will silence warnings
coming from -I and -iquote dirs in case of GCC, and -I for Clang. Clang
will still produce warnings for -iquote dirs, therefore the Clang
specific --system-header-prefix is recommended instead.
erenon added a commit to erenon/bazel that referenced this issue Feb 25, 2021
Projects with strict warnings level experience issues when they
depend on third party libraries with less-strict warnings:
The compiler will emit warnings for external sources.
See bazelbuild#12009 for more.

This change optionally silences those warnings, by changing -I flags to
-isystem flags and by adding -isystem flags for each -iquote flag, in
case of external dependencies, i.e: those targets that come from a
non-main workspace.

The new behavior can be enabled by --features=external_include_paths,
otherwise there's no functional change.

The default flag_group in unix_cc_toolchain_config will silence warnings
coming from -I and -iquote dirs in case of GCC, and -I for Clang. Clang
will still produce warnings for -iquote dirs, therefore the Clang
specific --system-header-prefix is recommended instead.
bazel-io pushed a commit that referenced this issue Apr 1, 2021
Projects with strict warnings level experience issues when they depend on third party libraries with less-strict warnings: The compiler will emit warnings for external sources. See #12009 for more.

This change optionally silences those warnings, by changing -I flags to -isystem flags and by adding -isystem flags for each -iquote flag, in case of external dependencies, i.e: those targets that come from a non-main workspace.

The new behavior can be enabled by --features=external_include_paths, otherwise there's no functional change.

The default flag_group in unix_cc_toolchain_config will silence warnings coming from -I and -iquote dirs in case of GCC, and -I for Clang. Clang will still produce warnings for -iquote dirs, therefore the Clang specific --system-header-prefix is recommended instead.

Closes #13107.

PiperOrigin-RevId: 366220384
@brentleyjones
Copy link
Contributor

Should this be closed now that 08936ae landed?

@aminya
Copy link

aminya commented Apr 14, 2022

Confirming that adding the following to .bazelrc fixes the issue:

build --features=external_include_paths

@ananta-code
Copy link

i am using -Wconditional-uninitialized flag and then i am getting some errrors from the library.

external/com_google_protobuf/src/google/protobuf/arena.cc:398:12: error: variable 'arena' may be uninitialized when used here [-Werror,-Wconditional-uninitialized]
return arena->AllocateAlignedWithCleanup(n, alloc_policy_.get());
^~~~~
external/com_google_protobuf/src/google/protobuf/arena.cc:395:21: note: initialize the variable 'arena' to silence this warning
SerialArena* arena;
^
= nullptr
1 error generated.

i want to filter out this error since it is coming from the library and i am using Bazel 5.0 and feature : build --features=external_include_paths but still i am seeing the above error from the library.

Could you please help me on this?

@ananta-code
Copy link

-Wconversion
i am using -Wconditional-uninitialized flag and then i am getting some errrors from the library.

external/com_google_protobuf/src/google/protobuf/arena.cc:398:12: error: variable 'arena' may be uninitialized when used here [-Werror,-Wconditional-uninitialized]
return arena->AllocateAlignedWithCleanup(n, alloc_policy_.get());
^~~~~
external/com_google_protobuf/src/google/protobuf/arena.cc:395:21: note: initialize the variable 'arena' to silence this warning
SerialArena* arena;
^
= nullptr
1 error generated.

i want to filter out this error since it is coming from the library and i am using Bazel 5.0 and feature : build --features=external_include_paths but still i am seeing the above error from the library.

Could you please help me on this?

copybara-service bot pushed a commit that referenced this issue Jul 14, 2023
Hi bazel team

I use an aspect to run clangtidy on the codebase. It is based on https://github.com/erenon/bazel_clang_tidy.

To check my codebase with `-Werror`, I use the "new" feature `external_include_path` requested by #12009, introduced by commit 08936ae.

Now my clangtidy rules did not work anymore of course. As you can see in https://github.com/erenon/bazel_clang_tidy/blob/master/clang_tidy/clang_tidy.bzl, all the different include paths are being passed to the clang-tidy executable. I now also needed to pass the new external_includes to `clang-tidy`.

This PR adds `external_includes` to the `compilation_context` object. I looked at the style of the other `includes` and hope it is in line with your expectations.

Closes #18094.

PiperOrigin-RevId: 548070112
Change-Id: I212420d2f888c3af088c4afbf8202c848d19722e
@xumykargo
Copy link

Does external_include_paths only cover what's specified in includes in external cc_library rules?

I have multiple external repos in my WORKSPACE and with --verbose_failures, I can check which directories are using iquote / isystem. Not all the external headers are covered by isystem; some are only covered by iquote, and trigger warnings. By spotchecks, it seems like hdrs are not covered by isystem, and only includes are.

keith added a commit to bazelbuild/apple_support that referenced this issue May 6, 2024
keith added a commit to bazelbuild/apple_support that referenced this issue May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: feature request
Projects
None yet
Development

No branches or pull requests

9 participants