I'm trying to port C++ software to Rust and one of the parts is fetching a git submodule with a C++ library. I'd like to integrate that action into my custom build.rs script instead of forcing a user to do that manually before running cargo build. Here is my build.rs:
fn main() {
std::process::Command::new("git")
.args([
"submodule",
"update",
"--init",
"--depth 1",
"--recommend-shallow",
])
.output()
.expect("Failed to fetch git submodules!");
// here C++ code compilation with cc::Build happens
}
Unfortunately: the command didn't execute -> the submodule wasn't fetched -> C++ compiler started complaining about missing headers -> cargo threw an error. Otherwise than that build.rs is totally fine, because it worked perfectly after running git submodule update manually before cargo build. Suprisingly enough changing the command to echo cargo:warning=test, catching the output of the std::process::Command and outputting it with io::stdout().write_all(&output.stdout).unwrap(); resulted in cargo correctly reporting a warning. touching a test file and later rming it after the compilation worked as well. Why git doesn't work, but these commands do?
git submodule's usage info, which is printed every time you enter a bad command. It made me think and I've just split the--depth 1argument into 2 separate ones. Sure enough stderr is now empty, but the build script still errors out with litany of errors in stdout.