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

cosmos-sdk-proto: Generated serde serialization code is not usable in no_std context #499

Closed
romac opened this issue Sep 4, 2024 · 1 comment · Fixed by #500
Closed

Comments

@romac
Copy link
Member

romac commented Sep 4, 2024

It looks like the code generated by the buf.build/community/neoeinstein-prost-serde:v0.3.0 is not usable in no_std context:

$ git clone [email protected]:cosmos/cosmos-rust
$ cd cosmos-rust/cosmos-sdk-proto
$ git checkout cosmos-sdk-proto/v0.25.0-pre.0
$ cargo check --no-default-features --features serde
(...)

error[E0433]: failed to resolve: use of undeclared crate or module `std`
 --> cosmos-sdk-proto/src/prost/cosmos-sdk/cosmos.auth.v1beta1.serde.rs:5:46
  |
5 |     fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
  |                                              ^^^ use of undeclared crate or module `std`

(...)

error[E0433]: failed to resolve: use of undeclared type `ToString`
    --> cosmos-sdk-proto/src/prost/cosmos-sdk/cosmos.vesting.v1beta1.serde.rs:1191:50
     |
1191 |             struct_ser.serialize_field("length", ToString::to_string(&self.length).as_str())?;
     |                                                  ^^^^^^^^ use of undeclared type `ToString`
     |
help: consider importing one of these items
    -->  cosmos-sdk-proto/src/lib.rs:221:13
     |
221  +             use alloc::string::ToString;
    -->  |cosmos-sdk-proto/src/lib.rs:221:13
     |
221  +             use serde::__private::ToString;

(...)

To fix this, we should attempt to make the generated code work with no_std, either by patching the output, or by using informal-pbjson to generate the serialization code, like we do in ibc-proto-rs.

Just enabling the std feature when serde is enabled is unfortunately not really an option, as ibc-proto has downstream users which depend on the serde feature but not std.

As such it is currently blocking cosmos/ibc-proto-rs#187

@romac romac changed the title cosmos-sdk-proto: Fails to compile with --no-default-features --features serde cosmos-sdk-proto: Generated serde serialization code is not usable in no_std context Sep 4, 2024
tony-iqlusion added a commit that referenced this issue Sep 5, 2024
Adds some transforms which enable the generated PBJSON-related code to
be usable in `no_std` environments.

This is a workaround until such a time as it can be implemented natively
in `neoeinstein-prost-serde`. See neoeinstein/protoc-gen-prost#102.

Closes #499
@tony-iqlusion
Copy link
Member

Should be fixed by #500.

I also opened an upstream issue: neoeinstein/protoc-gen-prost#102

tony-iqlusion added a commit that referenced this issue Sep 5, 2024
Adds some transforms which enable the generated PBJSON-related code to
be usable in `no_std` environments.

This is a workaround until such a time as it can be implemented natively
in `neoeinstein-prost-serde`. See neoeinstein/protoc-gen-prost#102.

Closes #499
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants