Live data from Hacker News

Scaling Rust Builds with Bazel

mmapped.blog

91–100 of 133 posts

Re: Scaling Rust Builds with Bazel

#91
post #64
post #12

Hey, what a surprise, ex-google engineers dragging everyone into bazel... Maybe you have some really complicated use case that makes cargo insufficient, but really, it's pretty damn nice and it's integrated with everything. There are languages that need bazel, rust isn't one of them

Bazel isn't about a particular language needing its build facilities - its about ALL of your organizations languages being built with one tool, ideally in one monorepository. Its very attractive when you have lots of microservices that would otherwise live in disparate repositories. Using a monorepo and Bazel allows you to share api definitions (proto files) across your entire code base (rules_proto, rules_grpc) , so…

> its about ALL of your organizations languages being built with one tool,

Yeah, that's an effective way to sell someone's promotion, but it's always a promise that is never met and instead it's a constant source of problems.

Sometimes reinventing the wheel just buys you a wobbly, squeaky wheel.

Re: Scaling Rust Builds with Bazel

#92
post #80

Earlier quoted context omitted.

Lol, Googler here, I can't deny that I have he urge to force Bazel into the world. It's just, when I joined Google I found a build system I didn't hate. This was the first time. I don't actually love Bazel (Blaze internally), but I love that I don't hate it. Every time I have to learn a new build system in open source work I groan. Why are there so many systems for essentially the same thing?

This was my fist experience with blaze too. First it was, wtf is this shit, and theze blaze-bin/etc folders. Then after I left Google I realized how much I miss it. No Make is not a replacement, or ninja.

> No Make is not a replacement, or ninja.

Why?

The world has been running on make for decades, and it runs just fine. Meanwhile, does Bazel support basic stuff like shared libs or vended libs that are not deployed system-wide? Last time I checked, it didn't.

Re: Scaling Rust Builds with Bazel

#93
post #41

Earlier quoted context omitted.

I guess because package managers (apt, nix, ..) build around the idea of shared libraries, while bazel assume statically built. TBH it’s hard to say which operate model is better anyway. They are simply incompatible :) Related topic: https://youtu.be/Pzl1B7nB9Kc

Bazel does not assume statically built. Where do you get this idea?

From their open issues and ugly hacks needed to build anything else...

https://github.com/bazelbuild/bazel/issues/1920

https://stackoverflow.com/questions/32845940/symbols-from-st...

Re: Scaling Rust Builds with Bazel

#94

Earlier quoted context omitted.

I think Bazel is actually a good build system, but the issue is that they lack good educational resources. Then others adopt it at smaller companies without a team to manage Bazel and without investing time to onboard others into understanding how it works. There are some new talks coming out external from the Bazel maintainers which do a better job of this, but you still have to hunt for them. This is made worse bec…

Not just that it doesn't integrate well with external tools. Cmake works better here. We had a googler at our company switch everything to bazel and it just slowed everyone down. There really is something about Google engineers, this sort of subtle arrogance that the Google way is superior to everything else is existence. Maybe I'm the ass hole but I wonder if anyone can relate?

> We had a googler at our company switch everything to bazel and it just slowed everyone down.

I'd love to hear if anyone can make a case for Bazel knowing that cmake+build cache tools like ccache buy far better performance improvements than any full or incremental build.

Re: Scaling Rust Builds with Bazel

#95
post #23

Earlier quoted context omitted.

Question for an insider. Bazel code coverage seems to be one of the roughest edges. At least when running C++ tests. Only lcov is supported, and due to the sandboxing it's impossible to get other tools working since they always spit out extra instrumentation data that's neither cached nor available on the next sandbox. Does blaze support code coverage properly? Does Google just not care about code coverage? Am I just…

You can get coverage working for almost anything by having each test convert its coverage data to LCOV before stopping, in the same sandbox as the test. I forget the exact details but I think you can do this with a custom run_under test wrapper used during coverage. The wrapper runs your test, with whatever custom coverage system you have, then afterwards it converts to LCOV. Sometimes this might require updates to l…

> You can get coverage working for almost anything by having each test convert its coverage data to LCOV before stopping, in the same sandbox as the test.

I have to call bullshit on this. With C or C++ you need to build the whole project with specific compiler flags to be able to generate code coverage reports. This is not something you implement by tweaking a setting in unit tests.

Re: Scaling Rust Builds with Bazel

#96
I'm using Nix Flakes to support a active and medium-sized Open Source development team working on a decently-sized Rust project which includes cross-compilation for mobile devices, CI with larger integration tests, and so on. I had to find solutions to some of the same aspects as described here.

> This nix-alienation bifurcated our build environment: the CI servers built the code with nix-build, and developers built the code by entering the nix-shell and invoking cargo.

I don't anything wrong with this. Why would you throw the ability to simply use the Rust toolchain and all other tools directly?

It might be the fault of `nix-shell` which was a confusing and worked in some contrived ways. Nix Flakes have `nix develop` with an explicit "nix dev shell" construct which starts a shell that simply puts all the tools neccessary to build the project in the PATH (and possibly other relevant envs).

In our project developers simply need to install Nix and run `nix develop` (or use direnv) and from there on they mostly don't need to remember about Nix during their local work. Only when they need to touch something build/CI related they need to touch nix files, which is maybe 5% of the work, and then they can just ask for help.

The higher level tests do require a bit of thought so they reuse Nix building system, instead of fighting against it.

> Our security team chose Ubuntu as the deployment target and insisted that production binaries link against the regularly updated system libraries (libc, libc++, openssl, etc.) the deployment platform provides.

> Furthermore, the infrastructure team got a few new members unfamiliar with nix and decided to switch to a more familiar technology, Docker containers. The team implemented a new build system that runs cargo builds inside a docker container with the versions of dynamic libraries identical to those in the production environment.

I think at this point it was game over for using Nix.

Nix has a great support for building OCI (aka Docker) containers. It's great to be able to write 10 lines of Nix and just import all the required derivations from existing Nix build system and get a quick to build, nicely cacheable container that has only 35M.

But if you're not going to use it, then you turn a benefit into an extra work.

Using Nix to build inside Dockerfile is a terrible combination, eliminating lots of benefits of each done properly in separation.

> The idea of migrating the build system came from a few engineers (read Xooglers) who were tired of fighting with long build times and poor tooling.

It seems to me that it comes down to this. People didn't want to learn Nix, so they constructed bunch of incompatible ways of doing things.

Eventually there were already bunch of people familiar with Bazel so that's what they used. Had you have few engineers familiar with Nix, they would restructure things and make them work with Nix.

Some final tactical advice for people that would want to solve these problems with Rust. Use Nix Flakes, they are soo much better than old style Nix. Use `crane` for Rust - IMO the best compromise between "not rebuilding everything" and "simple wrapper over cargo". Use cachix or some shared Nix caching. Let developers work in `nix develop` shell and do their thing without thinking too much about Nix. Whenever they need part of codebase running reproducibly (fixtures for tests etc.) tactically invoke `nix build` and `nix run` . For normal Linux distros, provide OCI containers built natively with Nix. If you need raw binaries in order of preference: cross-compile to Musl (can't be done for C++), patchelf (a bit risky with C++ as OP mentioned), maintain a parallel build procedure via Dockerfile, but don't use Nix in it, and use it only to build the artifacts and nothing else.

Re: Scaling Rust Builds with Bazel

#97
post #12

Hey, what a surprise, ex-google engineers dragging everyone into bazel... Maybe you have some really complicated use case that makes cargo insufficient, but really, it's pretty damn nice and it's integrated with everything. There are languages that need bazel, rust isn't one of them

Lol, Googler here, I can't deny that I have he urge to force Bazel into the world. It's just, when I joined Google I found a build system I didn't hate. This was the first time. I don't actually love Bazel (Blaze internally), but I love that I don't hate it. Every time I have to learn a new build system in open source work I groan. Why are there so many systems for essentially the same thing?

> Every time I have to learn a new build system in open source work I groan. Why are there so many systems for essentially the same thing?

I'd love to hear what leads you to believe that adding yet another build system in the form of Bazel would solve that problem for you.

Re: Scaling Rust Builds with Bazel

#98
post #24
post #12

Hey, what a surprise, ex-google engineers dragging everyone into bazel... Maybe you have some really complicated use case that makes cargo insufficient, but really, it's pretty damn nice and it's integrated with everything. There are languages that need bazel, rust isn't one of them

I mean for C++ having the caching just work like you get with Bazel is a huge thing. I agree that Cargo is already near perfect and I wouldn't suggest you switch to Bazel if you have a Rust project. In our case we have a C++ project with some Python, some Rust. Having everything in Bazel here is good for us.

> I mean for C++ having the caching just work like you get with Bazel is a huge thing.

It's a good thing then that cmake+ccache work out of the box by passing the caching tool of your choice like ccache to the compiler launchers.

Re: Scaling Rust Builds with Bazel

#99
post #80

Earlier quoted context omitted.

This was my fist experience with blaze too. First it was, wtf is this shit, and theze blaze-bin/etc folders. Then after I left Google I realized how much I miss it. No Make is not a replacement, or ninja.

> No Make is not a replacement, or ninja. Why? The world has been running on make for decades, and it runs just fine. Meanwhile, does Bazel support basic stuff like shared libs or vended libs that are not deployed system-wide? Last time I checked, it didn't.

Yes, Bazel supports both of those things.

Re: Scaling Rust Builds with Bazel

#100

Earlier quoted context omitted.

> No Make is not a replacement, or ninja. Why? The world has been running on make for decades, and it runs just fine. Meanwhile, does Bazel support basic stuff like shared libs or vended libs that are not deployed system-wide? Last time I checked, it didn't.

Yes, Bazel supports both of those things.

You have people in this discussion claiming otherwise, and I also know for a fact that in the past it did not supported either.

Can you actually provide a working example?

Post reply on HN