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

add no_std support #42

Merged
merged 9 commits into from
Nov 9, 2022
Merged

add no_std support #42

merged 9 commits into from
Nov 9, 2022

Conversation

gilescope
Copy link
Contributor

@gilescope gilescope commented Aug 28, 2022

This PR is proposing upstreaming the work done by Integritee parachain and in particular @echevrier to make frame-metadata work for no_std. I have been using this fork myself for a month or two now and can confirm it works fine in browsers.

It's pretty important that we have no_std support as otherwise it's a big blocker for anyone trying to decode scale in wasm (ie. in the browser).

Happy to implement any feedback to get no_std support into main.

Co-authored-by: echevrier edith.chevrier@scs.ch

#2)

* Metadata supporting scale-info can be decoded and serialized in no_std (feature flag scale_info)

* Changes from review: rename feature flag into full_derive

* Changes from review: std implies full-derive

* Changes from review: optimization

Co-authored-by: echevrier <edith.chevrier@scs.ch>
@cla-bot-2021
Copy link

cla-bot-2021 bot commented Aug 28, 2022

User @echevrier, please sign the CLA here.

@gilescope
Copy link
Contributor Author

@echevrier what are your thoughts? Are you happy for this to be upstreamed?

@echevrier
Copy link
Contributor

@echevrier what are your thoughts? Are you happy for this to be upstreamed?
Yes sure. Thanks a lot.

frame-metadata/Cargo.toml Outdated Show resolved Hide resolved
@gilescope
Copy link
Contributor Author

thinking about renaming full_derive into two features: serde-codec and decode. There's some debug impls in there too. I'm tempted to leave them out and just try and land the minimum possible to be able to use this crate in the browser.

@clangenb
Copy link

clangenb commented Sep 5, 2022

Very happy to see this upstream! I can understand that it is tempting to leave out Debug. However, not having debug limits downstream derives greatly, I would be very happy to see debug at least as an additional feature.

The reasoning behind the full_derive was exactly that it includes serde-codec, scale-decode and debug, considering that a crate that uses one of the features is probably by nature not in a performance critical environment, so it does not hurt to enable them all at once.

Again, I don't mind if it is split up, but I would be very happy to see the optional debug feature. :)

@gilescope
Copy link
Contributor Author

gilescope commented Sep 5, 2022 via email

@gilescope
Copy link
Contributor Author

#39 suggests calling serde_codec feature serde_full - seems reasonable to me.

Are there any downsides? Unused debug impls will just get optimised away won't they?
@gilescope
Copy link
Contributor Author

Ah. I see debug was already in std but just not pushed down to non-std. Right, happy now with this.

@gilescope
Copy link
Contributor Author

Moved the debug down for the other versions as well.

Copy link
Contributor

@ascjones ascjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, new feature names are much clearer

with:
command: check
toolchain: stable
args: --manifest-path ./frame-metadata/Cargo.toml --no-default-features --features decode,serde_full,v14
Copy link
Contributor

@jsdw jsdw Sep 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also worth adding a specific check for just serde_full and just decode features being enabled? (it's so easy to miss compile errors that don't occur when both are enabled but do occur when just one is)

Copy link
Member

@niklasad1 niklasad1 Sep 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest that we try to use cargo hack check --each-feature here if it's possible instead doing this manually it is so easy to forget some combination of feature flags.

Copy link
Contributor

@jsdw jsdw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just one suggestion

(if this plays well with ci then we should double up,
doing the same again but target wasm32)
@gilescope
Copy link
Contributor Author

How does this look re cargo hack? Not entirely sure how I coax the ci to run the changes...

@clangenb
Copy link

clangenb commented Nov 8, 2022

Is there a reason that prevents this PR from being merged? Would be nice to see it in the next release.

@ascjones
Copy link
Contributor

ascjones commented Nov 8, 2022

If @jsdw and @niklasad1 are happy that their suggestions are applied then we can merge

@niklasad1
Copy link
Member

niklasad1 commented Nov 8, 2022

yeah, it looks good to me

@jsdw ? :)

@jsdw
Copy link
Contributor

jsdw commented Nov 9, 2022

I'm good with it!

Ultimately we probably want to add a more thorough check that the no_std feature actually works (it's cropped up in other crates that somebody breaks no_std by importing some std thing not behind a feature flag etc, and it is missed) but I'm happy with this merging anyway at the mo; let's just open an issue to do a more thorough test!

@jsdw jsdw merged commit 1ea3299 into paritytech:main Nov 9, 2022
@jsdw jsdw mentioned this pull request Nov 9, 2022
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 this pull request may close these issues.

6 participants