cargo-binstall/crates/bin/build.rs
Jiahao XU 28525359d3
Ensure cargo-binstall build.rs always join the thread (#2185)
Make sure the build script waits for it to finish before exiting the whole process

Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com>
2025-06-06 07:36:07 +00:00

52 lines
1.3 KiB
Rust

use std::{
io,
path::Path,
process::{Child, Command},
thread,
};
fn succeeds(res: io::Result<Child>) -> bool {
res.and_then(|mut child| child.wait())
.map(|status| status.success())
.unwrap_or(false)
}
fn emit_vergen_info() {
let git = Command::new("git").arg("--version").spawn();
// .git is usually a dir, but it also can be a file containing
// path to another .git if it is a submodule.
//
// If build.rs is run on a git repository, then ../../.git
// should exists.
let is_git_repo = Path::new("../../.git").exists();
let mut builder = vergen::EmitBuilder::builder();
builder.all_build().all_cargo().all_rustc();
if is_git_repo && succeeds(git) {
builder.all_git();
} else {
builder.disable_git();
}
builder.emit().unwrap();
}
fn main() {
thread::scope(|s| {
let handle = s.spawn(|| {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=manifest.rc");
println!("cargo:rerun-if-changed=windows.manifest");
embed_resource::compile("manifest.rc", embed_resource::NONE)
.manifest_required()
.unwrap();
});
emit_vergen_info();
handle.join().unwrap();
});
}