diff --git a/proto-compiler/Cargo.toml b/proto-compiler/Cargo.toml index 9980ade..efc4ab9 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 0dcb721..1aa26e8 100644 --- a/proto-compiler/src/lib.rs +++ b/proto-compiler/src/lib.rs @@ -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."); diff --git a/proto/Cargo.toml b/proto/Cargo.toml index 430b464..06a480d 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 = [ diff --git a/proto/src/lib.rs b/proto/src/lib.rs index 667be8e..5c2c887 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)]