Earthly for Rust
Fast, incremental Rust builds in CI
Fast Rust Builds in CI
Get Started Free
IMPORT github.com/earthly/lib/rust
December 2023
Incremental Rust builds in CI
In this post, we present lib/rust, an open-source Earthly library created in collaboration with the ExpressVPN core team, that will help you get maximum performance on Rust builds in CI when used in....
Read more
Documentation
Earthly guide for Rust
This page will help you use Earthly if you are using Rust. Step 1: Import the Rust library To get started, import the rust library as shown below. Note that the --global-cache flag is currently required to allow for...
Read more
Why Earthly?
With Earthly, all builds are self-contained, consistent, portable, and
language agnostic.
Before:
Bash and YAML spaghetti
Clunky and Brittle
Build guru required
With Earthly:
Consistent
Robust
Easy to Understand
Why Are Rust Builds Slow in CI?
Understanding the complexities of Rust's build process and its challenges
in CI.
Intricacies of Rust Compilation
- Rust has one of the most advanced compilers available. Its compilation process is thorough, emphasizing safety and concurrency. This is great but has a cost, build speed.
- The language's extensive checks and optimizations, essential for runtime performance, contribute to its inherently slow compilation.
Local Optimizations vs. CI Limitations
- Developers utilize local optimizations such as Cargo caching, which are less effective in CI.
- The stateless nature CI builds often undermines these local optimizations, leading to full rebuilds and slower build times.
Challenges with Cargo Caching in CI
- Cargo caching enables incremental builds, significantly reducing build times.
- Incremental builds are difficult to reproduce in CI, because Cargo’s cache folders mix cacheable artifacts and non-cacheable artifacts.
- Caching in CI often requires a cache download and upload for each build, increasing build times, and has size limits which Cargo may exceed.
Fast, Incremental Rust Builds in CI with Earthly
Earthly + Earthly Satellites give you fast, incremental Rust builds in CI.
Incremental Rust Builds in CI
- Earthly speeds up Rust builds in CI by effectively implementing Cargo's caching and Rust's incremental compilation.
- This approach significantly reduces unnecessary rebuilds in CI, mirroring the efficiency of local Rust builds.
Earthly Satellites: Persistent Remote Build Runners
- Earthly Satellites are persistent remote build runners that retain cache data locally.
- This drastically speeds up CI build times by eliminating cache uploads and downloads.
- Instead of bringing the cache data to the compute, we colocate the cache data and compute, eliminating cache transfers altogether.
Optimizing Rust Builds with Earthly's lib/rust
Library
- Earthly's
lib/rust
library optimizes caching for Rust in CI. - It abstracts away cache configuration entirely while also resolving common duplication and inefficiency issues.
- This makes it easy to ensure Rust is caching correctly and building incrementally in CI, while also keeping your build files clean and readable.
BuildKit Layer Caching + Advanced Cache Mounts
- Earthly leverages Docker layer caching via BuildKit. Every step of your build is cached and reused if possible.
- Earthly also offers cache mounts to augment layer caching and support use cases such as partial cache invalidation which is not possible with layer caching and required for incremental builds.
Streamlined Build Workflow with Earthly
- Earthly’s Guide for Rust details a simple Rust example with optimized caching and compilation steps that enhance overall build efficiency.
- The Earthly approach focuses on incremental builds, ensuring rapid and effective Rust builds in CI.