Skip to content

Commit

Permalink
make sql and its dependencies optional (#1089)
Browse files Browse the repository at this point in the history
Making SQL optional would be great and does not brings unwanted dependencies when SQL is not used. Here is an example: #1086
  • Loading branch information
vedhavyas authored Jun 26, 2023
1 parent 6102a1a commit 308409d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 23 additions & 10 deletions client/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,45 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
async-trait = "0.1"
ethereum = { workspace = true, features = ["with-codec"] }
futures = "0.3.25"
ethereum = { workspace = true, features = ["with-codec"], optional = true }
futures = { version = "0.3.25", optional = true }
kvdb-rocksdb = { workspace = true, optional = true }
log = "0.4.17"
parity-db = { workspace = true, optional = true }
parking_lot = "0.12.1"
scale-codec = { package = "parity-scale-codec", workspace = true }
smallvec = { version = "1.10", optional = true }
sqlx = { workspace = true, features = ["runtime-tokio-native-tls", "sqlite"] }
tokio = { version = "1.19", features = ["macros", "sync"] }
sqlx = { workspace = true, features = ["runtime-tokio-native-tls", "sqlite"], optional = true }
tokio = { version = "1.19", features = ["macros", "sync"], optional = true }
# Substrate
sc-client-api = { workspace = true }
sc-client-api = { workspace = true, optional = true }
sc-client-db = { workspace = true }
sp-api = { workspace = true }
sp-api = { workspace = true, optional = true }
sp-blockchain = { workspace = true }
sp-core = { workspace = true }
sp-database = { workspace = true }
sp-runtime = { workspace = true }
sp-storage = { workspace = true }
sp-storage = { workspace = true, optional = true }
# Frontier
fc-storage = { workspace = true }
fp-consensus = { workspace = true, features = ["default"] }
fp-rpc = { workspace = true, features = ["default"] }
fc-storage = { workspace = true, optional = true }
fp-consensus = { workspace = true, features = ["default"], optional = true }
fp-rpc = { workspace = true, features = ["default"], optional = true }
fp-storage = { workspace = true, features = ["default"] }

[features]
default = ["parity-db"]
sql = [
"ethereum",
"futures",
"sqlx",
"tokio",
"sc-client-api",
"sp-api",
"sp-storage",
"fc-storage",
"fp-consensus",
"fp-rpc",
]
parity-db = ["dep:parity-db"]
rocksdb = [
"kvdb-rocksdb",
Expand All @@ -47,6 +59,7 @@ rocksdb = [
]

[dev-dependencies]
futures = { version = "0.3.25" }
maplit = "1.0.2"
tempfile = "3.3.0"
# Substrate
Expand Down
5 changes: 4 additions & 1 deletion client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ use sp_core::H256;
use sp_runtime::traits::Block as BlockT;

pub mod kv;
pub mod sql;
use kv::{columns, static_keys};

#[cfg(feature = "sql")]
pub mod sql;

#[derive(Clone)]
pub enum Backend<Block: BlockT> {
KeyValue(kv::Backend<Block>),
#[cfg(feature = "sql")]
Sql(sql::Backend<Block>),
}

Expand Down
11 changes: 9 additions & 2 deletions client/mapping-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,28 @@ futures = "0.3.25"
futures-timer = "3.0.2"
log = "0.4.17"
parking_lot = "0.12.1"
tokio = { version = "1.19", features = ["macros", "sync"] }
tokio = { version = "1.19", features = ["macros", "sync"], optional = true }
# Substrate
sc-client-api = { workspace = true }
sc-utils = { workspace = true }
sp-api = { workspace = true }
sp-blockchain = { workspace = true }
sp-consensus = { workspace = true, features = ["default"] }
sp-core = { workspace = true }
sp-core = { workspace = true, optional = true }
sp-runtime = { workspace = true }
# Frontier
fc-db = { workspace = true }
fc-storage = { workspace = true }
fp-consensus = { workspace = true, features = ["default"] }
fp-rpc = { workspace = true, features = ["default"] }

[features]
sql = [
"tokio",
"sp-core",
"fc-db/sql",
]

[dev-dependencies]
ethereum = { workspace = true }
ethereum-types = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions client/mapping-sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#![allow(clippy::too_many_arguments)]

pub mod kv;
#[cfg(feature = "sql")]
pub mod sql;

use sp_api::BlockT;
Expand Down
4 changes: 2 additions & 2 deletions template/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ pallet-transaction-payment = { workspace = true }
# Frontier
fc-cli = { workspace = true }
fc-consensus = { workspace = true }
fc-db = { workspace = true }
fc-mapping-sync = { workspace = true }
fc-db = { workspace = true, features = ["default", "sql"] }
fc-mapping-sync = { workspace = true, features = ["sql"] }
fc-rpc = { workspace = true }
fc-rpc-core = { workspace = true }
fc-storage = { workspace = true }
Expand Down

0 comments on commit 308409d

Please sign in to comment.