Skip to content

Commit

Permalink
add tonic feature to proto crate (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid authored Nov 28, 2024
1 parent aec5bbe commit 91c14bd
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ The minor version will be incremented upon a breaking change and the patch versi

### Features

- proto: add tonic feature ([#474](https://github.com/rpcpool/yellowstone-grpc/pull/474))

### Breaking

## 2024-11-28
Expand Down
2 changes: 1 addition & 1 deletion yellowstone-grpc-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ futures = { workspace = true }
thiserror ={ workspace = true }
tonic = { workspace = true, features = ["tls", "tls-roots"] }
tonic-health = { workspace = true }
yellowstone-grpc-proto = { workspace = true }
yellowstone-grpc-proto = { workspace = true, features = ["tonic", "tonic-compression"] }

[dev-dependencies]
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
Expand Down
10 changes: 6 additions & 4 deletions yellowstone-grpc-proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ solana-transaction-status = { workspace = true, optional = true }
smallvec = { workspace = true, optional = true }
spl-token-2022 = { workspace = true, optional = true }
thiserror = { workspace = true, optional = true }
tonic = { workspace = true }
tonic = { workspace = true, optional = true }

[dev-dependencies]
criterion = { workspace = true }
Expand All @@ -44,7 +44,7 @@ protobuf-src = { workspace = true }
tonic-build = { workspace = true }

[features]
default = ["convert", "tonic-compression"]
default = ["convert", "tonic", "tonic-compression"]
convert = [
"dep:bincode",
"dep:solana-account-decoder",
Expand All @@ -60,10 +60,12 @@ plugin = [
"dep:serde",
"dep:smallvec",
"dep:spl-token-2022",
"dep:thiserror"
"dep:thiserror",
"dep:tonic"
]
plugin-bench = ["plugin", "dep:prost_011", "dep:solana-storage-proto"]
tonic-compression = ["tonic/gzip", "tonic/zstd"]
tonic = ["dep:tonic"]
tonic-compression = ["tonic", "tonic/gzip", "tonic/zstd"]

[lints]
workspace = true
17 changes: 15 additions & 2 deletions yellowstone-grpc-proto/build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
use tonic_build::manual::{Builder, Method, Service};
use {
std::{env, fs, path::Path},
tonic_build::manual::{Builder, Method, Service},
};

fn main() -> anyhow::Result<()> {
std::env::set_var("PROTOC", protobuf_src::protoc());

// build protos
tonic_build::compile_protos("proto/geyser.proto")?;
tonic_build::configure().compile_protos(&["proto/geyser.proto"], &["proto"])?;

// build protos without tonic (wasm)
let out_dir = env::var("OUT_DIR").expect("OUT_DIR not found");
let out_dir_path = Path::new(&out_dir).join("no-tonic");
fs::create_dir_all(&out_dir_path).expect("failed to create out no-tonic directory");
tonic_build::configure()
.build_client(false)
.build_server(false)
.out_dir(out_dir_path)
.compile_protos(&["proto/geyser.proto"], &["proto"])?;

// build with accepting our custom struct
let geyser_service = Service::builder()
Expand Down
20 changes: 17 additions & 3 deletions yellowstone-grpc-proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@ pub mod geyser {
#![allow(clippy::clone_on_ref_ptr)]
#![allow(clippy::missing_const_for_fn)]

tonic::include_proto!("geyser");
#[cfg(feature = "tonic")]
include!(concat!(env!("OUT_DIR"), "/geyser.rs"));
#[cfg(not(feature = "tonic"))]
include!(concat!(env!("OUT_DIR"), "/no-tonic/geyser.rs"));
}

pub mod solana {
#![allow(clippy::missing_const_for_fn)]

pub mod storage {
pub mod confirmed_block {
tonic::include_proto!("solana.storage.confirmed_block");
#[cfg(feature = "tonic")]
include!(concat!(
env!("OUT_DIR"),
"/solana.storage.confirmed_block.rs"
));
#[cfg(not(feature = "tonic"))]
include!(concat!(
env!("OUT_DIR"),
"/no-tonic/solana.storage.confirmed_block.rs"
));
}
}
}
Expand All @@ -21,7 +33,9 @@ pub mod prelude {
pub use super::{geyser::*, solana::storage::confirmed_block::*};
}

pub use {prost, tonic};
pub use prost;
#[cfg(feature = "tonic")]
pub use tonic;

#[cfg(feature = "plugin")]
pub mod plugin;
Expand Down

0 comments on commit 91c14bd

Please sign in to comment.