top | item 23681271

(no title)

asdkhadsj | 5 years ago

> On the other hand I tried introducing Rust for a small part of a larger ecosystem and the cold compile times were so bad we rewrote the functionality in C. It shaved minutes off our CI build times, which costs actual money.

Yea, we have this issue (as a shop now using Rust for all of our backend).

I have a couple of hacks in place to cache the majority of the build thankfully, only needing to compile source code unless something changes. When our build cache works our builds take ~60s. When it doesn't, ~15m.

discuss

order

qppo|5 years ago

To be fair to Rust, this is certainly true of other languages. C++ builds can also be compile time hogs.

What did you wind up doing to cache your builds? I've tried a few different hacks but none have stuck.

asdkhadsj|5 years ago

Oh yea, I wasn't picking on Rust. If anything I tend to defend Rust haha.

As far as what we did to cache, nothing fancy - using Docker build layers. I add my Cargo files (lock/toml), include a stub source lib.rs or main.rs to make it build with a fake source, and then build the project.

This builds all the dependencies. It also builds a fake binary/lib for your project, so you need to strip that from the target directory. Something like `rm -rf target/your?project?name*` (I use ? to wildcard _ and -)

If you do that in one layer, your dependencies will be cached with that docker image. In the next layer you can add your source like normal, compile it, and you'll be set.

We lose our cache frequently though because we're not taking special care to centralize or persist the layer cache. We should, for sanity.

pjmlp|5 years ago

Indeed, but unless you are doing some crazy meta-programming, you can keep reusing the same binary libraries, as inside the same company most projects tend to have similar build flags anyway.

Alternatively it is also quite common to use dynamic libraries, or stuff like COM, XPC.

jfkebwjsbx|5 years ago

C++ build times get high only if you start messing with the type system and ask for it to be recompiled every single time again and again.

Rust is slower overall, which is why people tend to complain. And if you start messing around like in C++, then you get even crazier times.

But in neither case it is a dealbreaker compared to other languages. Go proponents claim compilation speed is everything, which is suspicious. I do not need to run my code immediately if I am programming in C++ or Rust. And if I am really doing something that requires interactivity, I should be doing it another way, not recompiling every time...