From a89fbfddbc1dac27e1cc806d6f1317068e948dce Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Mon, 23 Dec 2024 19:06:59 -0800 Subject: [PATCH] Exctract `proto` from `socket-layer` feature. Signed-off-by: Yury-Fridlyand --- .gitignore | 3 +++ glide-core/Cargo.toml | 3 ++- glide-core/build.rs | 5 +++-- glide-core/src/client/types.rs | 8 ++++---- glide-core/src/lib.rs | 4 ++-- glide-core/src/request_type.rs | 4 ++-- glide-core/src/retry_strategies.rs | 2 +- go/Cargo.toml | 2 +- go/src/lib.rs | 2 +- 9 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 6799f31ea6..d9c1fca963 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,6 @@ utils/TestUtils.js # java compiled files. *.class + +# generaged files (e.g. protobuf) +generated/ diff --git a/glide-core/Cargo.toml b/glide-core/Cargo.toml index bd12bb09c9..67500f7e66 100644 --- a/glide-core/Cargo.toml +++ b/glide-core/Cargo.toml @@ -43,11 +43,12 @@ serde_json = "1" serde = { version = "1", features = ["derive"] } [features] +proto = ["protobuf"] socket-layer = [ + "proto", "directories", "integer-encoding", "num_cpus", - "protobuf", "tokio-util", ] standalone_heartbeat = [] diff --git a/glide-core/build.rs b/glide-core/build.rs index 9ba9ca89a7..69e462a1ee 100644 --- a/glide-core/build.rs +++ b/glide-core/build.rs @@ -1,6 +1,6 @@ // Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 -#[cfg(feature = "socket-layer")] +#[cfg(feature = "proto")] fn build_protobuf() { let customization_options = protobuf_codegen::Customize::default() .lite_runtime(false) @@ -13,10 +13,11 @@ fn build_protobuf() { .input("src/protobuf/response.proto") .input("src/protobuf/connection_request.proto") .customize(customization_options) + .out_dir("src/generated") .run_from_script(); } fn main() { - #[cfg(feature = "socket-layer")] + #[cfg(feature = "proto")] build_protobuf(); } diff --git a/glide-core/src/client/types.rs b/glide-core/src/client/types.rs index a0053587c8..3f65294780 100644 --- a/glide-core/src/client/types.rs +++ b/glide-core/src/client/types.rs @@ -6,7 +6,7 @@ use logger_core::log_warn; use std::collections::HashSet; use std::time::Duration; -#[cfg(feature = "socket-layer")] +#[cfg(feature = "proto")] use crate::connection_request as protobuf; #[derive(Default)] @@ -73,7 +73,7 @@ pub struct ConnectionRetryStrategy { pub number_of_retries: u32, } -#[cfg(feature = "socket-layer")] +#[cfg(feature = "proto")] fn chars_to_string_option(chars: &::protobuf::Chars) -> Option { if chars.is_empty() { None @@ -82,7 +82,7 @@ fn chars_to_string_option(chars: &::protobuf::Chars) -> Option { } } -#[cfg(feature = "socket-layer")] +#[cfg(feature = "proto")] fn none_if_zero(value: u32) -> Option { if value == 0 { None @@ -91,7 +91,7 @@ fn none_if_zero(value: u32) -> Option { } } -#[cfg(feature = "socket-layer")] +#[cfg(feature = "proto")] impl From for ConnectionRequest { fn from(value: protobuf::ConnectionRequest) -> Self { let read_from = value.read_from.enum_value().ok().map(|val| match val { diff --git a/glide-core/src/lib.rs b/glide-core/src/lib.rs index 9450afef2c..352b395766 100644 --- a/glide-core/src/lib.rs +++ b/glide-core/src/lib.rs @@ -1,7 +1,7 @@ // Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 -#[cfg(feature = "socket-layer")] -include!(concat!(env!("OUT_DIR"), "/protobuf/mod.rs")); +#[cfg(feature = "proto")] +include!("generated/mod.rs"); pub mod client; mod retry_strategies; #[cfg(feature = "socket-layer")] diff --git a/glide-core/src/request_type.rs b/glide-core/src/request_type.rs index d6b43ae027..83c1409fb8 100644 --- a/glide-core/src/request_type.rs +++ b/glide-core/src/request_type.rs @@ -2,7 +2,7 @@ use redis::{cmd, Cmd}; -#[cfg(feature = "socket-layer")] +#[cfg(feature = "proto")] use crate::command_request::RequestType as ProtobufRequestType; #[repr(C)] @@ -431,7 +431,7 @@ fn get_two_word_command(first: &str, second: &str) -> Cmd { cmd } -#[cfg(feature = "socket-layer")] +#[cfg(feature = "proto")] impl From<::protobuf::EnumOrUnknown> for RequestType { fn from(value: ::protobuf::EnumOrUnknown) -> Self { match value.enum_value_or(ProtobufRequestType::InvalidRequest) { diff --git a/glide-core/src/retry_strategies.rs b/glide-core/src/retry_strategies.rs index 3b60cc402e..ad0fd720a0 100644 --- a/glide-core/src/retry_strategies.rs +++ b/glide-core/src/retry_strategies.rs @@ -54,7 +54,7 @@ pub(crate) fn get_exponential_backoff( } } -#[cfg(feature = "socket-layer")] +#[cfg(feature = "proto")] #[allow(dead_code)] pub(crate) fn get_fixed_interval_backoff( fixed_interval: u32, diff --git a/go/Cargo.toml b/go/Cargo.toml index 90f86983e7..abd60a9ea0 100644 --- a/go/Cargo.toml +++ b/go/Cargo.toml @@ -10,7 +10,7 @@ crate-type = ["cdylib"] [dependencies] redis = { path = "../glide-core/redis-rs/redis", features = ["aio", "tokio-comp", "connection-manager", "tokio-rustls-comp"] } -glide-core = { path = "../glide-core", features = ["socket-layer"] } +glide-core = { path = "../glide-core", features = ["proto"] } tokio = { version = "^1", features = ["rt", "macros", "rt-multi-thread", "time"] } protobuf = { version = "3.3.0", features = [] } diff --git a/go/src/lib.rs b/go/src/lib.rs index 361bf320f6..604129186c 100644 --- a/go/src/lib.rs +++ b/go/src/lib.rs @@ -28,7 +28,7 @@ use tokio::runtime::Runtime; #[derive(Debug)] pub struct CommandResponse { response_type: ResponseType, - int_value: c_long, + int_value: i64, float_value: c_double, bool_value: bool,