Unlocking Faster Rust Build Times with Fleet

What is Fleet?

Fleet is a build tool designed to alleviate Rust’s long compile times, making it an ideal solution for optimizing build times in local development and CI/CD pipelines. Its primary focus is on ease of use, wrapping existing build tools and tweaking optimizations to provide a configurable and intuitive experience. Currently in beta, Fleet supports nightly rustc and is actively being developed, with plans to move to the stable toolchain soon.

Getting Started with Fleet

To get started with Fleet, you’ll need to have Rust installed on your machine. Once set up, you can use Fleet with the following command-line arguments:

  • -h/--help
  • -V/--version
  • build
  • run

Additional optional arguments are available for run and build in the Fleet documentation. To benchmark build times, ensure clean builds and consider caching and preloading.

Optimizations in Fleet

Fleet focuses on four key optimizations to significantly speed up your Rust build times:

Ramdisk

A Ramdisk is a block of RAM used as a virtual hard disk to improve speed and reduce stress on physical disks. By placing the /target folder on a Ramdisk, build times can be significantly improved, especially for non-SSD hard disks or WSL (Windows Subsystem for Linux) users.

fleet run --ramdisk /target

Build Configuration

Fleet manipulates build configurations using compiler options and flags to boost performance. Examples include increasing codegen-units for parallelism and lowering optimization levels for debug builds.

[build]
codegen-units = 4
opt-level = 1

Sccache

Sccache is a compiler-caching tool that stores compilation results on disk or in cloud storage, reducing duplicated work across projects or crates. This optimization is particularly useful for CI/CD pipelines where builds are executed in fresh instances or containers.

fleet build --sccache

Custom Linker

Fleet configures and uses a custom linker to improve build performance, especially for large projects with deep dependency trees. The choice of linker depends on the operating system:

  • Linux: clang + lld
  • Windows: rust-lld.exe
  • Mac OS: zld
fleet run --linker clang

Faster Rust Build Times with Fleet

By leveraging Fleet’s multi-platform and multi-environment optimizations, developers can significantly reduce compile times and improve their overall development experience. While Fleet is still in beta, it’s worth trying out, especially if you’re struggling with slow build times.

Leave a Reply