Skip to content

Commit f286e06

Browse files
committed
feat: make rocksdb optional when using sqlite feature
- Make rocksdb dependency optional in both lib and bin crates - Add feature flags to properly control backend selection - Update conditional compilation to check for rocksdb feature - Add proper error variants for each backend (rocksdb, sqlite, indexdb) - Disable default features for ckb-light-client-lib dependency This allows building with --features sqlite --no-default-features to completely exclude rocksdb from the dependency tree.
1 parent c7bd063 commit f286e06

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

light-client-bin/Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ckb-types = "1"
1919
ckb-traits = "1"
2020
ckb-systemtime = "1"
2121

22-
ckb-light-client-lib = { path = "../light-client-lib" }
22+
ckb-light-client-lib = { path = "../light-client-lib", default-features = false }
2323
clap = { version = "4", features = ["cargo"] }
2424
log = "0.4"
2525
ctrlc = { version = "3.2.1", features = ["termination"] }
@@ -29,7 +29,7 @@ jsonrpc-http-server = "18.0"
2929
jsonrpc-server-utils = "18.0"
3030
rocksdb = { package = "ckb-rocksdb", version = "=0.21.1", features = [
3131
"snappy",
32-
], default-features = false }
32+
], default-features = false, optional = true }
3333
env_logger = "0.11"
3434
anyhow = "1.0.56"
3535

@@ -46,10 +46,11 @@ serde_json = "1.0"
4646
tempfile = "3.0"
4747

4848
[features]
49-
default = []
50-
portable = ["rocksdb/portable"]
51-
march-native = ["rocksdb/march-native"]
49+
default = ["rocksdb", "ckb-light-client-lib/rocksdb"]
50+
portable = ["rocksdb", "rocksdb/portable", "ckb-light-client-lib/rocksdb"]
51+
march-native = ["rocksdb", "rocksdb/march-native", "ckb-light-client-lib/rocksdb"]
5252
sqlite = ["ckb-light-client-lib/sqlite"]
53+
rocksdb = ["dep:rocksdb"]
5354

5455
# [profile.release]
5556
# overflow-checks = true

light-client-lib/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ repository = "https://github.com/nervosnetwork/ckb-light-client"
1212
crate-type = ["cdylib", "rlib"]
1313

1414
[features]
15-
default = []
15+
default = ["rocksdb"]
1616
sqlite = ["rusqlite"]
17+
rocksdb = ["dep:rocksdb"]
1718

1819
[dependencies]
1920
ckb-app-config = "1"
@@ -56,7 +57,7 @@ bincode = "1.3"
5657
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
5758
rocksdb = { package = "ckb-rocksdb", version = "=0.21.1", features = [
5859
"snappy",
59-
], default-features = false }
60+
], default-features = false, optional = true }
6061
rusqlite = { version = "0.32", optional = true, features = ["bundled"] }
6162

6263
[target.'cfg(target_arch = "wasm32")'.dependencies]

light-client-lib/src/error.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ pub enum Error {
1111
#[error("runtime error: {0}")]
1212
Runtime(String),
1313

14-
#[cfg(not(target_arch = "wasm32"))]
14+
#[cfg(all(not(target_arch = "wasm32"), feature = "rocksdb"))]
1515
#[error("db error: {0}")]
1616
Db(#[from] rocksdb::Error),
1717

18+
#[cfg(all(not(target_arch = "wasm32"), feature = "sqlite"))]
19+
#[error("db error: {0}")]
20+
Sqlite(#[from] rusqlite::Error),
21+
1822
#[cfg(target_arch = "wasm32")]
1923
#[error("db error: {0}")]
2024
Indexdb(String),

light-client-lib/src/storage/db/iterator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Unified iterator types for different storage backends (RocksDB, IndexedDB, SQLite)
22
3-
#[cfg(not(target_arch = "wasm32"))]
3+
#[cfg(all(not(target_arch = "wasm32"), feature = "rocksdb"))]
44
use rocksdb::Direction;
55

66
// On wasm32, re-export IteratorDirection and KVPair from db-common to avoid duplication
@@ -15,7 +15,7 @@ pub enum IteratorDirection {
1515
Reverse,
1616
}
1717

18-
#[cfg(not(target_arch = "wasm32"))]
18+
#[cfg(all(not(target_arch = "wasm32"), feature = "rocksdb"))]
1919
impl From<IteratorDirection> for Direction {
2020
fn from(dir: IteratorDirection) -> Self {
2121
match dir {

0 commit comments

Comments
 (0)