From be0abffe22558a8498f6c56de89216ea0ed4515c Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Tue, 20 Feb 2024 14:49:21 +0100 Subject: [PATCH] feat(proto): grpc server and client support --- proto-compiler/Cargo.toml | 12 ++++++++++++ proto-compiler/src/lib.rs | 7 +++++++ proto/Cargo.toml | 12 ++++++++++++ proto/src/lib.rs | 2 +- proto/tests/grpc.rs | 8 ++++++++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 proto/tests/grpc.rs diff --git a/proto-compiler/Cargo.toml b/proto-compiler/Cargo.toml index 9980ade6..efc4ab91 100644 --- a/proto-compiler/Cargo.toml +++ b/proto-compiler/Cargo.toml @@ -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"] diff --git a/proto-compiler/src/lib.rs b/proto-compiler/src/lib.rs index 0dcb7215..9581360b 100644 --- a/proto-compiler/src/lib.rs +++ b/proto-compiler/src/lib.rs @@ -97,6 +97,13 @@ pub fn proto_compile() { let tenderdash_ver = tenderdash_version(tenderdash_dir); println!("[info] => Creating structs."); + + #[cfg(feature = "grpc")] + tonic_build::configure() + .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."); diff --git a/proto/Cargo.toml b/proto/Cargo.toml index 430b4646..b1f26f80 100644 --- a/proto/Cargo.toml +++ b/proto/Cargo.toml @@ -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 = [ @@ -39,6 +50,7 @@ derive_more = { version = "0.99.17" } [dev-dependencies] serde_json = { version = "1.0", default-features = false, features = ["alloc"] } +tenderdash-abci = { path = "../abci" } [build-dependencies] tenderdash-proto-compiler = { path = "../proto-compiler" } diff --git a/proto/src/lib.rs b/proto/src/lib.rs index 667be8e2..5c2c8876 100644 --- a/proto/src/lib.rs +++ b/proto/src/lib.rs @@ -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)] diff --git a/proto/tests/grpc.rs b/proto/tests/grpc.rs new file mode 100644 index 00000000..d037d13c --- /dev/null +++ b/proto/tests/grpc.rs @@ -0,0 +1,8 @@ +use tenderdash_abci::common::docker::TenderdashDocker; + +#[test] +fn test_docker() { + let container_name = "tenderdash_test"; + let app_address = "tcp://; + +} \ No newline at end of file