6

I want to generate some .rs code in my rust program, and I create a package gen-proxy-ffi which use bindgen to do that. The following command can generate codes I need.

cargo run --package gen-proxy-ffi --bin gen-proxy-ffi 

When the codes are generated, I can then build the whole project by

cargo build

Now, I want cargo build will automaticly generate code by calling cargo run --package gen-proxy-ffi --bin gen-proxy-ffi. I know I can write some code to build.rs to specify rust's compiling routine, so I write the following codes, where 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!");
}

However, when running cargo build now, it prints out the following error

+ cargo run --package gen-proxy-ffi --bin gen-proxy-ffi --
    Blocking waiting for file lock on build directory

After some searching, I know it is because cargo build on the same project twice at one time.

However, from this post, I found no solution to this, so I wonder if there are any ways I can generate code and build the whole project by one cargo build?

calvin
  • 2,125
  • 2
  • 21
  • 38
  • I would've hoped setting a different `CARGO_TARGET_DIR` would help, but I'm not getting any success with that – kmdreko Sep 03 '21 at 16:27

0 Answers0