cargo-make rust 任务执行以及构建工具

发布时间 2023-12-18 09:32:53作者: 荣锋亮

再学习nakago 框架的时候发现其使用了cargo-make 这个工具,但是很方便,类似make 的构建模式

包含的特性

依赖管理,别名支持,支持workspace

简单使用

  • 安装
cargo install --force cargo-make
  • 参考使用
    创建一个cargo 项目
 
cargo new appdemo

Makefile.toml 文件

[tasks.format]
install_crate = "rustfmt"
command = "cargo"
args = ["fmt", "--", "--emit=files"]
 
[tasks.clean]
command = "cargo"
args = ["clean"]
 
[tasks.build]
command = "cargo"
args = ["build"]
dependencies = ["clean"]
 
[tasks.test]
command = "cargo"
args = ["test"]
dependencies = ["clean"]
 
[tasks.my-flow]
dependencies = [
    "format",
    "build",
    "test"
]

效果

  • 运行
cargo make my-flow

效果

说明

对于golang 开发有一些实践是基于make cargo-make 工具可以让我们基于make 类似的模式进行开发管理,很值得使用下

参考资料

https://sagiegurari.github.io/cargo-make/
https://github.com/sagiegurari/cargo-make
https://github.com/bkonkle/nakago-simple-template/blob/main/template/Makefile.toml
https://sagiegurari.github.io/cargo-make/#usage-workspace-support