应用大小
虽然 Tauri 默认提供非常小的二进制文件,但略微提升一下限制也无妨,因此这里有一些技巧和提示来达到最佳效果。
Cargo 配置
您可以为项目做出的一项最简单的前端无关的大小优化是添加一个 Cargo 配置文件。
根据您使用的是稳定版还是夜间构建版 Rust 工具链,可供选择的功能略有不同。建议您除非是高级用户,否则坚持使用稳定工具链。
[profile.dev]incremental = true # Compile your binary in smaller steps.
[profile.release]codegen-units = 1 # Allows LLVM to perform better optimization.lto = true # Enables link-time-optimizations.opt-level = "s" # Prioritizes small binary size. Use `3` if you prefer speed.panic = "abort" # Higher performance by disabling panic handlers.strip = true # Ensures debug symbols are removed.
[profile.dev]incremental = true # Compile your binary in smaller steps.rustflags = ["-Zthreads=8"] # Better compile performance.
[profile.release]codegen-units = 1 # Allows LLVM to perform better optimization.lto = true # Enables link-time-optimizations.opt-level = "s" # Prioritizes small binary size. Use `3` if you prefer speed.panic = "abort" # Higher performance by disabling panic handlers.strip = true # Ensures debug symbols are removed.trim-paths = "all" # Removes potentially privileged information from your binaries.rustflags = ["-Cdebuginfo=0", "-Zthreads=8"] # Better compile performance.
参考
- incremental: 分小步骤编译二进制。
- codegen-units: 折中编译时间以加快编译速度。
- lto: 启用链接时优化。
- opt-level: 决定编译器的焦点。使用
3
优化性能,z
优化大小,或s
在两者之间取得平衡。 - panic: 通过删除恐慌解析来减少大小。
- strip: 从二进制中删除符号或调试信息。
- rpath: 通过在二进制中硬编码信息来协助查找二进制所需的动态库。
- trim-paths: 从二进制中删除潜在受权信息。
- rustflags: 按配置文件设置基于 Rust 编译器的标志。
-Cdebuginfo=0
: 是否在构建中包含调试信息符号。-Zthreads=8
: 在编译时增加线程数量。
版权所有 2025 Tauri 贡献者。CC-BY / MIT