Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicated protos and use feature-guard in generated code instead #240

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading