137 points · by oftenwrong · 1y ago · 46 comments
I hope to find the time to build a PoC one day…
I think it's still very representative.
Has anyone seen an advantage of using bazel? The learning curve is an issue as well.
Blaze (inside Google) was pretty good but not only because of common builds but also because of artifacts that were shared across developers.
Like, “I want an OCI image with these contents” gets you an image with the exact files bit-for-bit from the same source, every time. At least aspirationally.
Bazel makes this consistent with platforms [0]. I have not used bazel with Rust but it worked fine for my multi-target C++ builds.
- Automatic caching of everything. In most build tools, caching is opt in, so the core build/compile steps usually end up getting cached but everything else is not and ends up being wastefully recomputed all the time. In Bazel, caching is the default so everything is cached. Even tests are cached so if you run a test twice on the same code and inputs (transitively), the second time it is skipped
- Dependency based test selection: You can use bazel query to determine the possible targets and tests affected by a code change, allowing you to trivially set up CI to only run tests downstream of a PR diff and skip unrelated ones. Any large codebase that doesn't use Bazel ends up re-inventing this manually, e.g. consider this code in apache/spark that re-implements this in a Python script that wraps `mvn` or `sbt` (which are build tools that do not provide this functionality) https://github.com/apache/spark/blob/290b4b31bae2e02b648d2c5...
- Automatic sandboxing of your build steps in CGroup/NS containers, to ensure your build steps do not make use of un-declared files. In most build tools, this kind of mistake results in confusing nondeterministic parallelism and cache invalidation problems down the road, where e.g. your build step may rely on a file on disk but not realize it needs to re-compute when the file changes. In Bazel, these mis-configurations result in a deterministic error up front
- At my last job we extended these cgroups to limit CPU/Memory usage as well, which eliminates the noisy neighbour problem and ensures a build step or test gets the same compute footprint whether run alone during development or 96x parallel on a CI worker (https://github.com/bazelbuild/bazel/pull/21322). Otherwise it's common for tests to pass when run during manual development then timeout or OOM when run in CI under resource pressure due to other tests hogging the CPU or RAM
- Built in support for seamless shared caches: e.g. I compile something on my laptop, you download it to your laptop for usage. This also applies to tests: e.g. if TestFoo was run in CI on master, if i pull master and run all tests without changing the Foo code, TestFoo is skipped and uses the CI result
- Built in support for shared compute clusters: e.g. I compile stuff and it automatically happens in the cloud on 96 core machines, or i run a lot of tests (e.g. after a big refactor) on my laptop and it automatically gets farmed out to run 1024x parallel on the cluster (which despite running faster shouldn't cost any more than running 1x parallel, since it costs 1024x as much per-second but should finish in 1024x fewer seconds!)
- Support for deep integration between multiple languages: e.g. building a Go binary and Rust library which are both used in a Python executable, which is then tested using a Bash script and deployed as part of a Java backend server. Most build tools support one language well and others not at all, Bazel supports them all (not perfect but adequately)
If you never hit these needs, you don't need Bazel, and you probably shouldn't use it because it is ferociously complicated. But if you do hit these needs, most other build tools simply do not cut it at all.
We're trying to support some of these use cases and provide a simpler alternative in https://mill-build.org, but Bazel really is a high bar to reach in terms of features that support large monorepos
I guess for a small team (say less than 10 people) the complexity of Bazel is too much to make it worth it, but those features you mention seem like universally useful for any project. I bet there are lots and lots of reinvented wheels out there trying to do just a subset of all these.
For your small-ish project I'm guessing you have wants, but if the project grows at some point those will transition into needs and then you may have to make hard choices. That's my experience rolling it out Bazel myself and maintaining it for a growing organization and codebase over 7 years
I'm hoping the Mill build tool I'm working on can become an easier/friendlier alternative that provides many of the same benefits, even if it can't support the extreme Google scale that Bazel does. So if you think these things sound cool, but you don't want to spend 1 person decade on your build tool, you should check out Mill!
We do not use some of the more complex features like remote execution, but we do enjoy all the other features including remote caching. We reduced build times by 92% after the migration.
So my advice would be, try it and see for yourself if you think it’s worth the hassle. For my team, it definitely has been.
Regarding Mill: I got excited at first and then I realized it's for JVM languages only(?) How come?
I'm sure it's possible to do the exact same thing in <NAME ANOTHER BUILD TOOL>, but I found it to be easy enough in Bazel without the configuration being overly verbose.
bazel run make_otel_sdk
it compiles debug, fastdebug, release, then it places the .dll, include/ folders, etc. into single zip. I'm also invoking sentry-cli to obtain all source code used and also place them in
https://github.com/malkia/opentelemetry-cpp/actions/runs/120...
it produced this
https://github.com/malkia/opentelemetry-cpp/releases/tag/v1....
At work in a top level .bazelrc I have caching on the intranet, but on the github I'm relying (not ideal) on the actions/cache through disk_cache blobs - it works, but storing back all "blobs" makes it a bit worse than expected.
Rules_pkg went through the same problem: it was built in to bazel, then they moved it out into rules_pkg 0.0.1, then the maintainer of rules_pkg felt free to break everything multiple times, mostly for unjustifiable aesthetic reasons.
> Bzlmod, the new way to manage external dependencies, is turned on by default since Bazel 7.0.
> We are aiming to remove WORKSPACE in Bazel 9 completely.
Oh, that's good to know. Sorry I wasn't paying attention, M.