Skip to content

Commit

Permalink
respect rust-lang/rust's omit-git-hash
Browse files Browse the repository at this point in the history
The config.toml file in rust-lang/rust has the omit-git-hash option,
which prevents git information from being embedded into binaries. This
works for most tools, as they rely on the git information provided by
bootstrap through environment variables.

Cargo does its own git detection in its build script though, which
didn't adhere to to that option. This changes that by skipping git
detection whenever bootstrap signals the option is enabled.
  • Loading branch information
pietroalbini committed Nov 13, 2023
1 parent 2cbbf6e commit ab76a0b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ fn commit_info() {
if !Path::new(".git").exists() {
return;
}

// Var set by bootstrap whenever omit-git-hash is enabled in rust-lang/rust's config.toml.
println!("cargo:rerun-if-env-changed=CFG_OMIT_GIT_HASH");
#[allow(clippy::disallowed_methods)]
if std::env::var_os("CFG_OMIT_GIT_HASH").is_some() {
return;
}

let output = match Command::new("git")
.arg("log")
.arg("-1")
Expand Down

0 comments on commit ab76a0b

Please sign in to comment.