我有以下 crate 结构:
|── proj/
└── src/
└── bin/
└── foo-bin-rs/
└── src/
└── main.rs
└── Cargo.toml
└── main.rs
└── Cargo.toml
└── build.rs
foo-bin-rs
是一个子模块。我想找到一种干净的方式来发布构建
通过 cargo 命令构建 foo-bin-rs
作为构建的一部分
用于 proj
的命令。我没有找到任何使用
src/bin
目录中的二进制文件是它们自己单独的箱子,只是
单个文件。我的第一个想法是拥有一个发布自己的 build.rs
cargo
命令,但我找不到允许通过
用作 root 的目录。对此的规范解决方案是什么?
最佳答案
My first thought was to have a build.rs that issued its own cargo command, but I couldn't find a flag for cargo that allowed passing a directory to use as root.
有一个命令行参数,但它不需要目录;相反,它需要 Cargo.toml
文件的完整路径。该参数名为 --manifest-path
,它可用于许多子命令,例如 build
和 run
。它是这样使用的(注意相对路径也是有效的):
$ cargo build --manifest-path=/path/to/proj/src/bin/foo-bin-rs/Cargo.toml
如果您需要从构建脚本运行可执行文件,您可以像往常一样简单地使用 cargo run
一次性构建和运行。
关于rust - 用 cargo 构建子模块二进制箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43882955/