Skip to content

Commit

Permalink
Make git2 optional
Browse files Browse the repository at this point in the history
Fixes #3072
  • Loading branch information
lu-zero committed Dec 5, 2022
1 parent ac5938e commit f2c08ff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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"
Expand Down
27 changes: 21 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,33 @@ 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
///
/// 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
Expand All @@ -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(
Expand Down

0 comments on commit f2c08ff

Please sign in to comment.