Skip to content

Commit f2c08ff

Browse files
committed
Make git2 optional
Fixes #3072
1 parent ac5938e commit f2c08ff

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ binaries = [
3838
"av-metrics",
3939
"nom",
4040
]
41-
default = ["binaries", "asm", "threading", "signal_support"]
41+
default = ["binaries", "asm", "threading", "signal_support", "git_version"]
42+
git_version = ["built/git2"]
4243
asm = ["nasm-rs", "cc"]
4344
threading = ["rayon/threads"]
4445
signal_support = ["signal-hook"]
@@ -118,7 +119,7 @@ features = ["png"]
118119
[build-dependencies]
119120
cc = { version = "1.0", optional = true, features = ["parallel"] }
120121
rustc_version = "0.4"
121-
built = { version = "0.5.1", features = ["git2", "chrono"] }
122+
built = { version = "0.5.1", features = ["chrono"] }
122123

123124
[build-dependencies.nasm-rs]
124125
version = "0.2"

src/lib.rs

+21-6
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,33 @@ pub mod version {
407407
}
408408
}
409409

410+
cfg_if::cfg_if! {
411+
if #[cfg(feature="git_version")] {
412+
fn git_version() -> &'static str {
413+
crate::built_info::GIT_VERSION.unwrap_or_default()
414+
}
415+
416+
fn git_hash() -> &'static str {
417+
crate::built_info::GIT_COMMIT_HASH.unwrap_or_default()
418+
}
419+
} else {
420+
fn git_version() -> &'static str {
421+
"UNKNOWN"
422+
}
423+
424+
fn git_hash() -> &'static str {
425+
"UNKNOWN"
426+
}
427+
}
428+
}
410429
/// Commit hash (short)
411430
///
412431
/// Short hash of the git commit used by this build
413432
///
414433
/// e.g. `g743d464`
415434
///
416435
pub fn hash() -> String {
417-
crate::built_info::GIT_COMMIT_HASH.unwrap_or_default().to_string()
436+
git_hash().to_string()
418437
}
419438

420439
/// Version information with the information
@@ -423,11 +442,7 @@ pub mod version {
423442
/// e.g. `0.1.0 (v0.1.0-1-g743d464)`
424443
///
425444
pub fn full() -> String {
426-
format!(
427-
"{} ({})",
428-
short(),
429-
crate::built_info::GIT_VERSION.unwrap_or_default()
430-
)
445+
format!("{} ({})", short(), git_version(),)
431446
}
432447
}
433448
#[cfg(all(

0 commit comments

Comments
 (0)