Skip to content

Commit

Permalink
Remove duplicated protos and use feature-guard in generated code inst…
Browse files Browse the repository at this point in the history
…ead (#240)

* consolidated protobuf w/ transport feature

* cargo fmt

---------

Co-authored-by: David Komer <6406986+dakom@users.noreply.github.com>
  • Loading branch information
dakom and dakom committed Sep 19, 2024
1 parent 06f9f52 commit 1363423
Show file tree
Hide file tree
Showing 94 changed files with 360 additions and 62,375 deletions.
48 changes: 14 additions & 34 deletions scripts/sync-protobuf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,10 @@ popd
# so that the newly generated code does not
# contain removed files.

PROST_TRANSPORT_DIR="prost-transport"
PROST_NO_TRANSPORT_DIR="prost-no-transport"
PROST_DIR="prost"

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"
rm -rf "src/$PROST_DIR"
mkdir -p "src/$PROST_DIR"

cd tools/proto-compiler

Expand All @@ -154,45 +151,28 @@ cargo run -- compile \
--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_NO_TRANSPORT_DIR"
--out "../../src/$PROST_DIR"

cd ../..

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

# Remove leftover Cosmos SDK modules.
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"
rm -f "src/$PROST_DIR/cosmos.base.store.v1beta1.rs"
rm -f "src/$PROST_DIR/cosmos.auth.v1beta1.rs"
rm -f "src/$PROST_DIR/cosmos.base.query.v1beta1.rs"
rm -f "src/$PROST_DIR/cosmos.base.v1beta1.rs"
rm -f "src/$PROST_DIR/cosmos.staking.v1beta1.rs"
rm -f "src/$PROST_DIR/cosmos.upgrade.v1beta1.rs"
rm -f "src/$PROST_DIR/cosmos_proto.rs"

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

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

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

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

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

Expand All @@ -43,10 +34,8 @@ 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(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");
#[cfg(feature = "proto-descriptor")]
pub const FILE_DESCRIPTOR_SET: &[u8] = include_bytes!("prost/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 1363423

Please sign in to comment.