diff --git a/abci/Cargo.toml b/abci/Cargo.toml index 1d68b11..6cfef7d 100644 --- a/abci/Cargo.toml +++ b/abci/Cargo.toml @@ -21,7 +21,6 @@ default = [ "unix", "grpc", "tracing-span", - "std", ] # docker-tests includes integration tests that require docker to be available docker-tests = ["server"] @@ -31,8 +30,9 @@ server = [ "dep:tokio-util", "dep:futures", ] -std = ["tenderdash-proto/std"] -grpc = ["std", "tenderdash-proto/grpc"] +# std is deprecated, use "grpc" instead +std = ["grpc"] +grpc = ["tenderdash-proto/grpc"] crypto = ["dep:lhash"] tcp = ["server"] unix = ["server"] diff --git a/proto-compiler/Cargo.toml b/proto-compiler/Cargo.toml index ba65a6a..24b3002 100644 --- a/proto-compiler/Cargo.toml +++ b/proto-compiler/Cargo.toml @@ -25,7 +25,7 @@ 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. +# Build the gRPC server. Requires tenderdash-proto/grpc feature. server = ["grpc"] -# Build the gRPC client. Requires tenderdash-proto/std feature. +# Build the gRPC client. Requires tenderdash-proto/grpc feature. client = ["grpc"] diff --git a/proto-compiler/src/constants.rs b/proto-compiler/src/constants.rs index 0ff9aca..905a0d0 100644 --- a/proto-compiler/src/constants.rs +++ b/proto-compiler/src/constants.rs @@ -2,6 +2,20 @@ /// Tenderdash repository URL. pub const TENDERDASH_REPO: &str = "https://github.com/dashpay/tenderdash"; + +pub enum ModuleType { + Std, + NoStd, +} +impl ToString for ModuleType { + fn to_string(&self) -> String { + match self { + ModuleType::Std => "tenderdash_std".to_string(), + ModuleType::NoStd => "tenderdash_nostd".to_string(), + } + } +} + // Commitish formats: // Tag: v0.34.0-rc4 // Branch: master diff --git a/proto-compiler/src/functions.rs b/proto-compiler/src/functions.rs index 59bc118..ef04878 100644 --- a/proto-compiler/src/functions.rs +++ b/proto-compiler/src/functions.rs @@ -7,7 +7,7 @@ use std::{ use walkdir::WalkDir; -use crate::constants::DEFAULT_TENDERDASH_COMMITISH; +use crate::constants::{ModuleType, DEFAULT_TENDERDASH_COMMITISH}; /// Check out a specific commitish of the tenderdash repository. /// @@ -247,7 +247,7 @@ pub fn generate_tenderdash_lib( tenderdash_lib_target: &Path, abci_ver: &str, td_ver: &str, - module_name: &str, + module_type: &ModuleType, ) { let mut file_names = WalkDir::new(prost_dir) .into_iter() @@ -310,7 +310,7 @@ pub mod meta {{ tenderdash_commitish(), abci_ver, td_ver, - module_name, + module_type.to_string(), ); let mut file = diff --git a/proto-compiler/src/lib.rs b/proto-compiler/src/lib.rs index 4d02afa..db9aece 100644 --- a/proto-compiler/src/lib.rs +++ b/proto-compiler/src/lib.rs @@ -9,6 +9,7 @@ use functions::{ }; mod constants; +pub use constants::ModuleType; use constants::{CUSTOM_FIELD_ATTRIBUTES, CUSTOM_TYPE_ATTRIBUTES, TENDERDASH_REPO}; use crate::functions::{check_state, save_state}; @@ -22,10 +23,14 @@ use crate::functions::{check_state, save_state}; /// # Arguments /// /// * `module_name` - name of module to put generated files into -pub fn proto_compile(module_name: &str) { +pub fn proto_compile(module_type: ModuleType) { let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - let prost_out_dir = root.join("..").join("proto").join("src").join(module_name); + let prost_out_dir = root + .join("..") + .join("proto") + .join("src") + .join(module_type.to_string()); let tenderdash_lib_target = prost_out_dir.join("mod.rs"); let out_dir = var("OUT_DIR") @@ -108,14 +113,23 @@ pub fn proto_compile(module_name: &str) { 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(); + match module_type { + ModuleType::Std => { + #[cfg(feature = "grpc")] + tonic_build::configure() + .generate_default_stubs(true) + .compile_with_config(pb, &protos, &proto_includes_paths) + .unwrap(); + #[cfg(not(feature = "grpc"))] + panic!( + "grpc feature is required to compile {}", + module_type.to_string() + ); + }, + ModuleType::NoStd => { + pb.compile_protos(&protos, &proto_includes_paths).unwrap(); + }, + } println!("[info] => Removing old structs and copying new structs."); copy_files(&out_dir, &prost_out_dir); // This panics if it fails. @@ -125,7 +139,7 @@ pub fn proto_compile(module_name: &str) { &tenderdash_lib_target, &abci_ver, &tenderdash_ver, - module_name, + &module_type, ); save_state(&prost_out_dir, &commitish); diff --git a/proto/Cargo.toml b/proto/Cargo.toml index 412cf02..4b13bf5 100644 --- a/proto/Cargo.toml +++ b/proto/Cargo.toml @@ -33,11 +33,12 @@ all-features = true # issues related to outdated generated files. default = ["grpc"] -# Enable standard library support -std = ["prost/std", "prost-types/std"] -# Build gRPC server +# Enable standard library support; DEPRECATED - use `grpc` instead +std = ["grpc"] +# Build gRPC server using tonic grpc = [ - "std", + "prost/std", + "prost-types/std", "tenderdash-proto-compiler/server", "tenderdash-proto-compiler/client", "dep:tonic", diff --git a/proto/build.rs b/proto/build.rs index 0e6b055..d2cc633 100644 --- a/proto/build.rs +++ b/proto/build.rs @@ -1,5 +1,7 @@ use std::env; +use tenderdash_proto_compiler::ModuleType; + fn main() { // default Tenderdash version to use if TENDERDASH_COMMITISH is not set const DEFAULT_VERSION: &str = "v0.14.0-dev.5"; @@ -11,10 +13,10 @@ fn main() { env::set_var("TENDERDASH_COMMITISH", DEFAULT_VERSION); } - #[cfg(feature = "std")] - tenderdash_proto_compiler::proto_compile("tenderdash_std"); - #[cfg(not(feature = "std"))] - tenderdash_proto_compiler::proto_compile("tenderdash_nostd"); + #[cfg(feature = "grpc")] + tenderdash_proto_compiler::proto_compile(ModuleType::Std); + // we always build nostd version + tenderdash_proto_compiler::proto_compile(ModuleType::NoStd); println!("cargo:rerun-if-changed=../proto-compiler/src"); println!("cargo:rerun-if-changed=Cargo.toml"); diff --git a/proto/src/error.rs b/proto/src/error.rs index cfa6eb4..4c1d268 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 = "std"))] +#[cfg(not(feature = "grpc"))] use core::{convert::TryFrom, fmt::Display, num::TryFromIntError}; -#[cfg(feature = "std")] +#[cfg(feature = "grpc")] 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 f62ca63..d1023e9 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. -#![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(not(feature = "grpc"), no_std)] #![deny(warnings, trivial_casts, trivial_numeric_casts, unused_import_braces)] #![allow(clippy::large_enum_variant)] #![forbid(unsafe_code)] @@ -21,27 +21,27 @@ pub mod google { mod error; -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "grpc"))] use core::{ convert::{TryFrom, TryInto}, fmt::Display, }; -#[cfg(feature = "std")] +#[cfg(feature = "grpc")] use std::fmt::Display; use bytes::{Buf, BufMut}; pub use error::Error; use prost::{encoding::encoded_len_varint, Message}; -#[cfg(not(feature = "std"))] #[rustfmt::skip] pub mod tenderdash_nostd; -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "grpc"))] +// Re-export the nostd module only if the std one is not available pub use tenderdash_nostd::*; -#[cfg(feature = "std")] +#[cfg(feature = "grpc")] #[rustfmt::skip] pub mod tenderdash_std; -#[cfg(feature = "std")] +#[cfg(feature = "grpc")] pub use tenderdash_std::*; pub mod serializers; diff --git a/proto/src/protobuf.rs b/proto/src/protobuf.rs index b21e789..04237ac 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 = "std"))] +#[cfg(not(feature = "grpc"))] use core::fmt; -#[cfg(feature = "std")] +#[cfg(feature = "grpc")] 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 0544cc7..c1536ab 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 = "std"))] +#[cfg(not(feature = "grpc"))] use core::{fmt::Display, str::FromStr}; -#[cfg(feature = "std")] +#[cfg(feature = "grpc")] 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 17c9222..f55b977 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 = "std"))] +#[cfg(not(feature = "grpc"))] use core::{convert::TryFrom, fmt::Formatter}; -#[cfg(feature = "std")] +#[cfg(feature = "grpc")] use std::fmt::Formatter; use serde::{ diff --git a/proto/src/serializers/time_duration.rs b/proto/src/serializers/time_duration.rs index f30e943..0bdc33a 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 = "std"))] +#[cfg(not(feature = "grpc"))] use core::time::Duration; -#[cfg(feature = "std")] +#[cfg(feature = "grpc")] 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 41bf1f0..10ff120 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 = "std"))] +#[cfg(not(feature = "grpc"))] use core::fmt::{self, Debug}; -#[cfg(feature = "std")] +#[cfg(feature = "grpc")] 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 e0fdfeb..229c353 100644 --- a/proto/tests/unit.rs +++ b/proto/tests/unit.rs @@ -1,4 +1,4 @@ -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "grpc"))] use core::convert::TryFrom; use tenderdash_proto::{