From 82cc92395e9540dc4d45f7d3282d8831b15027f9 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Thu, 9 Jan 2025 12:46:14 +0100 Subject: [PATCH] chore: features improvements --- abci/Cargo.toml | 33 +++++++++++-------- proto/Cargo.toml | 15 ++++++--- proto/src/error.rs | 4 +-- proto/src/lib.rs | 6 ++-- proto/src/prelude.rs | 2 +- proto/src/protobuf.rs | 4 +-- proto/src/serializers/from_str.rs | 4 +-- .../src/serializers/part_set_header_total.rs | 4 +-- proto/src/serializers/time_duration.rs | 4 +-- proto/src/serializers/timestamp.rs | 4 +-- proto/tests/unit.rs | 2 +- 11 files changed, 48 insertions(+), 34 deletions(-) diff --git a/abci/Cargo.toml b/abci/Cargo.toml index 2325c91..7eaafeb 100644 --- a/abci/Cargo.toml +++ b/abci/Cargo.toml @@ -16,31 +16,38 @@ rust-version.workspace = true version.workspace = true [features] -default = [ - "server", - "docker-tests", - "crypto", - "tcp", - "unix", - "grpc", - "tracing-span", -] +# By default, include the server feature together with both tcp and unix transports. +default = ["server", "docker-tests", "crypto", "tcp", "unix", "tracing-span"] # docker-tests includes integration tests that require docker to be available docker-tests = ["server"] +# Enable server support; this is most likely what you want (plus `tcp` and/or `unix`) server = [ "tracing-subscriber/fmt", + "tenderdash-proto/server", "dep:tokio", "dep:tokio-util", "dep:futures", - "grpc", + "std", ] -# std is deprecated, use "grpc" instead -std = ["grpc"] -grpc = ["tenderdash-proto/server"] +# DEPRECATED; use `server` instead +grpc = ["server"] + +# Disable no_std support +std = ["tenderdash-proto/std"] + +# Include crypto features, like signature verification crypto = ["dep:lhash"] + +# Include server TCP support tcp = ["server"] + +# Include server unix socket support unix = ["server"] + +# Include `tracing` crate spans tracing-span = ["dep:uuid"] + +# Include `serde` support serde = ["tenderdash-proto/serde", "dep:serde_json"] [[example]] diff --git a/proto/Cargo.toml b/proto/Cargo.toml index 4ebc580..7ef35e5 100644 --- a/proto/Cargo.toml +++ b/proto/Cargo.toml @@ -36,14 +36,21 @@ all-features = true # issues related to outdated generated files. default = ["server"] -# Enable standard library support; DEPRECATED - use `client` and/or `server` instead +# Enable standard library support; required by `client` and `server` std = ["client"] -# Enable gRPC support using tonic; internal, consider using `server` or `client` instead -grpc = ["client", "dep:tonic", "tonic/codegen", "tonic/prost"] +# Enable gRPC support using tonic; DEPRECATED, consider using `server` or `client` instead +grpc = ["client"] # Build gRPC server using tonic. Includes `client` feature. server = ["client", "tonic/transport"] # Build minimal gRPC client using tonic, without transport -client = ["tenderdash-proto-compiler/grpc", "prost/std", "grpc"] +client = [ + "tenderdash-proto-compiler/grpc", + "prost/std", + "dep:tonic", + "tonic/codegen", + "tonic/prost", + "std", +] serde = ["dep:serde", "bytes/serde"] diff --git a/proto/src/error.rs b/proto/src/error.rs index ea92b87..9ef24ba 100644 --- a/proto/src/error.rs +++ b/proto/src/error.rs @@ -1,8 +1,8 @@ //! This module defines the various errors that be raised during Protobuf //! conversions. -#[cfg(not(feature = "grpc"))] +#[cfg(not(feature = "std"))] use core::{convert::TryFrom, fmt::Display, num::TryFromIntError}; -#[cfg(feature = "grpc")] +#[cfg(feature = "std")] use std::{fmt::Display, num::TryFromIntError}; use flex_error::{define_error, DisplayOnly}; diff --git a/proto/src/lib.rs b/proto/src/lib.rs index b72b89f..0b35a5d 100644 --- a/proto/src/lib.rs +++ b/proto/src/lib.rs @@ -1,6 +1,6 @@ //! tenderdash-proto library gives the developer access to the Tenderdash //! proto-defined structs. -#![cfg_attr(not(feature = "grpc"), no_std)] +#![cfg_attr(not(feature = "std"), no_std)] #![deny(warnings, trivial_casts, trivial_numeric_casts, unused_import_braces)] #![allow(clippy::large_enum_variant)] #![allow(clippy::doc_lazy_continuation)] @@ -21,12 +21,12 @@ pub mod google { mod error; -#[cfg(not(feature = "grpc"))] +#[cfg(not(feature = "std"))] use core::{ convert::{TryFrom, TryInto}, fmt::Display, }; -#[cfg(feature = "grpc")] +#[cfg(feature = "std")] use std::fmt::Display; use bytes::{Buf, BufMut}; diff --git a/proto/src/prelude.rs b/proto/src/prelude.rs index 7fa30e1..24c0d3d 100644 --- a/proto/src/prelude.rs +++ b/proto/src/prelude.rs @@ -11,7 +11,7 @@ pub use alloc::{ }; pub use core::prelude::v1::*; -#[cfg(feature = "grpc")] +#[cfg(feature = "std")] pub use tonic; pub use crate::time::{FromMillis, ToMillis}; diff --git a/proto/src/protobuf.rs b/proto/src/protobuf.rs index c97a113..6d441d7 100644 --- a/proto/src/protobuf.rs +++ b/proto/src/protobuf.rs @@ -3,9 +3,9 @@ // Prost does not seem to have a way yet to remove documentations defined in // protobuf files. These structs are defined in gogoproto v1.3.1 at https://github.com/gogo/protobuf/tree/v1.3.1/protobuf/google/protobuf -#[cfg(not(feature = "grpc"))] +#[cfg(not(feature = "std"))] use core::fmt; -#[cfg(feature = "grpc")] +#[cfg(feature = "std")] use std::fmt; /// A Timestamp represents a point in time independent of any time zone or local diff --git a/proto/src/serializers/from_str.rs b/proto/src/serializers/from_str.rs index c1536ab..0544cc7 100644 --- a/proto/src/serializers/from_str.rs +++ b/proto/src/serializers/from_str.rs @@ -1,9 +1,9 @@ //! Serialize and deserialize any `T` that implements [[core::str::FromStr]] //! and [[core::fmt::Display]] from or into string. Note this can be used for //! all primitive data types. -#[cfg(not(feature = "grpc"))] +#[cfg(not(feature = "std"))] use core::{fmt::Display, str::FromStr}; -#[cfg(feature = "grpc")] +#[cfg(feature = "std")] use std::{fmt::Display, str::FromStr}; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; diff --git a/proto/src/serializers/part_set_header_total.rs b/proto/src/serializers/part_set_header_total.rs index f55b977..17c9222 100644 --- a/proto/src/serializers/part_set_header_total.rs +++ b/proto/src/serializers/part_set_header_total.rs @@ -6,9 +6,9 @@ //! Tendermint Core v0.34.0. This deserializer allows backwards-compatibility by //! deserializing both ways. See also: -#[cfg(not(feature = "grpc"))] +#[cfg(not(feature = "std"))] use core::{convert::TryFrom, fmt::Formatter}; -#[cfg(feature = "grpc")] +#[cfg(feature = "std")] use std::fmt::Formatter; use serde::{ diff --git a/proto/src/serializers/time_duration.rs b/proto/src/serializers/time_duration.rs index 0bdc33a..f30e943 100644 --- a/proto/src/serializers/time_duration.rs +++ b/proto/src/serializers/time_duration.rs @@ -1,7 +1,7 @@ //! Serialize/deserialize core::time::Duration type from and into string: -#[cfg(not(feature = "grpc"))] +#[cfg(not(feature = "std"))] use core::time::Duration; -#[cfg(feature = "grpc")] +#[cfg(feature = "std")] use std::time::Duration; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; diff --git a/proto/src/serializers/timestamp.rs b/proto/src/serializers/timestamp.rs index aa4af9c..5068736 100644 --- a/proto/src/serializers/timestamp.rs +++ b/proto/src/serializers/timestamp.rs @@ -1,7 +1,7 @@ //! Serialize/deserialize Timestamp type from and into string: -#[cfg(not(feature = "grpc"))] +#[cfg(not(feature = "std"))] use core::fmt::{self, Debug}; -#[cfg(feature = "grpc")] +#[cfg(feature = "std")] use std::fmt::{self, Debug}; use serde::{de::Error as _, ser::Error, Deserialize, Deserializer, Serialize, Serializer}; diff --git a/proto/tests/unit.rs b/proto/tests/unit.rs index ba59705..295297e 100644 --- a/proto/tests/unit.rs +++ b/proto/tests/unit.rs @@ -1,4 +1,4 @@ -#[cfg(not(feature = "grpc"))] +#[cfg(not(feature = "std"))] use core::convert::TryFrom; use tenderdash_proto::{