diff --git a/Cargo.lock b/Cargo.lock index fbd24bca5e..95f2e7481f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4191,7 +4191,6 @@ checksum = "f47e98e36909e951f4da3908f4475f969bec92a41734dd92e883aaa11c10294b" dependencies = [ "chrono", "const_format", - "git2", "is_debug", ] diff --git a/crates/nu-command/Cargo.toml b/crates/nu-command/Cargo.toml index 789884f9db..16419644f1 100644 --- a/crates/nu-command/Cargo.toml +++ b/crates/nu-command/Cargo.toml @@ -70,7 +70,8 @@ serde_ini = "0.2.0" serde_urlencoded = "0.7.0" serde_yaml = "0.8.16" sha2 = "0.10.0" -shadow-rs = "0.11.0" +# Disable default features b/c the default features build Git (very slow to compile) +shadow-rs = { version = "0.11.0", default-features = false } strip-ansi-escapes = "0.1.1" sysinfo = "0.23.5" terminal_size = "0.1.17" @@ -112,7 +113,7 @@ dataframe = ["polars", "num"] database = ["sqlparser", "rusqlite"] [build-dependencies] -shadow-rs = "0.11.0" +shadow-rs = { version = "0.11.0", default-features = false } [dev-dependencies] hamcrest2 = "0.3.0" diff --git a/crates/nu-command/build.rs b/crates/nu-command/build.rs index 4a0dfc4591..67343c24b8 100644 --- a/crates/nu-command/build.rs +++ b/crates/nu-command/build.rs @@ -1,3 +1,18 @@ +use std::process::Command; + fn main() -> shadow_rs::SdResult<()> { + // Look up the current Git commit ourselves instead of relying on shadow_rs, + // because shadow_rs does it in a really slow-to-compile way (it builds libgit2) + let hash = get_git_hash().expect("failed to get latest git commit hash"); + println!("cargo:rustc-env=NU_COMMIT_HASH={}", hash); + shadow_rs::new() } + +fn get_git_hash() -> Result { + let out = Command::new("git").args(["rev-parse", "HEAD"]).output()?; + Ok(String::from_utf8(out.stdout) + .expect("could not convert stdout to string") + .trim() + .to_string()) +} diff --git a/crates/nu-command/src/core_commands/version.rs b/crates/nu-command/src/core_commands/version.rs index 77b5ab6587..a6b75156b5 100644 --- a/crates/nu-command/src/core_commands/version.rs +++ b/crates/nu-command/src/core_commands/version.rs @@ -63,21 +63,7 @@ pub fn version( span: call.head, }); - cols.push("tag".to_string()); - vals.push(Value::String { - val: shadow_rs::tag(), - span: call.head, - }); - - let short_commit: Option<&str> = Some(shadow::SHORT_COMMIT).filter(|x| !x.is_empty()); - if let Some(short_commit) = short_commit { - cols.push("short_commit".to_string()); - vals.push(Value::String { - val: short_commit.to_string(), - span: call.head, - }); - } - let commit_hash: Option<&str> = Some(shadow::COMMIT_HASH).filter(|x| !x.is_empty()); + let commit_hash: Option<&str> = option_env!("NU_COMMIT_HASH"); if let Some(commit_hash) = commit_hash { cols.push("commit_hash".to_string()); vals.push(Value::String { @@ -85,14 +71,6 @@ pub fn version( span: call.head, }); } - let commit_date: Option<&str> = Some(shadow::COMMIT_DATE).filter(|x| !x.is_empty()); - if let Some(commit_date) = commit_date { - cols.push("commit_date".to_string()); - vals.push(Value::String { - val: commit_date.to_string(), - span: call.head, - }); - } let build_os: Option<&str> = Some(shadow::BUILD_OS).filter(|x| !x.is_empty()); if let Some(build_os) = build_os {