Unlocking Faster Rust Build Times with Fleet

Rust’s long compile times have been a persistent concern for developers, especially when working on large projects or crates with many dependencies. While the language prioritizes runtime performance over compile-time performance, this can lead to frustrating wait times during development. In this article, we’ll explore Fleet, a build tool designed to alleviate these issues and significantly speed up your Rust build times.

What is Fleet?

Fleet is a one-stop solution for optimizing Rust build times, both for 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

Installing Fleet requires Rust to be installed on your machine. Once set up, you can use Fleet with four command-line arguments: -h/--help, -V/--version, build, and 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:

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.

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.

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.

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: clang + lld for Linux, rust-lld.exe for Windows, and zld for Mac OS.

Conclusion

Fleet has the potential to revolutionize Rust development by providing a powerful, all-in-one package for optimizing build speeds. By leveraging its 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

Your email address will not be published. Required fields are marked *