Did strip_include_prefix in cc_library add to the search path instead of using _virtual_includes?

34 views
Skip to first unread message

carpen...@gmail.com

unread,
Mar 26, 2021, 12:52:07 PMMar 26
to bazel-discuss
I seem to remember researching the difference between strip_include_prefix="" and include_prefix="" with bazel 2.0.  I found that under some conditions we could skip the potentially expensive generation of _virtual_includes. I came to the conclusion that by preferring strip_include_prefix=""" and the cc_library would just add an additional include path to effectively strip part of the path away. This is great for importing huge libraries like boost, where you want to not have absolute repo paths, but avoid _virtual_includes. 

I have since upgraded to a much newer version of Bazel and went back to look at it, and I can't see evidence of it adding a -I to the include path.

This seems to suggest I am not the only one who thought it worked like that: https://github.com/bazelbuild/intellij/issues/145#issuecomment-350922120

What I thought you could do was: 
Have your say boost library somewhere like:
//external/boost/include/boost/{all the headers}
If you put a BUILD file in "//external/boost/include/"
cc_library(
    name = "headers",
    strip_include_prefix = "",
    hdrs =  and glob(["boost/**/*.hpp"]),
)
It adds would add a -I to the include path of all cc_* which depend on that library. 

Was this the case, or do I miss-remember? 

James


Konstantin

unread,
Apr 14, 2021, 8:06:20 AMApr 14
to bazel-discuss
If I understand you right you can use "includes" attribute instead of strip_include_prefix and it would do exactly what you want - adding -l to all dependencies and not generating _virtual_includes.

Konstantin

Reply all
Reply to author
Forward
0 new messages