From 1d21a77bccf2da6bbd36ff6c353dae2b40ac1046 Mon Sep 17 00:00:00 2001 From: PG Herveou Date: Fri, 15 Mar 2024 12:04:13 +0100 Subject: [PATCH] Use zepter to format Cargo.toml files (#2161) See /~https://github.com/paritytech/polkadot-sdk/blob/master/substrate/docs/STYLE_GUIDE.md?plain=1#L148-L172 /~https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/CONTRIBUTING.md?plain=1#L146 --- .config/zepter.yaml | 40 ++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 1 + CONTRIBUTING.md | 3 +++ Cargo.lock | 3 +++ crates/allocator/Cargo.toml | 4 ++-- crates/e2e/Cargo.toml | 17 ++++++++------ crates/engine/Cargo.toml | 7 ++---- crates/env/Cargo.toml | 38 ++++++++++++++++-------------- crates/ink/Cargo.toml | 24 +++++++++---------- crates/ink/codegen/Cargo.toml | 11 +++++---- crates/ink/ir/Cargo.toml | 8 ++++--- crates/ink/macro/Cargo.toml | 10 ++++---- crates/metadata/Cargo.toml | 14 +++++------ crates/prelude/Cargo.toml | 2 +- crates/primitives/Cargo.toml | 14 ++++++----- crates/storage/Cargo.toml | 18 +++++++------- crates/storage/traits/Cargo.toml | 12 +++++----- 17 files changed, 140 insertions(+), 86 deletions(-) create mode 100644 .config/zepter.yaml diff --git a/.config/zepter.yaml b/.config/zepter.yaml new file mode 100644 index 00000000000..c253a9e0d00 --- /dev/null +++ b/.config/zepter.yaml @@ -0,0 +1,40 @@ +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=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', + # 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', + # Auxiliary flags: + '--offline', + '--locked', + '--show-path', + '--quiet', + ] + # Same as `check`, but with the `--fix` flag. + default: + - [ $check.0, '--fix' ] + +# Will be displayed when any workflow fails: +help: + text: | + Ink! 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" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1baf31fa7ac..00a1fe2e285 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -102,6 +102,7 @@ jobs: - name: Check Formatting run: | + zepter run check cargo +nightly fmt --all -- --check # For the UI tests we need to disable the license check cargo +nightly fmt --all -- --check ./crates/ink/tests/ui/contract/{pass,fail}/*.rs diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 516d40e75f7..a596cbb6bdb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -65,6 +65,9 @@ Verify the following locally, otherwise the CI will fail: - `cargo +nightly fmt --all` 1. Is `clippy` happy with it? - `cargo clippy --all-targets --all-features` -- -D warnings; +1. Are Cargo.toml files formatted properly? + * `cargo install zepter` + * `zepter run` 1. Does the code still compile? - `cargo check --all-features` 1. Do all the integration tests/examples still compile? diff --git a/Cargo.lock b/Cargo.lock index 51134a593e3..c06e334c97a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4036,11 +4036,14 @@ source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "085a71440a945fae1bc6077fd40bdf1780a7e31747b86b2012bba18b18f0d6ef" dependencies = [ "bounded-collections", + "frame-benchmarking", "frame-support", "frame-system", "log", + "pallet-balances", "parity-scale-codec", "scale-info", + "serde", "sp-core", "sp-io", "sp-runtime", diff --git a/crates/allocator/Cargo.toml b/crates/allocator/Cargo.toml index a63e847a670..fa73d843215 100644 --- a/crates/allocator/Cargo.toml +++ b/crates/allocator/Cargo.toml @@ -22,7 +22,7 @@ quickcheck = { workspace = true } quickcheck_macros = { workspace = true } [features] -default = ["std"] +default = [ "std" ] std = [] -ink-fuzz-tests = ["std"] +ink-fuzz-tests = [ "std" ] no-allocator = [] diff --git a/crates/e2e/Cargo.toml b/crates/e2e/Cargo.toml index f71a6725ac9..7f3a921b6db 100644 --- a/crates/e2e/Cargo.toml +++ b/crates/e2e/Cargo.toml @@ -53,21 +53,24 @@ sp-weights = { workspace = true } scale-info = { workspace = true, features = ["derive"] } [features] -default = ["std"] +default = [ "std" ] std = [ "impl-serde/std", + "ink_e2e_macro/std", "pallet-contracts/std", - "scale/std", "scale-info/std", + "scale/std", "serde/std", "sp-core/std", "sp-runtime/std", "sp-weights/std", - "ink_e2e_macro/std" + "drink?/std", + "frame-support/std", + "pallet-contracts-mock-network?/std" ] drink = [ - "dep:drink", - "subxt-metadata", - "pallet-contracts-mock-network", - "ink_e2e_macro/drink", + "dep:drink", + "ink_e2e_macro/drink", + "pallet-contracts-mock-network", + "subxt-metadata", ] diff --git a/crates/engine/Cargo.toml b/crates/engine/Cargo.toml index 7bf3c1886bd..0109ff2e7ca 100644 --- a/crates/engine/Cargo.toml +++ b/crates/engine/Cargo.toml @@ -28,8 +28,5 @@ blake2 = { workspace = true } secp256k1 = { workspace = true, features = ["recovery", "global-context"], optional = true } [features] -default = ["std"] -std = [ - "scale/std", - "secp256k1" -] +default = [ "std" ] +std = [ "ink_primitives/std", "scale/std", "secp256k1" ] diff --git a/crates/env/Cargo.toml b/crates/env/Cargo.toml index b1de7f8a426..289b96612dd 100644 --- a/crates/env/Cargo.toml +++ b/crates/env/Cargo.toml @@ -59,28 +59,30 @@ scale-info = { workspace = true, features = ["derive"], optional = true } ink = { path = "../ink" } [features] -default = ["std"] +default = [ "std" ] std = [ - "ink_allocator/std", - "ink_prelude/std", - "ink_primitives/std", - "ink_storage_traits/std", - "ink_engine/std", - "scale/std", - "scale-decode", - "scale-encode", - "scale-info/std", - "secp256k1", - "schnorrkel", - "num-traits/std", - # Enables hashing crates for off-chain environment. - "sha2", - "sha3", - "blake2", + "blake2", + "ink_allocator/std", + "ink_engine/std", + "ink_prelude/std", + "ink_primitives/std", + "ink_storage_traits/std", + "num-traits/std", + "scale-decode", + "scale-encode", + "scale-info/std", + "scale/std", + "schnorrkel", + "secp256k1", + # Enables hashing crates for off-chain environment. + "sha2", + "sha3", + "scale-decode?/std", + "scale-encode?/std" ] # Enable contract debug messages via `debug_print!` and `debug_println!`. ink-debug = [] # Disable the ink! provided global memory allocator. -no-allocator = ["ink_allocator/no-allocator"] +no-allocator = [ "ink_allocator/no-allocator" ] diff --git a/crates/ink/Cargo.toml b/crates/ink/Cargo.toml index 7d863739339..f2790b07147 100644 --- a/crates/ink/Cargo.toml +++ b/crates/ink/Cargo.toml @@ -35,23 +35,21 @@ trybuild = { workspace = true, features = ["diff"] } [features] -default = ["std"] +default = [ "std" ] std = [ - "ink_metadata/std", - "ink_prelude/std", - "ink_primitives/std", - "ink_env/std", - "ink_storage/std", - "ink_macro/std", - "scale/std", - "scale-info/std", + "ink_env/std", + "ink_macro/std", + "ink_metadata/std", + "ink_prelude/std", + "ink_primitives/std", + "ink_storage/std", + "scale-info/std", + "scale/std", ] # Enable contract debug messages via `debug_print!` and `debug_println!`. -ink-debug = [ - "ink_env/ink-debug", -] +ink-debug = [ "ink_env/ink-debug" ] show-codegen-docs = [] # Disable the ink! provided global memory allocator. -no-allocator = ["ink_env/no-allocator"] +no-allocator = [ "ink_env/no-allocator" ] diff --git a/crates/ink/codegen/Cargo.toml b/crates/ink/codegen/Cargo.toml index 7d4437dfe96..62e3269cb33 100644 --- a/crates/ink/codegen/Cargo.toml +++ b/crates/ink/codegen/Cargo.toml @@ -35,9 +35,12 @@ serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } [features] -default = ["std"] +default = [ "std" ] std = [ - "itertools/use_std", - "either/use_std", - "ir/std" + "either/use_std", + "ink_primitives/std", + "ir/std", + "itertools/use_std", + "scale/std", + "serde/std" ] diff --git a/crates/ink/ir/Cargo.toml b/crates/ink/ir/Cargo.toml index 43624737ae0..66ff6fa00e6 100644 --- a/crates/ink/ir/Cargo.toml +++ b/crates/ink/ir/Cargo.toml @@ -28,8 +28,10 @@ impl-serde = { workspace = true } ink_prelude = { workspace = true } [features] -default = ["std"] +default = [ "std" ] std = [ - "itertools/use_std", - "either/use_std", + "either/use_std", + "ink_prelude/std", + "itertools/use_std", + "impl-serde/std" ] diff --git a/crates/ink/macro/Cargo.toml b/crates/ink/macro/Cargo.toml index a5ccdac5134..08692ddbe79 100644 --- a/crates/ink/macro/Cargo.toml +++ b/crates/ink/macro/Cargo.toml @@ -38,9 +38,11 @@ name = "ink_macro" proc-macro = true [features] -default = ["std"] +default = [ "std" ] std = [ - "scale/std", - "ink_ir/std", - "ink_primitives/std", + "ink_codegen/std", + "ink_ir/std", + "ink_primitives/std", + "scale/std", + "scale-info/std" ] diff --git a/crates/metadata/Cargo.toml b/crates/metadata/Cargo.toml index 9036f079758..4a4723c1c28 100644 --- a/crates/metadata/Cargo.toml +++ b/crates/metadata/Cargo.toml @@ -31,14 +31,12 @@ pretty_assertions = "1" serde_json = "1" [features] -default = [ - "std", - "derive", -] +default = [ "derive", "std" ] std = [ - "ink_prelude/std", - "ink_primitives/std", - "serde/std", - "scale-info/std", + "ink_prelude/std", + "ink_primitives/std", + "scale-info/std", + "serde/std", + "scale/std" ] derive = [] diff --git a/crates/prelude/Cargo.toml b/crates/prelude/Cargo.toml index 563abd92bbd..dd7c53e5506 100644 --- a/crates/prelude/Cargo.toml +++ b/crates/prelude/Cargo.toml @@ -18,5 +18,5 @@ include = ["/Cargo.toml", "src/**/*.rs", "/README.md", "/LICENSE"] cfg-if = { workspace = true } [features] -default = ["std"] +default = [ "std" ] std = [] diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index 60cf753407e..e167f74b11c 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -24,11 +24,13 @@ scale-info = { workspace = true, features = ["derive"], optional = true } xxhash-rust = { workspace = true, features = ["const_xxh32"] } [features] -default = ["std"] +default = [ "std" ] std = [ - "ink_prelude/std", - "scale/std", - "scale-decode", - "scale-encode", - "scale-info/std", + "ink_prelude/std", + "scale-decode", + "scale-encode", + "scale-info/std", + "scale/std", + "scale-decode?/std", + "scale-encode?/std" ] diff --git a/crates/storage/Cargo.toml b/crates/storage/Cargo.toml index c04d4cb066b..5cd12048c73 100644 --- a/crates/storage/Cargo.toml +++ b/crates/storage/Cargo.toml @@ -36,14 +36,14 @@ itertools = { workspace = true, default-features = true } ink = { path = "../ink"} [features] -default = ["std"] +default = [ "std" ] std = [ - "ink_metadata/std", - "ink_env/std", - "ink_prelude/std", - "ink_primitives/std", - "ink_storage_traits/std", - "scale/std", - "scale-info/std", + "ink_env/std", + "ink_metadata/std", + "ink_prelude/std", + "ink_primitives/std", + "ink_storage_traits/std", + "scale-info/std", + "scale/std", ] -ink-fuzz-tests = ["std"] +ink-fuzz-tests = [ "std" ] diff --git a/crates/storage/traits/Cargo.toml b/crates/storage/traits/Cargo.toml index 98694e61500..906554d61da 100644 --- a/crates/storage/traits/Cargo.toml +++ b/crates/storage/traits/Cargo.toml @@ -25,11 +25,11 @@ scale-info = { workspace = true, features = ["derive"], optional = true } paste = { workspace = true } [features] -default = ["std"] +default = [ "std" ] std = [ - "ink_metadata/std", - "ink_primitives/std", - "ink_prelude/std", - "scale/std", - "scale-info/std", + "ink_metadata/std", + "ink_prelude/std", + "ink_primitives/std", + "scale-info/std", + "scale/std", ]