Skip to content

Commit

Permalink
fix: fix usage as a library (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
CrabNejonas authored Sep 5, 2024
1 parent dbbdfa3 commit ab41e6d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 32 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-usage-as-library.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cargo-packager": patch
---

Fix using the crate as a library without `cli` feature flag
70 changes: 38 additions & 32 deletions crates/packager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,48 @@ name = "cargo-packager"
version = "0.10.2"
description = "Executable packager and bundler distributed as a CLI and library."
authors = [
"CrabNebula Ltd.",
"Tauri Programme within The Commons Conservancy",
"George Burton <[email protected]>"
"CrabNebula Ltd.",
"Tauri Programme within The Commons Conservancy",
"George Burton <[email protected]>",
]
keywords = [ "bundle", "package", "cargo" ]
keywords = ["bundle", "package", "cargo"]
categories = [
"command-line-interface",
"command-line-utilities",
"development-tools::cargo-plugins",
"development-tools::build-utils",
"os"
"command-line-interface",
"command-line-utilities",
"development-tools::cargo-plugins",
"development-tools::build-utils",
"os",
]
edition = { workspace = true }
license = { workspace = true }
repository = { workspace = true }

[[bin]]
name = "cargo-packager"
# path = "src/bins/cli.rs"
required-features = ["cli"]

[package.metadata.docs.rs]
rustdoc-args = [ "--cfg", "doc_cfg" ]
rustdoc-args = ["--cfg", "doc_cfg"]
default-target = "x86_64-unknown-linux-gnu"
targets = [
"x86_64-pc-windows-msvc",
"x86_64-unknown-linux-gnu",
"x86_64-apple-darwin"
"x86_64-pc-windows-msvc",
"x86_64-unknown-linux-gnu",
"x86_64-apple-darwin",
]

[lints.rust]
# cfg(doc_cfg) is used for docs.rs detection. see above
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(doc_cfg)'] }

[features]
default = [ "cli", "rustls-tls" ]
cli = [ "clap", "dep:tracing-subscriber" ]
schema = [ "schemars", "cargo-packager-utils/schema" ]
clap = [ "dep:clap", "cargo-packager-utils/clap" ]
native-tls = [ "ureq/native-tls" ]
native-tls-vendored = [ "native-tls", "native-tls/vendored" ]
rustls-tls = [ "ureq/tls" ]
default = ["cli", "rustls-tls"]
cli = ["clap", "dep:tracing-subscriber"]
schema = ["schemars", "cargo-packager-utils/schema"]
clap = ["dep:clap", "cargo-packager-utils/clap"]
native-tls = ["ureq/native-tls"]
native-tls-vendored = ["native-tls", "native-tls/vendored"]
rustls-tls = ["ureq/tls"]

[dependencies]
thiserror = { workspace = true }
Expand All @@ -49,16 +54,18 @@ dunce = { workspace = true }
dirs = { workspace = true }
semver = { workspace = true }
base64 = { workspace = true }
clap = { workspace = true, optional = true, features = [ "env" ] }
clap = { workspace = true, optional = true, features = ["env"] }
tracing = { workspace = true }
tracing-subscriber = { version = "0.3", optional = true, features = [ "env-filter" ] }
tracing-subscriber = { version = "0.3", optional = true, features = [
"env-filter",
] }
toml = "0.8"
cargo_metadata = "0.18"
ureq = { version = "2.10", default-features = false }
hex = "0.4"
sha1 = "0.10"
sha2 = "0.10"
zip = { version = "0.6", default-features = false, features = [ "deflate" ] }
zip = { version = "0.6", default-features = false, features = ["deflate"] }
handlebars = "5.1"
glob = "0.3"
relative-path = "1.9"
Expand All @@ -70,25 +77,24 @@ flate2 = "1.0"
strsim = "0.11"
schemars = { workspace = true, optional = true }
native-tls = { version = "0.2", optional = true }
cargo-packager-utils = { version = "0.1.1", path = "../utils", features = [ "serde" ] }
cargo-packager-utils = { version = "0.1.1", path = "../utils", features = [
"serde",
] }
icns = { package = "tauri-icns", version = "0.1" }
time = { workspace = true, features = [ "formatting" ] }
time = { workspace = true, features = ["formatting"] }
image = "0.25"
tempfile = "3"
plist = "1"

[target."cfg(target_os = \"windows\")".dependencies]
winreg = "0.52"
once_cell = "1.19"
uuid = { version = "1", features = [ "v4", "v5" ] }
uuid = { version = "1", features = ["v4", "v5"] }
regex = "1.10"

[target."cfg(target_os = \"windows\")".dependencies.windows-sys]
version = "0.52"
features = [
"Win32_System_SystemInformation",
"Win32_System_Diagnostics_Debug"
]
[target."cfg(target_os = \"windows\")".dependencies.windows-sys]
version = "0.52"
features = ["Win32_System_SystemInformation", "Win32_System_Diagnostics_Debug"]

[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"netbsd\", target_os = \"openbsd\"))".dependencies]
image = "0.25"
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions crates/packager/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use thiserror::Error;
pub enum Error {
/// Clap error.
#[error(transparent)]
#[cfg(feature = "cli")]
Clap(#[from] clap::error::Error),
/// Error while reading cargo metadata.
#[error("Failed to read cargo metadata: {0}")]
Expand Down
5 changes: 5 additions & 0 deletions crates/packager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub use sign::SigningConfig;
pub use package::{package, PackageOutput};
use util::PathExt;

#[cfg(feature = "cli")]
fn parse_log_level(verbose: u8) -> tracing::Level {
match verbose {
0 => tracing_subscriber::EnvFilter::builder()
Expand Down Expand Up @@ -144,17 +145,20 @@ pub fn init_tracing_subscriber(verbosity: u8) {
}
}

#[cfg(feature = "cli")]
enum TracingFormatter {
WithoutTime(
tracing_subscriber::fmt::format::Format<tracing_subscriber::fmt::format::Compact, ()>,
),
WithTime(tracing_subscriber::fmt::format::Format<tracing_subscriber::fmt::format::Compact>),
}

#[cfg(feature = "cli")]
struct ShellFieldVisitor {
message: String,
}

#[cfg(feature = "cli")]
impl tracing::field::Visit for ShellFieldVisitor {
fn record_str(&mut self, field: &tracing::field::Field, value: &str) {
if field.name() == "message" {
Expand All @@ -169,6 +173,7 @@ impl tracing::field::Visit for ShellFieldVisitor {
}
}

#[cfg(feature = "cli")]
impl<S, N> tracing_subscriber::fmt::FormatEvent<S, N> for TracingFormatter
where
S: tracing::Subscriber + for<'a> tracing_subscriber::registry::LookupSpan<'a>,
Expand Down

0 comments on commit ab41e6d

Please sign in to comment.