We are migrating a CMake project to Bazel. We have several header only libraries that are tagged SYSTEM in CMake project to suppress some warnings. When migrating these to Bazel, the way we are able to make this work is by using the below
cc_library(
name = "lib",
srcs = ["include/header1.h", ...],
includes = ["include"],
)
This works but as per Bazel C++ documentation, it is not recommended to have interface/public headers in srcs
. Those should be part of hdrs
. Adding these to headers doesn't work because it uses the regular -I
based inclusion instead of -isystem
.
Is our way of doing this fine, although not recommended by bazel? If not, what would be the correct way of doing it?
EDIT:
After some digging, found the textual_hdrs
attribute on cc_library
and using that it seems to work too. And this seems to be a cleaner approach than adding the public headers to srcs
. Now the rule looks like this
cc_library(
name = "lib",
textual_hdrs = ["include/header1.h", ...],
includes = ["include"],
)
This looks like a good solution for us, except that the documentation on textual_hdrs isn't clear enough to indicate that this is what it is meant for.
PS: It is really not possible for us to refactor the code to fix the warnings as there are numerous libraries like this and just completely outside the scope of this migration effort.
It turns out adding it to hdrs
does work if you make sure that strip_include_prefix is None (or not passed). We had a macro that was wrapping up the cc_library instance and it was defaulting strip_include_prefix to empty string. Interestingly this doesn't affect textual_hdrs
or srcs
, but does affect hdrs
In summary the below seems to work fine
cc_library(
name = "lib",
hdrs = ["include/header1.h", ...],
includes = ["include"],
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With