Skip to content

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

Closed

Description

@devjgm

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?

Activity

  1. devjgm commented on Aug 26, 2020

    @devjgm
    Author

    Tagging @hicksjoseph

  2. self-assigned this
    on Aug 27, 2020
  3. added
    P2
    team-Rules-CPP
    on Aug 27, 2020
  4. ulfjack commented on Sep 7, 2020

    @ulfjack
    Contributor

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

  5. devjgm commented on Sep 8, 2020

    @devjgm
    Author

    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.

  6. devjgm commented on Sep 21, 2020

    @devjgm
    Author

    Any update on this?

  7. oquenchil commented on Oct 14, 2020

    @oquenchil
    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.

  8. added
    help wanted
    on Oct 14, 2020
  9. ulfjack commented on Oct 14, 2020

    @ulfjack
    Contributor

    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.

  10. derekmauro commented on Oct 14, 2020

    @derekmauro

    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.

  11. added
    P3
    and removed
    P2
    help wanted
    on Nov 19, 2020
  12. erenon commented on Jan 18, 2021

    @erenon
    Contributor

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

  13. added a commit that references this issue on Apr 1, 2021
  14. brentleyjones commented on Jan 7, 2022

    @brentleyjones
    Contributor

    Should this be closed now that 08936ae landed?

  15. aminya commented on Apr 14, 2022

    @aminya

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

    build --features=external_include_paths
    
  16. ananta-code commented on Jul 13, 2022

    @ananta-code

    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?

  17. ananta-code commented on Jul 13, 2022

    @ananta-code

    -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?

  18. xumykargo commented on Nov 20, 2023

    @xumykargo

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3team-Rules-CPPtype: feature request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions