Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Fix Substrate features #14660

Merged
merged 19 commits into from
Aug 1, 2023
Merged

Fix Substrate features #14660

merged 19 commits into from
Aug 1, 2023

Conversation

ggwpez
Copy link
Member

@ggwpez ggwpez commented Jul 27, 2023

Trying to automatically fix std, runtime-benchmarks and try-runtime features with

zepter lint propagate-feature --feature try-runtime --left-side-feature-missing=ignore --workspace --fix --feature-enables-dep="try-runtime:frame-try-runtime"
zepter lint propagate-feature --feature runtime-benchmarks --left-side-feature-missing=ignore --workspace --fix --feature-enables-dep="runtime-benchmarks:frame-benchmarking"
zepter lint propagate-feature --feature std --left-side-feature-missing=ignore --workspace --fix

The auto-fixer tries to be as non-invasive as possible, but removes empty lines.

Explanation:

  • This adds the feature for all dependencies that expose it. It does not create the feature if it is not present, since left-side-feature-missing is passed. To be really correct I think we would have to add it to all crates that do not have it though.
  • The feature-enables-dep will enable the given dependency as non-optional when the feature is enabled. Otherwise the features of optional dependencies will also be enabled as optional.

Known blindspot: The --workspace flag currently requires that both sides are in the workspace. This will be extended soon to also allow the right-hand-side dependency to be outside of the worspace. Since currently it does not detect serde/std as missing when the --workspace flag is present.

TODO:

  • Double check that it also works fine for dev-dependencies. I am not sure what rules to use here.
  • Add CI
  • Add other featalign to double-check (will maybe do as follow up so we already have something working).

zepter lint propagate-feature --feature try-runtime --left-side-feature-missing=ignore --workspace --fix --feature-enables-dep="try-runtime:frame-try-runtime"
zepter lint propagate-feature --feature runtime-benchmarks --left-side-feature-missing=ignore --workspace --fix --feature-enables-dep="runtime-benchmarks:frame-benchmarking"
zepter lint propagate-feature --feature std --left-side-feature-missing=ignore --workspace --fix

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@ggwpez ggwpez added A3-in_progress Pull request is in progress. No review needed at this stage. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit labels Jul 27, 2023
ggwpez added 11 commits July 27, 2023 16:27
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@ggwpez ggwpez marked this pull request as ready for review July 27, 2023 19:25
@ggwpez ggwpez requested review from a team July 27, 2023 19:25
@ggwpez ggwpez requested a review from a team July 27, 2023 19:25
@ggwpez ggwpez requested review from cheme, koute and a team as code owners July 27, 2023 19:25
@ggwpez ggwpez added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Jul 27, 2023
@paritytech-ci paritytech-ci requested a review from a team July 28, 2023 07:30
@shawntabrizi
Copy link
Member

Could we use Zepter to a little bit of toml formatting too?

For example organizing dependencies alphabetically?

@ggwpez
Copy link
Member Author

ggwpez commented Jul 30, 2023

Could we use Zepter to a little bit of toml formatting too?

For example organizing dependencies alphabetically?

Yes we definitely can. Currently the autofixer is written to not re-order anything, but it already has to touch the toml array, so it could be ordered as well.
Comments within the dependency array are lost, but i think that is a fine trade-off in this case.

@koute
Copy link
Contributor

koute commented Jul 30, 2023

Comments within the dependency array are lost, but i think that is a fine trade-off in this case.

Could we make it so that they're not lost? (I assume there are toml libraries which can do this?)

@ggwpez
Copy link
Member Author

ggwpez commented Jul 30, 2023

Comments within the dependency array are lost, but i think that is a fine trade-off in this case.

Could we make it so that they're not lost? (I assume there are toml libraries which can do this?)

Oh, the official toml_edit crate actually mentions that it can preserve comment - so I must just be using it wrong. I will look into it, thanks!

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

Looks good besides the edge case around enabling of a crate and a feature in one go that I highlighted in the review

primitives/consensus/babe/Cargo.toml Outdated Show resolved Hide resolved
primitives/consensus/grandpa/Cargo.toml Outdated Show resolved Hide resolved
primitives/core/Cargo.toml Outdated Show resolved Hide resolved
primitives/io/Cargo.toml Outdated Show resolved Hide resolved
primitives/session/Cargo.toml Outdated Show resolved Hide resolved
primitives/transaction-storage-proof/Cargo.toml Outdated Show resolved Hide resolved
frame/asset-rate/Cargo.toml Outdated Show resolved Hide resolved
frame/examples/offchain-worker/Cargo.toml Outdated Show resolved Hide resolved
frame/support/test/Cargo.toml Outdated Show resolved Hide resolved
ggwpez and others added 2 commits August 1, 2023 21:33
Co-authored-by: Bastian Köcher <git@kchr.de>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@ggwpez
Copy link
Member Author

ggwpez commented Aug 1, 2023

bot merge

@paritytech-processbot paritytech-processbot bot merged commit b05a9d3 into master Aug 1, 2023
4 checks passed
@paritytech-processbot paritytech-processbot bot deleted the oty-fix-features branch August 1, 2023 20:26
@AurevoirXavier
Copy link
Contributor

AurevoirXavier commented Aug 3, 2023

cargo-featalign can address many of the situations mentioned in this thread such as preseving comments. Recently, I added support for sorting features alphabetically based on @shawntabrizi's comment.

However, I am unsure about how parity CI functions. I am eager to apply this tool to Substrate. cc @ggwpez

@ggwpez
Copy link
Member Author

ggwpez commented Aug 3, 2023

@AurevoirXavier you can check out the diff in scripts/ci/gitlab/pipeline/check.yml of this MR.
You can just add featalign alongside the Zepter invocation there into the same job. I am not a CI engie myself, but it should be fine.
The job currently takes 33 sec, it runs as one of the first jobs, but AFAIK it does not block later ones.

@shawntabrizi
Copy link
Member

it would be great if these feature fix stuff was somehow integrated into the node-template, cumulus, and similar projects.

Then users would run something like ./scripts/fix-features.sh in their custom project and make sure they are doing everything right.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

10 participants