Skip to content

Commit

Permalink
Allow to build without pulling git-version and concat_const
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Oct 1, 2024
1 parent 1df6829 commit 1a916c1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
15 changes: 11 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ bitflags = "2"
bzip2 = "0.4"
byteorder = "1"
cfg-if = "1"
concat_const = "0.1"
cstr = "0.2.10"
derivative = "2"
digest = "0.10"
either = "1"
getset = "0.1"
git-version = "0.3"
hex = "0.4"
hex-literal = "0.4"
indexmap = "2"
Expand All @@ -66,6 +64,10 @@ features = ["std"]
version = "4.2"
features = ["cargo", "derive"]

[dependencies.concat_const]
version = "0.1"
optional = true

[target.'cfg(windows)'.dependencies.curl-sys]
version = "0.4"
default-features = false
Expand All @@ -85,6 +87,10 @@ version = "1"
default-features = false
features = ["zlib"]

[dependencies.git-version]
version = "0.3"
optional = true

[target.'cfg(windows)'.dependencies.libz-sys]
version = "1"
features = ["static"]
Expand Down Expand Up @@ -153,13 +159,14 @@ panic = "abort"
panic = "abort"

[features]
default = ["version-check"]
default = ["full-version", "version-check"]
full-version = ["dep:concat_const", "dep:git-version"]
# libcurl.so compatibility (Linux only).
curl-compat = ["rustflags"]
# Check and report when a new version is available.
version-check = ["shared_child"]
# Download and apply new versions.
self-update = ["shared_child", "dep:tar", "dep:xz2", "dep:zip", "windows-sys/Win32_System_Threading"]
self-update = ["shared_child", "dep:concat_const", "dep:tar", "dep:xz2", "dep:zip", "windows-sys/Win32_System_Threading"]

# Development features

Expand Down
13 changes: 12 additions & 1 deletion src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,31 +171,42 @@ macro_rules! full_version {
mod static_ {
use clap::crate_version;
// Work around https://github.com/rust-lang/rust-analyzer/issues/8828 with `as cat`.
#[cfg(feature = "full-version")]
use concat_const::concat as cat;
#[cfg(feature = "full-version")]
use git_version::git_version;

#[cfg(any(feature = "version-check", feature = "self-update"))]
use super::BuildBranch;

pub const SHORT_VERSION: &str = crate_version!();
#[cfg(feature = "full-version")]
const GIT_VERSION: &str = git_version!(
args = ["--always", "--match=nothing/", "--abbrev=40", "--dirty=m"],
fallback = "",
);
#[cfg(feature = "full-version")]
pub const MODIFIED: bool = matches!(GIT_VERSION.as_bytes().last(), Some(b'm'));
#[cfg(not(feature = "full-version"))]
pub const MODIFIED: bool = false;
#[cfg(feature = "full-version")]
pub const BUILD_COMMIT: &str = unsafe {
// Subslicing is not supported in const yet.
std::str::from_utf8_unchecked(std::slice::from_raw_parts(
GIT_VERSION.as_ptr(),
GIT_VERSION.len() - if MODIFIED { 1 } else { 0 },
))
};
#[cfg(not(feature = "full-version"))]
pub const BUILD_COMMIT: &str = "";

#[cfg(any(feature = "version-check", feature = "self-update"))]
pub const BUILD_BRANCH: BuildBranch = BuildBranch::from_version(SHORT_VERSION);

// #[allow(clippy::const_is_empty)]
#[cfg(feature = "full-version")]
pub const FULL_VERSION: &str = full_version!(SHORT_VERSION, BUILD_COMMIT, MODIFIED, cat);
#[cfg(not(feature = "full-version"))]
pub const FULL_VERSION: &str = SHORT_VERSION;
}

fn value<'a, T: 'a + ConfigType + ?Sized, F: FnOnce(T::Owned) -> Option<T::Owned>>(
Expand Down

0 comments on commit 1a916c1

Please sign in to comment.