diff --git a/Cargo.toml b/Cargo.toml index bc2d5e7f74..d7b69ff27f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,8 @@ binaries = [ "av-metrics", "nom", ] -default = ["binaries", "asm", "threading", "signal_support"] +default = ["binaries", "asm", "threading", "signal_support", "git_version"] +git_version = ["built/git2"] asm = ["nasm-rs", "cc"] threading = ["rayon/threads"] signal_support = ["signal-hook"] @@ -118,7 +119,7 @@ features = ["png"] [build-dependencies] cc = { version = "1.0", optional = true, features = ["parallel"] } rustc_version = "0.4" -built = { version = "0.5.1", features = ["git2", "chrono"] } +built = { version = "0.5.1", features = ["chrono"] } [build-dependencies.nasm-rs] version = "0.2" diff --git a/src/lib.rs b/src/lib.rs index 48a14e89dc..9f23e516cf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -407,6 +407,25 @@ pub mod version { } } + cfg_if::cfg_if! { + if #[cfg(feature="git_version")] { + fn git_version() -> &'static str { + crate::built_info::GIT_VERSION.unwrap_or_default() + } + + fn git_hash() -> &'static str { + crate::built_info::GIT_COMMIT_HASH.unwrap_or_default() + } + } else { + fn git_version() -> &'static str { + "UNKNOWN" + } + + fn git_hash() -> &'static str { + "UNKNOWN" + } + } + } /// Commit hash (short) /// /// Short hash of the git commit used by this build @@ -414,7 +433,7 @@ pub mod version { /// e.g. `g743d464` /// pub fn hash() -> String { - crate::built_info::GIT_COMMIT_HASH.unwrap_or_default().to_string() + git_hash().to_string() } /// Version information with the information @@ -423,11 +442,7 @@ pub mod version { /// e.g. `0.1.0 (v0.1.0-1-g743d464)` /// pub fn full() -> String { - format!( - "{} ({})", - short(), - crate::built_info::GIT_VERSION.unwrap_or_default() - ) + format!("{} ({})", short(), git_version(),) } } #[cfg(all(