Nice work! It’s always exciting to see folk aiming at improving the Rust dev workflow, especially w.r.t. improving caching.
Q: What’s the advantage over naersk, does it cache each crate build individually?
A: It’s very similar to Naersk in the regard that it will build the entire workspace in one go. The unit of caching is the entire derivation itself, just like in Naersk.
The fact that you’ve managed to separate the dependencies from the src of the crate itself already sounds like a big win for the common caching needs!
That said, I’d love to hear your thoughts on the possibility of creating derivations per crate. Is this something that you considered but turned down due to difficulty of implementation? Or perhaps the state of cargo, its arbitrary-rust-code build scripts and macros make this simply not worth it?
One of my most major issues with the Rust dev process is the need to build every crate from scratch when starting new projects or updating the Rust version, even if you’ve just built the same list of dependencies for 100 other similar projects. The lack of user/system-wide caching of build artifacts is painful, results in huge initial compilation times and bloated
It seems like Nix is uniquely positioned to have a chance at solving this with its flexible-yet-hermetic build system. I think the
cargo2nix project is having a go at this:
This Nixpkgs overlay builds your Rust crates and binaries by first pulling the dependencies apart, building them individually as separate Nix derivations and linking them together. This is achieved by passing custom linker flags to the
cargo invocations and the underlying
Last time I tried I remember running into a lot of odd build errors, but that must have been a year ago now - perhaps it’s worth trying again…