### Cargo code snippets for different optimizations ## Dev build compilation speed optimization (more https://benw.is/posts/how-i-improved-my-rust-compile-times-by-seventy-five-percent) # Work only with the nightly version of Rust by the time it was written; it is recommended NOT to use it in production for now cargo-features = [ "codegen-backend", "profile-rustflags" ] # Important: It provides less useful error messages during compilation [profile.dev] opt-level = 1 codegen-backend = "cranelift" rustflags = [ "-Z", "threads=8", # Enable parallel frontend compiling "-C", "linker=clang", # Use clang as the linker "-C", "link-arg=-fuse-ld=mold", # Use mold as the linker backend "-C", "link-arg=-static", ] [profile.dev.package."*"] opt-level = 3 codegen-backend = "cranelift" [profile.dev.build-override] rustflags = [ "-Z", "threads=8", "-C", "link-arg=-fuse-ld=/run/current-system/sw/bin/mold" ] # `/run/current-system/sw/bin/mold` is an absolute path to the mold executable ## Release build size optimization (more https://github.com/johnthagen/min-sized-rust) # You can also use programs such as `upx` for size optimization [profile.release] strip = true opt-level = "z" # You can try 's' instead of 'z' if you want to optimize for speed lto = true codegen-units = 1 panic = "abort" # DELETE extra unwinding code that provides helpful backtrace information for runtime errors [profile.release.build-override] rustflags = [ "-Z", "location-detail=none" ] # DELETE a useful traceback information such as file, line, and column information for panic!() and [track_caller]