diff --git a/Cargo.lock b/Cargo.lock index 7550e7f7b..e4a02ecee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1787,6 +1787,8 @@ dependencies = [ "bitflags", "libc", "libgit2-sys", + "openssl-probe", + "openssl-sys", "log 0.4.11", "url 2.1.1", ] @@ -2458,7 +2460,9 @@ checksum = "9b33bf3d9d4c45b48ae1ea7c334be69994624dc0a69f833d5d9f7605f24b552b" dependencies = [ "cc", "libc", + "libssh2-sys", "libz-sys", + "openssl-sys", "pkg-config", ] @@ -2483,6 +2487,20 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "libssh2-sys" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eafa907407504b0e683786d4aba47acf250f114d37357d56608333fd167dd0fc" +dependencies = [ + "cc", + "libc", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", +] + [[package]] name = "libz-sys" version = "1.0.25" diff --git a/crates/nu-cli/Cargo.toml b/crates/nu-cli/Cargo.toml index 8a9fd2879..9b0efb3e8 100644 --- a/crates/nu-cli/Cargo.toml +++ b/crates/nu-cli/Cargo.toml @@ -114,6 +114,8 @@ optional = true version = "0.23.1" [build-dependencies] +git2 = "0.13" + [dev-dependencies] quickcheck = "0.9" diff --git a/crates/nu-cli/build.rs b/crates/nu-cli/build.rs new file mode 100644 index 000000000..7a3529943 --- /dev/null +++ b/crates/nu-cli/build.rs @@ -0,0 +1,28 @@ +use git2::Repository; +use std::path::Path; +use std::{env, fs, io}; + +fn main() -> Result<(), io::Error> { + let out_dir = env::var_os("OUT_DIR").expect( + "\ + OUT_DIR environment variable not found. \ + OUT_DIR is guaranteed to to exist in a build script by cargo - see \ + https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts\ + "); + + let latest_commit_hash = latest_commit_hash(env::current_dir()?).unwrap_or_default(); + + let commit_hash_path = Path::new(&out_dir).join("git_commit_hash"); + fs::write(commit_hash_path, latest_commit_hash)?; + + Ok(()) +} + +fn latest_commit_hash>(dir: P) -> Result { + let dir = dir.as_ref(); + Ok(Repository::discover(dir)? + .head()? + .peel_to_commit()? + .id() + .to_string()) +} diff --git a/crates/nu-cli/src/commands/version.rs b/crates/nu-cli/src/commands/version.rs index 5ca2d2e13..db80eeda0 100644 --- a/crates/nu-cli/src/commands/version.rs +++ b/crates/nu-cli/src/commands/version.rs @@ -5,6 +5,8 @@ use indexmap::IndexMap; use nu_errors::ShellError; use nu_protocol::{Dictionary, Signature, UntaggedValue}; +const GIT_COMMIT_HASH: &str = include_str!(concat!(env!("OUT_DIR"), "/git_commit_hash")); + pub struct Version; #[async_trait] @@ -48,6 +50,14 @@ pub fn version(args: CommandArgs, _registry: &CommandRegistry) -> Result