Skip to content

Commit

Permalink
Improve features dev-ex (#1831)
Browse files Browse the repository at this point in the history
Adds a config file that allows to run `zepter` without any arguments in
the workspace to address all issues.
A secondary workflow for the CI is provided as `zepter run check`. Both
the formatting and linting are now in one check for efficiancy.

The latest version also detects some more things that `featalign` was
already showing.

Error message [in the
CI](https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/3916205)
now looks like this:
```pre
...
crate 'test-parachains' (/Users/vados/Documents/work/polkadot-sdk/polkadot/parachain/test-parachains/Cargo.toml)
  feature 'std'
    must propagate to:
      parity-scale-codec
Found 55 issues (run with --fix to fix).
Error: Command 'lint propagate-feature' failed with exit code 1

Polkadot-SDK uses the Zepter CLI to detect abnormalities in the feature configuration.
It looks like one more more checks failed; please check the console output. You can try to automatically address them by running `zepter`.
Otherwise please ask directly in the Merge Request, GitHub Discussions or on Matrix Chat, thank you.

For more information, see:
  - #1831
  - https://github.com/ggwpez/zepter
```

TODO:
- [x] Check that CI fails correctly

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  • Loading branch information
ggwpez authored and s0me0ne-unkn0wn committed Oct 29, 2023
1 parent 335f0c3 commit bc98204
Show file tree
Hide file tree
Showing 46 changed files with 108 additions and 23 deletions.
45 changes: 45 additions & 0 deletions .config/zepter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version:
format: 1
# Minimum version of the binary that is expected to work. This is just for printing a nice error
# message when someone tries to use an older version.
binary: 0.13.2

# The examples in this file assume crate `A` to have a dependency on crate `B`.
workflows:
check:
- [
'lint',
# Check that `A` activates the features of `B`.
'propagate-feature',
# These are the features to check:
'--features=try-runtime,runtime-benchmarks,std',
# Do not try to add a new section into `[features]` of `A` only because `B` expose that feature. There are edge-cases where this is still needed, but we can add them manually.
'--left-side-feature-missing=ignore',
# Enabling this feature somehow pulls in two versions of `sp-runtime-interface` and makes it impossible to build that crate with `cargo b -p sp-runtime-interface`. We therefore disable it for now.
'--ignore-missing-propagate=sp-core/std:bandersnatch_vrfs/std',
# Ignore the case that `A` it outside of the workspace. Otherwise it will report errors in external dependencies that we have no influence on.
'--left-side-outside-workspace=ignore',
# Some features imply that they activate a specific dependency as non-optional. Otherwise the default behaviour with a `?` is used.
'--feature-enables-dep=try-runtime:frame-try-runtime,runtime-benchmarks:frame-benchmarking',
# Actually modify the files and not just report the issues:
'--offline',
'--locked',
'--show-path',
'--quiet',
]
# Format the features into canonical format:
- ['format', 'features', '--offline', '--locked', '--quiet']
# Same as `check`, but with the `--fix` flag.
default:
- [ $check.0, '--fix' ]
- [ $check.1, '--fix' ]

# Will be displayed when any workflow fails:
help:
text: |
Polkadot-SDK uses the Zepter CLI to detect abnormalities in the feature configuration.
It looks like one more more checks failed; please check the console output. You can try to automatically address them by running `zepter`.
Otherwise please ask directly in the Merge Request, GitHub Discussions or on Matrix Chat, thank you.
links:
- "https://github.com/paritytech/polkadot-sdk/issues/1831"
- "https://github.com/ggwpez/zepter"
19 changes: 3 additions & 16 deletions .gitlab/pipeline/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ check-try-runtime:
# experimental code may rely on try-runtime and vice-versa
- time cargo check --locked --all --features try-runtime,experimental

cargo-fmt-manifest:
stage: check
extends:
- .docker-env
- .common-refs
script:
- cargo install zepter --locked --version 0.11.0 -q -f --no-default-features && zepter --version
- echo "👉 Hello developer! If you see this CI check failing then it means that one of the your changes in a Cargo.toml file introduced ill-formatted or unsorted features. Please take a look at 'docs/STYLE_GUIDE.md#manifest-formatting' to find out more."
- zepter format features --check

# FIXME
.cargo-deny-licenses:
stage: check
Expand Down Expand Up @@ -91,17 +81,14 @@ job-starter:
script:
- echo ok

test-rust-feature-propagation:
check-rust-feature-propagation:
stage: check
extends:
- .kubernetes-env
- .test-pr-refs
script:
- cargo install --locked --version 0.11.1 -q -f zepter && zepter --version
- echo "👉 Hello developer! If you see this CI check failing then it means that one of the crates is missing a feature for one of its dependencies. The output below tells you which feature needs to be added for which dependency to which crate. You can do this by modifying the Cargo.toml file. For more context see the MR where this check was introduced https://github.com/paritytech/substrate/pull/14660"
- zepter lint propagate-feature --feature try-runtime --left-side-feature-missing=ignore --workspace --feature-enables-dep="try-runtime:frame-try-runtime" --locked
- zepter lint propagate-feature --feature runtime-benchmarks --left-side-feature-missing=ignore --workspace --feature-enables-dep="runtime-benchmarks:frame-benchmarking" --locked
- zepter lint propagate-feature --feature std --left-side-feature-missing=ignore --workspace --locked
- cargo install --locked --version 0.13.2 -q -f zepter && zepter --version
- zepter run check

# More info can be found here: https://github.com/paritytech/polkadot/pull/5865
.check-runtime-migration:
Expand Down
1 change: 1 addition & 0 deletions bridges/primitives/chain-polkadot-bulletin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ std = [
"codec/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"sp-api/std",
"sp-runtime/std",
"sp-std/std",
Expand Down
2 changes: 2 additions & 0 deletions bridges/primitives/relayers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ default = [ "std" ]
std = [
"bp-messages/std",
"bp-runtime/std",
"codec/std",
"frame-support/std",
"scale-info/std",
"sp-runtime/std",
"sp-std/std",
]
1 change: 1 addition & 0 deletions cumulus/pallets/parachain-system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ cumulus-test-relay-sproof-builder = { path = "../../test/relay-sproof-builder" }
[features]
default = [ "std" ]
std = [
"bytes/std",
"codec/std",
"cumulus-pallet-parachain-system-proc-macro/std",
"cumulus-primitives-core/std",
Expand Down
1 change: 1 addition & 0 deletions cumulus/pallets/xcmp-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ std = [
"log/std",
"polkadot-runtime-common/std",
"polkadot-runtime-parachains/std",
"rand_chacha/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
Expand Down
3 changes: 3 additions & 0 deletions cumulus/parachains/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ substrate-wasm-builder = { path = "../../../substrate/utils/wasm-builder" }
[features]
default = [ "std" ]
std = [
"codec/std",
"cumulus-primitives-core/std",
"cumulus-primitives-utility/std",
"frame-support/std",
"frame-system/std",
"log/std",
"num-traits/std",
"pallet-asset-tx-payment/std",
"pallet-assets/std",
"pallet-authorship/std",
Expand All @@ -66,6 +68,7 @@ std = [
"polkadot-core-primitives/std",
"polkadot-primitives/std",
"rococo-runtime-constants/std",
"scale-info/std",
"sp-consensus-aura/std",
"sp-core/std",
"sp-io/std",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ std = [
"polkadot-core-primitives/std",
"polkadot-parachain-primitives/std",
"polkadot-runtime-common/std",
"primitive-types/std",
"scale-info/std",
"sp-api/std",
"sp-block-builder/std",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ std = [
"polkadot-core-primitives/std",
"polkadot-parachain-primitives/std",
"polkadot-runtime-common/std",
"primitive-types/std",
"rococo-runtime-constants/std",
"scale-info/std",
"sp-api/std",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ std = [
"polkadot-core-primitives/std",
"polkadot-parachain-primitives/std",
"polkadot-runtime-common/std",
"primitive-types/std",
"scale-info/std",
"sp-api/std",
"sp-block-builder/std",
Expand Down
1 change: 1 addition & 0 deletions cumulus/parachains/runtimes/assets/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ std = [
"pallet-asset-tx-payment/std",
"pallet-xcm/std",
"parachains-common/std",
"scale-info/std",
"sp-api/std",
"sp-runtime/std",
"sp-std/std",
Expand Down
1 change: 1 addition & 0 deletions cumulus/parachains/runtimes/assets/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ substrate-wasm-builder = { path = "../../../../../substrate/utils/wasm-builder"
default = [ "std" ]
std = [
"assets-common/std",
"codec/std",
"cumulus-pallet-dmp-queue/std",
"cumulus-pallet-parachain-system/std",
"cumulus-pallet-xcmp-queue/std",
Expand Down
1 change: 1 addition & 0 deletions cumulus/parachains/runtimes/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ substrate-wasm-builder = { path = "../../../../substrate/utils/wasm-builder" }
default = [ "std" ]
std = [
"assets-common/std",
"codec/std",
"cumulus-pallet-dmp-queue/std",
"cumulus-pallet-parachain-system/std",
"cumulus-pallet-xcmp-queue/std",
Expand Down
1 change: 1 addition & 0 deletions cumulus/primitives/timestamp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ cumulus-primitives-core = { path = "../core", default-features = false }
[features]
default = [ "std" ]
std = [
"codec/std",
"cumulus-primitives-core/std",
"sp-inherents/std",
"sp-std/std",
Expand Down
1 change: 1 addition & 0 deletions cumulus/primitives/utility/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ std = [
"codec/std",
"cumulus-primitives-core/std",
"frame-support/std",
"log/std",
"pallet-xcm-benchmarks/std",
"polkadot-runtime-common/std",
"polkadot-runtime-parachains/std",
Expand Down
2 changes: 1 addition & 1 deletion docs/STYLE_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ let mut target_path =

> **TLDR**
> You can use the CLI tool [Zepter](https://crates.io/crates/zepter) to
> format the files: `zepter format features`
> format the files: `zepter format features --fix` (or `zepter f f -f`).
Rust `Cargo.toml` files need to respect certain formatting rules. All entries
need to be alphabetically sorted. This makes it easier to read them and insert
Expand Down
2 changes: 1 addition & 1 deletion polkadot/parachain/test-parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ sp-core = { path = "../../../substrate/primitives/core" }

[features]
default = [ "std" ]
std = [ "adder/std", "halt/std" ]
std = [ "adder/std", "halt/std", "parity-scale-codec/std" ]
2 changes: 1 addition & 1 deletion polkadot/parachain/test-parachains/adder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ substrate-wasm-builder = { path = "../../../../substrate/utils/wasm-builder" }

[features]
default = [ "std" ]
std = [ "parachain/std", "sp-io/std", "sp-std/std" ]
std = [ "parachain/std", "parity-scale-codec/std", "sp-io/std", "sp-std/std" ]
8 changes: 7 additions & 1 deletion polkadot/parachain/test-parachains/undying/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ substrate-wasm-builder = { path = "../../../../substrate/utils/wasm-builder" }

[features]
default = [ "std" ]
std = [ "parachain/std", "sp-io/std", "sp-std/std" ]
std = [
"log/std",
"parachain/std",
"parity-scale-codec/std",
"sp-io/std",
"sp-std/std",
]
2 changes: 2 additions & 0 deletions polkadot/runtime/parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ std = [
"polkadot-parachain-primitives/std",
"polkadot-runtime-metrics/std",
"primitives/std",
"rand/std",
"rand_chacha/std",
"rustc-hex/std",
"scale-info/std",
"serde/std",
Expand Down
1 change: 1 addition & 0 deletions polkadot/xcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ wasm-api = []
std = [
"bounded-collections/std",
"environmental/std",
"log/std",
"parity-scale-codec/std",
"scale-info/std",
"serde/std",
Expand Down
2 changes: 2 additions & 0 deletions polkadot/xcm/pallet-xcm-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ std = [
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"log/std",
"scale-info/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
Expand Down
1 change: 1 addition & 0 deletions polkadot/xcm/pallet-xcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ std = [
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"log/std",
"scale-info/std",
"serde",
"sp-core/std",
Expand Down
1 change: 1 addition & 0 deletions polkadot/xcm/xcm-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
]
std = [
"environmental/std",
"frame-benchmarking/std",
"frame-support/std",
"log/std",
Expand Down
1 change: 1 addition & 0 deletions substrate/bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ std = [
"pallet-utility/std",
"pallet-vesting/std",
"pallet-whitelist/std",
"primitive-types/std",
"scale-info/std",
"sp-api/std",
"sp-authority-discovery/std",
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/asset-conversion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ std = [
"frame-system/std",
"pallet-assets/std",
"pallet-balances/std",
"primitive-types/std",
"scale-info/std",
"sp-api/std",
"sp-arithmetic/std",
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/democracy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ std = [
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-balances/std",
"pallet-preimage/std",
"pallet-scheduler/std",
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/glutton/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ std = [
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-balances/std",
"scale-info/std",
"sp-core/std",
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/identity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ sp-core = { path = "../../primitives/core" }
default = [ "std" ]
std = [
"codec/std",
"enumflags2/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/message-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ std = [
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"log/std",
"scale-info/std",
"sp-arithmetic/std",
"sp-core/std",
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/multisig/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ std = [
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-balances/std",
"scale-info/std",
"sp-io/std",
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/nfts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ sp-keystore = { path = "../../primitives/keystore" }
default = [ "std" ]
std = [
"codec/std",
"enumflags2/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/nomination-pools/benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ sp-io = { path = "../../../primitives/io" }
default = [ "std" ]

std = [
"codec/std",
"frame-benchmarking/std",
"frame-election-provider-support/std",
"frame-support/std",
Expand All @@ -52,6 +53,7 @@ std = [
"pallet-nomination-pools/std",
"pallet-staking/std",
"pallet-timestamp/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-runtime-interface/std",
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/referenda/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ std = [
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-balances/std",
"pallet-preimage/std",
"pallet-scheduler/std",
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/society/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ std = [
"frame-support-test/std",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-balances/std",
"rand_chacha/std",
"scale-info/std",
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/statement/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ std = [
"codec/std",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-balances/std",
"scale-info/std",
"sp-api/std",
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ std = [
"log/std",
"scale-info/std",
"serde/std",
"serde_json/std",
"sp-api/std",
"sp-arithmetic/std",
"sp-core/std",
Expand Down
2 changes: 1 addition & 1 deletion substrate/primitives/api/proc-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ assert_matches = "1.3.0"
[features]
# Required for the doc tests
default = [ "std" ]
std = []
std = [ "blake2/std" ]
no-metadata-docs = []
frame-metadata = []
Loading

0 comments on commit bc98204

Please sign in to comment.