Rust 支持使用 profile 自定义构建,Profile 是预定义的,可使用不同的配置,对代码编译拥有更多的控制
介绍
Profile 分类:
release profile:发布环境通过 cargo build --release 使用
dev profile:开发环境通过 cargo build 使用
支持自定义profile
在 Cargo.toml 中,添加 [profile.xxx] section,在里面覆盖默认配置的子集
[profile.dev]
opt-level = 1
[profile.release]
opt-level = 3
说明:
opt-level 指定优化程度,值 [0~3,s,z],越大编译时间越长
- 更多参数配置参考:https://doc.rust-lang.org/stable/cargo/reference/profiles.html