我想在我的 rust 程序中生成一些 .rs 代码,并创建一个gen-proxy-ffi用于bindgen执行此操作的包。下面的命令可以生成我需要的代码。
cargo run --package gen-proxy-ffi --bin gen-proxy-ffi
Run Code Online (Sandbox Code Playgroud)
生成代码后,我可以通过以下方式构建整个项目
cargo build
Run Code Online (Sandbox Code Playgroud)
现在,我想cargo build通过调用自动生成代码cargo run --package gen-proxy-ffi --bin gen-proxy-ffi。我知道我可以向 build.rs 编写一些代码来指定 rust 的编译例程,因此我编写了以下代码,其中 make-gen-proxy-ffi.sh encaplsules cargo run --package gen-proxy-ffi --bin gen-proxy-ffi。
// build.rs
use std::process::Command;
use std::io::Write;
fn main() {
let o = Command::new("sh").args(&["make-gen-proxy-ffi.sh"]).output().expect("sh exec error!");
}
Run Code Online (Sandbox Code Playgroud)
但是,现在运行时cargo build,会打印出以下错误
+ cargo run --package gen-proxy-ffi --bin gen-proxy-ffi --
Blocking waiting for file lock on build directory
Run Code Online (Sandbox Code Playgroud)
经过一番搜索,我知道这是因为 cargo build同一个项目同时进行了两次。
但是,从这篇文章中,我没有找到解决方案,所以我想知道是否有任何方法可以生成代码并一次构建整个项目cargo build?
| 归档时间: |
|
| 查看次数: |
1791 次 |
| 最近记录: |