Faster Rust builds on macOS
After working on a Rust project for a client, I must admit that the build times eventually got the best of me. Being a polyglot developer I’m used to jumping between different languages and Go has definitely spoiled me when it comes to build times. My development machine is a maxed out MacBook Pro 16" and this medium sized project would take 3–5 minutes to compile (although throttling is definitely an issue here as well). Anyway, what gives?
Linux
To improve build times on Linux, the general advice is to use lld and that gives a massive boost (at least 50%+). But what about macOS?
macOS
Scavenging around on the web I found bits and pieces here and there, and decided to write down my findings here.
On macOS we can use zld by Michael Eisel to speed up things significantly. Just follow the following steps:
- Install the Xcode command line tools:
xcode-select --install
2. Switch the command line tools to the directory where xcodebuild
resides to make it available to the zld build process, otherwise it will fail:
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
3. Use Homebrew to build and install zld:
brew install michaeleisel/zld/zld
4. Create a cargo config file in .cargo/config
in your home directory with the following content:
[target.x86_64-apple-darwin]
rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/zld"]
- Save the config file
- ???
- Profit!
This gave me around 39–52% faster build times, depending on the project and the amount of dependencies that were used. Sweet!
Till next time!