tips-for-faster-rust-compile
Updatge Rust Compiler And ToolChain
Rust 一直在持续不断的优化编译的速度,因此定期更新你的 Rust 编译器和工具链是非常重要的。
1 | rustup update |
Cargo Check
Cargo check 是一个非常有用的工具,它可以在不编译代码的情况下检查你的代码是否有语法错误或其他问题。这可以大大加快你的开发速度。
Remove Unused Dependencies
1 | cargo install cargo-machete && cargo machete |
Update Dependencies
cargo update会自动更新所有依赖项到最新版本。cargo tree --duplicate查找多个版本的依赖项,目的是通过更新依赖旧版本的依赖项来合并到单个版本(待验证)
Faster Linker
- Linux/Macos: https://lld.llvm.org/
- Linux: https://github.com/rui314/mold
目前github 上比较活跃的还有: https://github.com/davidlattimore/wild 可以根据实际的情况选择
拆分 Crates
- 将大的 crate 分解成更小的 crate,可以提高编译速度和可维护性。
- 使用
cargo workspaces来管理多个 crate。
MacOS: Faster Incremental Debug Builds
在 Cargo.toml 中添加
1 | [profile.dev] |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 DoYouDo!
评论