Skip to content
This repository has been archived by the owner on Aug 4, 2024. It is now read-only.

Commit

Permalink
feat: make rpc functionality optional
Browse files Browse the repository at this point in the history
  • Loading branch information
KKould committed Dec 3, 2023
1 parent 9d09561 commit 0878f1c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ default-run = "server"
[[bin]]
name = "cli"
path = "src/bin/cli.rs"
required-features = ["net"]

[[bin]]
name = "server"
path = "src/bin/server.rs"
required-features = ["net"]

[[bench]]
name = "server_bench"
Expand All @@ -30,6 +32,7 @@ debug = true
[features]
sled = ["dep:sled"]
rocksdb = ["dep:rocksdb"]
net = ["dep:tonic", "dep:prost", "dep:tonic-build"]

[dependencies]
thiserror = "1.0.24"
Expand Down Expand Up @@ -59,8 +62,8 @@ crc32fast = "1.3.2"
skiplist = "0.5.1"
fslock = "0.2.1"
# grpc
tonic = "0.10.2"
prost = "0.12"
tonic = { version = "0.10.2", optional = true }
prost = { version = "0.12", optional = true }
# 其他数据库内核
sled = { version = "0.34.7", optional = true }
rocksdb = { version = "0.21.0", optional = true }
Expand All @@ -76,4 +79,4 @@ tempfile = "3.0.7"
rand = "0.8.5"

[build-dependencies]
tonic-build = "0.10.2"
tonic-build = {version = "0.10.2", optional = true}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
**组件原理Wiki** : https://github.com/KKould/KipDB/wiki

## 快速上手 🤞
确保 [Protocol Buffer Compiler](https://grpc.io/docs/protoc-installation/) 已安装。
Tips: 使用RPC时请确保 [Protocol Buffer Compiler](https://grpc.io/docs/protoc-installation/) 已安装。

#### 组件引入
``` toml
Expand Down
9 changes: 6 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::configure()
.protoc_arg("--experimental_allow_proto3_optional")
.compile(&["src/proto/kipdb.proto"], &["src/proto"])?;
#[cfg(feature = "net")]
{
tonic_build::configure()
.protoc_arg("--experimental_allow_proto3_optional")
.compile(&["src/proto/kipdb.proto"], &["src/proto"])?;
}
Ok(())
}
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ pub enum ConnectionError {
#[error("server flush error")]
FlushError,

#[cfg(feature = "net")]
#[error("Failed to connect to server, {0}")]
TonicTransportErr(#[from] tonic::transport::Error),

#[cfg(feature = "net")]
#[error("Failed to call server, {0}")]
TonicFailureStatus(#[from] tonic::Status),

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub mod config;
pub mod error;
pub mod kernel;
pub mod proto;

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

pub use error::KernelError;
Expand Down
1 change: 1 addition & 0 deletions src/proto/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#[cfg(feature = "net")]
tonic::include_proto!("kipdb");

0 comments on commit 0878f1c

Please sign in to comment.