diff --git a/Cargo.lock b/Cargo.lock index 629693d50..b7381b4a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -337,6 +337,7 @@ dependencies = [ "cxx-gen", "errno 0.2.8", "fast-float", + "git-version", "hexponent", "inventory", "lazy_static", @@ -368,6 +369,28 @@ dependencies = [ "wasi", ] +[[package]] +name = "git-version" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6b0decc02f4636b9ccad390dcbe77b722a77efedfa393caf8379a51d5c61899" +dependencies = [ + "git-version-macro", + "proc-macro-hack", +] + +[[package]] +name = "git-version-macro" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe69f1cbdb6e28af2bac214e943b99ce8a0a06b447d15d3e61161b0423139f3f" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "glob" version = "0.3.1" @@ -705,6 +728,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "proc-macro-hack" +version = "0.5.20+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" + [[package]] name = "proc-macro2" version = "1.0.66" diff --git a/Cargo.toml b/Cargo.toml index 1718f07ff..a56d077dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,6 +60,7 @@ rand = { version = "0.8.5", features = ["small_rng"] } unixstring = "0.2.7" widestring = "1.0.2" rand_pcg = "0.3.1" +git-version = "0.3" [build-dependencies] autocxx-build = "0.23.1" @@ -80,4 +81,4 @@ fish-ffi-tests = ["inventory"] # The following features are auto-detected by the build-script and should not be enabled manually. asan = [] -bsd = [] \ No newline at end of file +bsd = [] diff --git a/fish-rust/build.rs b/fish-rust/build.rs index fe19c27f5..934585eba 100644 --- a/fish-rust/build.rs +++ b/fish-rust/build.rs @@ -14,7 +14,7 @@ fn main() { .file("fish-rust/src/compat.c") .compile("libcompat.a"); - let rust_dir = std::env::var("CARGO_MANIFEST_DIR").expect("Env var CARGO_MANIFEST_DIR missing"); + let rust_dir = env!("CARGO_MANIFEST_DIR"); let target_dir = std::env::var("FISH_RUST_TARGET_DIR").unwrap_or(format!("{}/{}", rust_dir, "target/")); let cpp_fish_src_dir = format!("{}/{}", rust_dir, "src/"); diff --git a/fish-rust/src/lib.rs b/fish-rust/src/lib.rs index f65ed25d9..e4e644c24 100644 --- a/fish-rust/src/lib.rs +++ b/fish-rust/src/lib.rs @@ -10,6 +10,11 @@ #![allow(clippy::ptr_arg)] #![allow(clippy::field_reassign_with_default)] +pub const BUILD_VERSION: &str = match option_env!("FISH_BUILD_VERSION") { + Some(v) => v, + None => git_version::git_version!(args = ["--always", "--dirty=-dirty"], fallback = "unknown"), +}; + #[macro_use] mod common;