Skip to content

Commit

Permalink
feat(proto): grpc server and client support
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek committed Feb 20, 2024
1 parent 8b5afe6 commit 1389e71
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
12 changes: 12 additions & 0 deletions proto-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,15 @@ regex = { "version" = "1.7.1" }
ureq = { "version" = "2.6.2" }
zip = { version = "0.6.4", default-features = false, features = ["deflate"] }
fs_extra = { version = "1.3.0" }
tonic-build = { version = "0.11.0", optional = true }


[features]
default = []
# Enable gRPC support; needed by server and client features.
# Conflicts with no_std
grpc = ["dep:tonic-build"]
# Build the gRPC server. Requires tenderdash-proto/std feature.
server = ["grpc"]
# Build the gRPC client. Requires tenderdash-proto/std feature.
client = ["grpc"]
8 changes: 8 additions & 0 deletions proto-compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ pub fn proto_compile() {
let tenderdash_ver = tenderdash_version(tenderdash_dir);

println!("[info] => Creating structs.");

#[cfg(feature = "grpc")]
tonic_build::configure()
.generate_default_stubs(true)
.compile_with_config(pb, &protos, &proto_includes_paths)
.unwrap();

#[cfg(not(feature = "grpc"))]
pb.compile_protos(&protos, &proto_includes_paths).unwrap();

println!("[info] => Removing old structs and copying new structs.");
Expand Down
11 changes: 11 additions & 0 deletions proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,21 @@ description = """
[package.metadata.docs.rs]
all-features = true

[features]
default = ["grpc-server"]

# Enable standard library support
std = ["prost/std", "prost-types/std"]
# Build gRPC server
grpc-server = ["tenderdash-proto-compiler/server", "std"]
grpc-client = ["tenderdash-proto-compiler/client", "std"]

[dependencies]
prost = { version = "0.12", default-features = false, features = [
"prost-derive",
] }
prost-types = { version = "0.12", default-features = false }
tonic = { version = "0.11" }
bytes = { version = "1.0", default-features = false, features = ["serde"] }
serde = { version = "1.0", default-features = false, features = ["derive"] }
subtle-encoding = { version = "0.5", default-features = false, features = [
Expand Down
2 changes: 1 addition & 1 deletion proto/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! tenderdash-proto library gives the developer access to the Tenderdash
//! proto-defined structs.
#![no_std]
#![cfg_attr(not(feature = "std"), no_std)]
#![deny(warnings, trivial_casts, trivial_numeric_casts, unused_import_braces)]
#![allow(clippy::large_enum_variant)]
#![forbid(unsafe_code)]
Expand Down

0 comments on commit 1389e71

Please sign in to comment.