From a03e2301715665ebbaa349eb7cdcbf1aa879347e Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Sat, 30 Dec 2023 19:47:58 +0100 Subject: [PATCH] feat(cli): Allow building without self-update feature --- Cargo.toml | 7 ++++--- src/commands.rs | 1 + src/commands/self_update.rs | 13 ++++++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cc8a8a6e8..9e5779f4a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,9 +31,10 @@ description = { workspace = true } members = ["crates/rustic_testing", "xtask"] [features] -default = [] +default = ["self-update"] mimalloc = ["dep:mimalloc"] jemallocator = ["dep:jemallocator-global"] +self-update = ["dep:self_update", "dep:semver"] [[bin]] name = "rustic" @@ -67,8 +68,8 @@ serde_with = { workspace = true } # other dependencies chrono = { workspace = true } -self_update = { workspace = true } -semver = { workspace = true } +self_update = { workspace = true, optional = true } +semver = { workspace = true, optional = true } # commands clap = { workspace = true } diff --git a/src/commands.rs b/src/commands.rs index 50460378d..6ff90ec9d 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -108,6 +108,7 @@ enum RusticCmd { ShowConfig(ShowConfigCmd), /// Update to the latest rustic release + #[cfg_attr(not(feature = "self-update"), clap(hide = true))] SelfUpdate(SelfUpdateCmd), /// Remove unused data or repack repository pack files diff --git a/src/commands/self_update.rs b/src/commands/self_update.rs index dff8fb304..a92ed7e02 100644 --- a/src/commands/self_update.rs +++ b/src/commands/self_update.rs @@ -5,8 +5,6 @@ use crate::{Application, RUSTIC_APP}; use abscissa_core::{status_err, Command, Runnable, Shutdown}; use anyhow::Result; -use self_update::cargo_crate_version; -use semver::Version; /// `self-update` subcommand #[derive(clap::Parser, Command, Debug)] @@ -26,8 +24,11 @@ impl Runnable for SelfUpdateCmd { } impl SelfUpdateCmd { + #[cfg(feature = "self-update")] fn inner_run(&self) -> Result<()> { - let current_version = Version::parse(cargo_crate_version!())?; + use semver::Version; + + let current_version = Version::parse(self_update::cargo_crate_version!())?; let release = self_update::backends::github::Update::configure() .repo_owner("rustic-rs") @@ -62,4 +63,10 @@ impl SelfUpdateCmd { Ok(()) } + #[cfg(not(feature = "self-update"))] + fn inner_run(&self) -> Result<()> { + anyhow::bail!( + "This rustic was built without the \"self-updade\" feature. You should probably use your system package manager to update it." + ); + } }