5 ms·
> bazel works better if you have 1 library per header What do you mean?
by adgasf 7y ago
> bazel works better if you have 1 library per header
What do you mean?
- klipt 7y agoYou could have a cc_binary for your main foo_main.cc file that depends on cc_library targets separately specified for each bar_lib.h/bar_lib.cc. That makes the graph more granular, e.g. if you just update the foo_main.cc you don't need to recompile the libraries. Or you can reuse bar_lib in a different binary.
- adgasf 7y agoDoes Bazel break up these steps automatically under the hood? It could, in theory.
- SolarNet 7y agoIt does, this is testable a number of ways. The funniest one is to do a `#include "foo.bar"` (and make sure the file exists and is in `srcs`!) and watch bazel freak out with "I have no clue what kind of file that is, how do I analyze that!" Something to be aware of though is that Bazel does do some stupid things around this space. Like adding and removing files causes the build rule to change (if using a glob), which will proc a full rebuild of the library.
- grandmczeb 7y ago> if you just update the foo_main.cc you don't need to recompile the libraries. Are you sure this is required? I just tried with a test repo and Bazel only performed two actions after I updated foo_main.cpp (compile foo_main.cpp and link app.)
- SolarNet 7y agoThe case in question is .h file include chains. And it does work correctly.
- joshuamorton 7y agoTry two versions: Foo.cc that depends on a a lib that's glob of a.h, b.h, c.h, d.h. Foo.cc that depends on a_lib, b_lib, etc. Modify a. In the first case, you'll have to recompile all of abcd. In the second, only a.
- SolarNet 7y agoI just tested this and I think you are incorrect. Bazel will appear as if it's rebuilding all of them (it lists a dozen files), but it's really just checking the caches for them. Try running `bazel build -s` and watch what commands it actually runs. Note that adding and removing files (including through a glob) does always cause a rebuild though (because it's a change of the rule). This is a deficiency of bazel.
- joshuamorton 7y agoYou can skip that if you use libraries, it won't even check the cache or need to relink. That's faster, much faster at scale. The other nice thing is you get dead code elimination for free.
- SolarNet 7y agoSure, but my point was that Bazel is doing file/include analysis so medium sized multi-header libraries are not penalized.
- joshuamorton 7y agoThat's not correct, or at least it's not always correct. C may have some special support, but other languages don't. The other place this is obvious is with tests. If you have a unit test per source, a change to any source will return all tests, splitting reduces this.
- SolarNet 7y agoThen that is a problem with those language's implementations. Bazel allows for it, it is on those language implementations to provide support. Notably I am not aware of many languages that easily allow access to their dependency graphs (especially without third party tools anyway). To me this seems more of an issue with the languages in question than with Bazel.