Skip to content

Commit

Permalink
Make the flate2 dependency optional
Browse files Browse the repository at this point in the history
  • Loading branch information
eminence committed Nov 20, 2021
1 parent f6f227c commit de0a845
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ license = "MIT OR Apache-2.0"
edition = "2018"

[features]
default = ["chrono"]
default = ["chrono", "flate2"]

[dependencies]
libc = "0.2"
Expand All @@ -21,7 +21,7 @@ lazy_static = "1"
chrono = {version = "0.4", optional = true }
byteorder = {version="1", features=["i128"]}
hex = "0.4"
flate2 = "1"
flate2 = { version = "1", optional = true }
backtrace = { version = "0.3", optional = true }

[dev-dependencies]
Expand Down
23 changes: 17 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,13 +671,24 @@ pub enum ConfigSetting {
///
/// If CONFIG_KCONFIG_PROC is available, the config is read from `/proc/config.gz`.
/// Else look in `/boot/config-$(uname -r)` or `/boot/config` (in that order).
///
/// # Notes
/// Reading the compress `/proc/config.gz` is only supported if the `flate2` feature is enabled
/// (which it is by default).
#[cfg_attr(feature = "flate2", doc = "The flate2 feature is currently enabled")]
#[cfg_attr(not(feature = "flate2"), doc = "The flate2 feature is NOT currently enabled")]
pub fn kernel_config() -> ProcResult<HashMap<String, ConfigSetting>> {
use flate2::read::GzDecoder;

let reader: Box<dyn BufRead> = if Path::new(PROC_CONFIG_GZ).exists() {
let file = FileWrapper::open(PROC_CONFIG_GZ)?;
let decoder = GzDecoder::new(file);
Box::new(BufReader::new(decoder))
let reader: Box<dyn BufRead> = if Path::new(PROC_CONFIG_GZ).exists() && cfg!(feature = "flate2") {
#[cfg(feature = "flate2")]
{
let file = FileWrapper::open(PROC_CONFIG_GZ)?;
let decoder = flate2::read::GzDecoder::new(file);
Box::new(BufReader::new(decoder))
}
#[cfg(not(feature = "flate2"))]
{
unreachable!("flate2 feature not enabled")
}
} else {
let mut kernel: libc::utsname = unsafe { mem::zeroed() };

Expand Down

0 comments on commit de0a845

Please # to comment.