Skip to content

Instantly share code, notes, and snippets.

@janhohenheim
Last active May 14, 2026 11:41
Show Gist options
  • Select an option

  • Save janhohenheim/5731c11e91736bab5e9ef58c2a982c36 to your computer and use it in GitHub Desktop.

Select an option

Save janhohenheim/5731c11e91736bab5e9ef58c2a982c36 to your computer and use it in GitHub Desktop.
My global config.toml setup for ultra fast Rust compile times
[unstable]
codegen-backend = true
[profile.dev]
# Compile using cranelift for massively faster compilation
codegen-backend = "cranelift"
# If you want to attach a debugger, set `debug = true` instead
debug = "line-tables-only"
# Assuming we don't do `catch_unwind`, we can safely abort on panics for some extra perf
panic = "abort"
# Consider compiling deps with cranelift if you want cold-compilation to be faster
# Or, if you want your hot compilation to have max performance, copy the contents of `[profile.dev.build-override]` here
# The setting below is a happy medium between performance and cold compile time.
[profile.dev.package."*"]
codegen-backend = "llvm"
# cranelift is always `panic = abort`, so you need to compile with llvm to get `#[should_panic]` working
# See <https://github.com/rust-lang/rust/issues/32512>
[profile.test.package."*"]
codegen-backend = "llvm"
# Enable optimizations for build scripts and proc-macros
# This trades slower cold compilation for faster incremental compilation
[profile.dev.build-override]
codegen-backend = "llvm"
codegen-units = 1
opt-level = 3
# Disable cranelift for release profile,
# and trade some compile time for increased performance
[profile.release]
codegen-backend = "llvm"
codegen-units = 1
# lto = "fat" has very diminishing returns on performance, but extremely high compile times
# "thin" is good enough.
lto = "thin"
# Assuming we don't do `catch_unwind`, we can safely abort on panics for some extra perf
panic = "abort"
# cranelift cannot build wasm32-unknown-unknown out of the box
[profile.web]
codegen-backend = "llvm"
[build]
# Using a global target dir allows all projects to share incremental compilation results,
# vastly speeding up cold-compilation of new projects.
target-dir = "/home/hhh/.cargo/global-target"
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = [
"-Clink-arg=--ld-path=wild",
# Compile faster
"-Zshare-generics=y",
# 8 is the limit where parallelism overhead begins to dominate
"-Zthreads=8",
# optimize for the current CPU
# remove this if you want to share the binary with others
"-Ctarget-cpu=native",
]
rustdocflags = [
# Compile faster
"-Zshare-generics=y",
# 8 is the limit where parallelism overhead begins to dominate
"-Zthreads=8",
]
[target.wasm32-unknown-unknown]
rustflags = [
# Compile faster
"-Zshare-generics=y",
# 8 is the limit where parallelism overhead begins to dominate
"-Zthreads=8",
# optimize for the current CPU
# remove this if you want to share the binary with others
"-Ctarget-cpu=native",
]
rustdocflags = [
# Compile faster
"-Zshare-generics=y",
# 8 is the limit where parallelism overhead begins to dominate
"-Zthreads=8",
]
@janhohenheim
Copy link
Copy Markdown
Author

janhohenheim commented May 20, 2025

Put the above in ~/.cargo/config.toml.
Requires:

  • Linux
  • nightly: rustup default nightly
  • cranelift: rustup component add rustc-codegen-cranelift-preview --toolchain nightly
  • wild linker: cargo install --locked wild-linker
  • Bevy CLI: cargo install --git https://github.com/TheBevyFlock/bevy_cli --locked bevy_cli

and assumes you run your apps with bevy run and bevy run web -U multi-threading.
Also make sure to enable the dynamic_linking for Bevy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment