The book · Appendix

Fast compiles

You change one line, you want to see it, and you wait. What you wait for is a rebuild: Cargo compiling what changed and joining it to the rest, a job called linking. It's the wait you'll meet a hundred times a day, so it's the one that matters. A game made with shuyi new rebuilds in about a second, on the stable Rust it pins:

A new grid gameLinuxWindows (MSVC)Windows (GNU)
Rebuild after a one-line change in main.rs0.7–1.0 s1.8–1.9 s1.1 s
cargo check after the same change (what an editor runs)0.1 s0.2 s0.2 s
Clean build40–55 s105–120 s25 s

A clean build compiles everything, the engine included, as your first build does. cargo check looks for errors and doesn't make a program, which is why it's so quick. MSVC and GNU are Rust's two toolchains on Windows (chapter 1).

Linux and Windows (MSVC) are GitHub's 4-core runners; Windows (GNU) is a 24-core desktop. The engine's CI measures a new game's rebuild on every change to the engine, and fails one that goes over its budget.

The setup

You don't need to do anything for this: it comes with a new game. It is in the root Cargo.toml, whose comments say the same, and you can read on if you want to change it.

Linking the engine as one dynamic library, a file loaded when the program starts, as Bevy's dynamic_linking does, made no rebuild faster: the engine's crates are few and already built, so linking them statically, into the program, costs little.

When it's slow

On a nightly toolchain

Nightly is the Rust that's built each night, with features not yet finished. Two more options may help, for a developer to try in their own .cargo/config.toml: the Cranelift backend (-Zcodegen-backend=cranelift, with the rustc-codegen-cranelift component) and shared generics (-Zshare-generics=y).