mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-20 20:48:43 +00:00

that provides more information: ``` cargo-binstall: 1.0.0 build-date: 2023-07-18 build-target: aarch64-apple-darwin build-features: default,fancy_no_backtrace,git,rustls,static,trust_dns,zstd_thin build-commit-hash: 39d8cfc07f2253080ce997e620406c2994dced25 build-commit-date: 2023-07-18 rustc-version: 1.71.0 rustc-commit-hash: 8ede3aae28fe6e4d52b38157d7bfe0d3bceef225 rustc-llvm-version: 16.0 ``` Fixed #627 Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
44 lines
1.1 KiB
Rust
44 lines
1.1 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 main() {
|
|
let handle = thread::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);
|
|
});
|
|
|
|
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();
|
|
|
|
handle.join().unwrap();
|
|
}
|