rules_cc_toolchain icon indicating copy to clipboard operation
rules_cc_toolchain copied to clipboard

Disabling warnings from external headers

Open tpudlik opened this issue 2 years ago • 2 comments

The default Bazel C++ toolchain has a cool feature that allows disabling warnings from external headers: https://github.com/bazelbuild/bazel/pull/13107. It would be nice to add this to rules_cc_toolchain, too. It would make clang version upgrades less painful for downstream users like Pigweed (since third-party deps may pick up lots of new warnings on a version upgrade).

The implementation in the default toolchain is actually very simple, but it's not possible to express as a cc_feature, so it's not immediately clear to me how to add it.

Perhaps this should wait until the modular cc toolchains is finalized, since that may involve big changes to rules_cc_toolchain.

tpudlik avatar Feb 02 '23 22:02 tpudlik

I used to think this would be quite easy: https://github.com/tpudlik/rules_cc_toolchain/commit/80677f37da51d3d18cc9baba63327d36d91b23bd

But to my surprise, this leads to errors when I try to compile Pigweed. Typical error:

In file included from external/boringssl/src/crypto/x509/x_val.c:62:
In file included from external/boringssl/src/crypto/x509/internal.h:62:
external/boringssl/src/include/openssl/base.h:340:13: error: typedef redefinition with different types ('int' vs 'struct crypto_threadid_st')
typedef int CRYPTO_THREADID;
            ^
external/debian_stretch_amd64_sysroot/usr/include/openssl/crypto.h:237:3: note: previous definition is here
} CRYPTO_THREADID;
  ^

I think what's going on here is that the -I vs -isystem distinction was used in rules_cc_toolchain to override headers from the sysroot with headers from other external repos (boringssl in this case). But external_include_paths is implemented in upstream Bazel by converting -Is from external repos to -isystem.

This can probably be fixed by ensuring the include order for sysroot libraries is correct (so that they're overriden anyway), but the details are hazy to me.

tpudlik avatar Feb 03 '23 21:02 tpudlik

Yeah, I don't really have a good understanding of this either. I'm more than happy to change the usage of include flags in rules_cc_toolchain. I'll admit I'm not super familiar with the differences between; -I, -isystem, -iquote. I've read the docs for these flags, but I didn't feel like I fully understood the specific differences in enough detail to offer any guidance.

nathaniel-brough avatar Feb 04 '23 18:02 nathaniel-brough