Skip to content

Commit 6a065de

Browse files
authored
Make jemalloc, clap and pyo3 optional dependencies (#116)
1 parent f4d96c7 commit 6a065de

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

Cargo.toml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ name = "synapse_compress_state"
88
version = "0.1.0"
99
edition = "2018"
1010

11+
[[bin]]
12+
name = "synapse_compress_state"
13+
required-features = ["clap"]
14+
1115
[dependencies]
1216
indicatif = "0.17.0"
1317
openssl = "0.10.48"
@@ -18,7 +22,6 @@ rayon = "1.3.0"
1822
string_cache = "0.8.0"
1923
env_logger = "0.9.0"
2024
log = "0.4.14"
21-
pyo3-log = "0.7.0"
2225
log-panics = "2.0.0"
2326

2427
[dependencies.state-map]
@@ -31,16 +34,23 @@ crate-type = ["cdylib", "rlib"]
3134
[dependencies.clap]
3235
version = "4.0.15"
3336
features = ["cargo"]
37+
optional = true
3438

3539
[dependencies.pyo3]
3640
version = "0.17.1"
3741
features = ["extension-module"]
42+
optional = true
43+
44+
[dependencies.pyo3-log]
45+
version = "0.7.0"
46+
optional = true
3847

3948
[dependencies.tikv-jemallocator]
4049
version = "0.5.0"
4150
optional = true
4251

4352
[features]
44-
default = ["jemalloc"]
53+
default = ["clap", "jemalloc", "pyo3"]
4554
jemalloc = ["tikv-jemallocator"]
4655
no-progress-bars = []
56+
pyo3 = ["dep:pyo3", "dep:pyo3-log"]

src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
// of arguments - this hopefully doesn't make the code unclear
2121
// #[allow(clippy::too_many_arguments)] is therefore used around some functions
2222

23-
use log::{info, warn, LevelFilter};
23+
use log::{info, warn};
24+
#[cfg(feature = "pyo3")]
2425
use pyo3::{exceptions, prelude::*};
2526

27+
#[cfg(feature = "clap")]
2628
use clap::{crate_authors, crate_description, crate_name, crate_version, Arg, Command};
2729
use indicatif::{ProgressBar, ProgressStyle};
2830
use rayon::prelude::*;
@@ -117,6 +119,7 @@ pub struct Config {
117119
verify: bool,
118120
}
119121

122+
#[cfg(feature = "clap")]
120123
impl Config {
121124
/// Build up config from command line arguments
122125
pub fn parse_arguments() -> Config {
@@ -747,6 +750,7 @@ impl Config {
747750
/// Default arguments are equivalent to using the command line tool
748751
/// No default's are provided for db_url or room_id since these arguments
749752
/// are compulsory (so that new() act's like parse_arguments())
753+
#[cfg(feature = "pyo3")]
750754
#[allow(clippy::too_many_arguments)]
751755
#[pyfunction(
752756
// db_url has no default
@@ -802,14 +806,15 @@ fn run_compression(
802806
}
803807

804808
/// Python module - "import synapse_compress_state" to use
809+
#[cfg(feature = "pyo3")]
805810
#[pymodule]
806811
fn synapse_compress_state(_py: Python, m: &PyModule) -> PyResult<()> {
807812
let _ = pyo3_log::Logger::default()
808813
// don't send out anything lower than a warning from other crates
809-
.filter(LevelFilter::Warn)
814+
.filter(log::LevelFilter::Warn)
810815
// don't log warnings from synapse_compress_state, the synapse_auto_compressor handles these
811816
// situations and provides better log messages
812-
.filter_target("synapse_compress_state".to_owned(), LevelFilter::Debug)
817+
.filter_target("synapse_compress_state".to_owned(), log::LevelFilter::Debug)
813818
.install();
814819
// ensure any panics produce error messages in the log
815820
log_panics::init();

synapse_auto_compressor/Cargo.toml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ authors = ["William Ashton"]
44
version = "0.1.3"
55
edition = "2018"
66

7+
[[bin]]
8+
name = "synapse_auto_compressor"
9+
required-features = ["clap"]
10+
711
[package.metadata.maturin]
812
requires-python = ">=3.7"
913
project-url = {Source = "https://github.com/matrix-org/rust-synapse-compress-state"}
@@ -18,12 +22,11 @@ postgres = "0.19.0"
1822
postgres-openssl = "0.5.0"
1923
rand = "0.8.0"
2024
serial_test = "0.9.0"
21-
synapse_compress_state = { path = "../", features = ["no-progress-bars"] }
25+
synapse_compress_state = { path = "../", features = ["no-progress-bars"], default-features = false }
2226
env_logger = "0.9.0"
2327
log = "0.4.14"
2428
log-panics = "2.0.0"
2529
anyhow = "1.0.42"
26-
pyo3-log = "0.7.0"
2730

2831
# Needed for pyo3 support
2932
[lib]
@@ -32,15 +35,22 @@ crate-type = ["cdylib", "rlib"]
3235
[dependencies.clap]
3336
version = "4.0.15"
3437
features = ["cargo"]
38+
optional = true
3539

3640
[dependencies.pyo3]
3741
version = "0.17.1"
3842
features = ["extension-module"]
43+
optional = true
44+
45+
[dependencies.pyo3-log]
46+
version = "0.7.0"
47+
optional = true
3948

4049
[dependencies.tikv-jemallocator]
4150
version = "0.5.0"
4251
optional = true
4352

4453
[features]
45-
default = ["jemalloc"]
46-
jemalloc = ["tikv-jemallocator"]
54+
default = ["clap", "jemalloc", "pyo3"]
55+
jemalloc = ["tikv-jemallocator", "synapse_compress_state/jemalloc"]
56+
pyo3 = ["dep:pyo3", "dep:pyo3-log", "synapse_compress_state/pyo3"]

synapse_auto_compressor/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
//! on space reductions
88
99
use anyhow::Result;
10+
#[cfg(feature = "pyo3")]
1011
use log::{error, LevelFilter};
12+
#[cfg(feature = "pyo3")]
1113
use pyo3::{
1214
exceptions::PyRuntimeError, prelude::pymodule, types::PyModule, PyErr, PyResult, Python,
1315
};
@@ -56,6 +58,7 @@ impl FromStr for LevelInfo {
5658
}
5759

5860
// PyO3 INTERFACE STARTS HERE
61+
#[cfg(feature = "pyo3")]
5962
#[pymodule]
6063
fn synapse_auto_compressor(_py: Python, m: &PyModule) -> PyResult<()> {
6164
let _ = pyo3_log::Logger::default()

0 commit comments

Comments
 (0)