Skip to content

Commit

Permalink
Feature-gate generated tonic transport code behind transport feature (
Browse files Browse the repository at this point in the history
#238)

* code changes for no-transport option

* new protobuf generated with no-transport

* fmt

* Add changelog entry

---------

Co-authored-by: David Komer <6406986+dakom@users.noreply.github.com>
Co-authored-by: Romain Ruetschi <romain@informal.systems>
  • Loading branch information
3 people authored Sep 17, 2024
1 parent ca638cb commit 06f9f52
Show file tree
Hide file tree
Showing 95 changed files with 62,391 additions and 307 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/features/237-transport-feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Feature-gate generated `tonic` transport code behind `transport` feature
([\#237](https://github.com/cosmos/ibc-proto-rs/issues/237))
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ default-features = false
serde_json = "1.0.107"

[features]
default = ["std", "client"]
default = ["std", "client", "transport"]
transport = ["tonic/transport", "cosmos-sdk-proto/grpc-transport"]
std = ["cosmos-sdk-proto/std", "prost/std", "bytes/std", "subtle-encoding/std", "base64/std", "flex-error/std", "ics23/std", "informalsystems-pbjson/std"]
serde = ["dep:serde", "dep:informalsystems-pbjson", "ics23/serde", "cosmos-sdk-proto/serde"]
client = ["std", "dep:tonic", "tonic/codegen", "tonic/transport", "tonic/prost", "cosmos-sdk-proto/grpc-transport"]
client = ["std", "dep:tonic", "tonic/codegen", "tonic/prost"]
json-schema = ["std", "serde", "dep:schemars"]
server = ["std", "dep:tonic", "tonic/codegen", "tonic/transport", "tonic/prost"]
server = ["std", "dep:tonic", "tonic/codegen", "tonic/prost"]
parity-scale-codec = ["tendermint-proto/parity-scale-codec"]
borsh = ["tendermint-proto/borsh"]
proto-descriptor = []
53 changes: 38 additions & 15 deletions scripts/sync-protobuf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,43 +133,66 @@ popd
# so that the newly generated code does not
# contain removed files.

rm -rf src/prost
mkdir -p src/prost
PROST_TRANSPORT_DIR="prost-transport"
PROST_NO_TRANSPORT_DIR="prost-no-transport"

rm -rf "src/$PROST_TRANSPORT_DIR"
rm -rf "src/$PROST_NO_TRANSPORT_DIR"
mkdir -p "src/$PROST_TRANSPORT_DIR"
mkdir -p "src/$PROST_NO_TRANSPORT_DIR"

cd tools/proto-compiler

cargo build

# Run the proto-compiler twice,
# once for std version with --build-tonic set to true
# and once for no-std version with --build-tonic set to false
# once with transport and once without


cargo run -- compile \
--transport \
--ics "$COSMOS_ICS_DIR/proto-include" \
--ibc "$IBC_GO_DIR/proto-include" \
--nft "$NFT_TRANSFER_DIR/proto-include" \
--out "../../src/$PROST_TRANSPORT_DIR"

cargo run -- compile \
--ics "$COSMOS_ICS_DIR/proto-include" \
--ibc "$IBC_GO_DIR/proto-include" \
--nft "$NFT_TRANSFER_DIR/proto-include" \
--out ../../src/prost
--out "../../src/$PROST_NO_TRANSPORT_DIR"

cd ../..

# Remove generated ICS23 code because it is not used,
# we instead re-exports the `ics23` crate type definitions.
rm -f src/prost/cosmos.ics23.v1.rs
rm -f "src/$PROST_TRANSPORT_DIR/cosmos.ics23.v1.rs"
rm -f "src/$PROST_NO_TRANSPORT_DIR/cosmos.ics23.v1.rs"

# Remove leftover Cosmos SDK modules.
rm -f src/prost/cosmos.base.store.v1beta1.rs
rm -f src/prost/cosmos.auth.v1beta1.rs
rm -f src/prost/cosmos.base.query.v1beta1.rs
rm -f src/prost/cosmos.base.v1beta1.rs
rm -f src/prost/cosmos.staking.v1beta1.rs
rm -f src/prost/cosmos.upgrade.v1beta1.rs
rm -f src/prost/cosmos_proto.rs
rm -f "src/$PROST_TRANSPORT_DIR/cosmos.base.store.v1beta1.rs"
rm -f "src/$PROST_TRANSPORT_DIR/cosmos.auth.v1beta1.rs"
rm -f "src/$PROST_TRANSPORT_DIR/cosmos.base.query.v1beta1.rs"
rm -f "src/$PROST_TRANSPORT_DIR/cosmos.base.v1beta1.rs"
rm -f "src/$PROST_TRANSPORT_DIR/cosmos.staking.v1beta1.rs"
rm -f "src/$PROST_TRANSPORT_DIR/cosmos.upgrade.v1beta1.rs"
rm -f "src/$PROST_TRANSPORT_DIR/cosmos_proto.rs"

rm -f "src/$PROST_NO_TRANSPORT_DIR/cosmos.base.store.v1beta1.rs"
rm -f "src/$PROST_NO_TRANSPORT_DIR/cosmos.auth.v1beta1.rs"
rm -f "src/$PROST_NO_TRANSPORT_DIR/cosmos.base.query.v1beta1.rs"
rm -f "src/$PROST_NO_TRANSPORT_DIR/cosmos.base.v1beta1.rs"
rm -f "src/$PROST_NO_TRANSPORT_DIR/cosmos.staking.v1beta1.rs"
rm -f "src/$PROST_NO_TRANSPORT_DIR/cosmos.upgrade.v1beta1.rs"
rm -f "src/$PROST_NO_TRANSPORT_DIR/cosmos_proto.rs"

# The Tendermint ABCI protos are unused from within ibc-proto
rm -f src/prost/tendermint.abci.rs
rm -f "src/$PROST_TRANSPORT_DIR/tendermint.abci.rs"
rm -f "src/$PROST_NO_TRANSPORT_DIR/tendermint.abci.rs"

# Remove leftover Google HTTP configuration protos.
rm -f src/prost/google.api.rs
rm -f "src/$PROST_TRANSPORT_DIR/google.api.rs"
rm -f "src/$PROST_NO_TRANSPORT_DIR/google.api.rs"

# Remove the temporary checkouts of the repositories
rm -rf "$COSMOS_ICS_DIR"
Expand Down
17 changes: 14 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@ extern crate alloc;
extern crate core as std;

#[macro_export]
#[cfg(not(feature = "transport"))]
macro_rules! include_proto {
($path:literal) => {
include!(concat!("prost/", $path));
include!(concat!("prost-no-transport/", $path));
};
}

#[macro_export]
#[cfg(feature = "transport")]
macro_rules! include_proto {
($path:literal) => {
include!(concat!("prost-transport/", $path));
};
}

Expand All @@ -34,8 +43,10 @@ pub const INTERCHAIN_SECURITY_COMMIT: &str = include_str!("INTERCHAIN_SECURITY_C
pub const NFT_TRANSFER_COMMIT: &str = include_str!("NFT_TRANSFER_COMMIT");

/// File descriptor set of compiled proto.
#[cfg(feature = "proto-descriptor")]
pub const FILE_DESCRIPTOR_SET: &[u8] = include_bytes!("prost/proto_descriptor.bin");
#[cfg(all(feature = "proto-descriptor", feature = "transport"))]
pub const FILE_DESCRIPTOR_SET: &[u8] = include_bytes!("prost-transport/proto_descriptor.bin");
#[cfg(all(feature = "proto-descriptor", not(feature = "transport")))]
pub const FILE_DESCRIPTOR_SET: &[u8] = include_bytes!("prost-no-transport/proto_descriptor.bin");

// Re-export Cosmos SDK protos from the `cosmos_sdk_proto` crate
pub use cosmos_sdk_proto::cosmos;
Expand Down
Loading

0 comments on commit 06f9f52

Please sign in to comment.