Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Pallet without try-runtime feature flag produces a compiler warning #5092

Closed
shawntabrizi opened this issue Jul 22, 2024 · 1 comment · Fixed by #5099
Closed

Pallet without try-runtime feature flag produces a compiler warning #5092

shawntabrizi opened this issue Jul 22, 2024 · 1 comment · Fixed by #5099

Comments

@shawntabrizi
Copy link
Member

Ran into this while making some tutorial content:

warning: unexpected `cfg` condition value: `try-runtime`
  --> src/lib.rs:11:12
   |
11 |     #[pallet::pallet]
   |               ^^^^^^
   |
   = note: expected values for `feature` are: `default`, `std`
   = help: consider adding `try-runtime` as a feature in `Cargo.toml`
   = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
   = note: `#[warn(unexpected_cfgs)]` on by default

warning: `pallet-kitties` (lib) generated 1 warning

This is reproducible by taking a pallet without try-runtime feature in the Cargo.toml, and then running:

cargo +nightly build

The solution can be to add try-runtime = [] in the features, but probably better this is fixed within the macros and pallet code.

@gui1117
Copy link
Contributor

gui1117 commented Jul 22, 2024

I'm on it.

Also we could introduce 2 new attribute macros in frame-support:

  • #[cfg_feature_try_runtime]
  • and #[cfg_feature_runtime_benchmarks].

User could use them to have some code discarded/included depending on whether frame-support has try-runtime or runtime-benchmarks features.

This would allow people not to have to bother adding try-runtime nor runtime-benchmarks in their Cargo.toml for their pallet.
And avoid some miss when configuring the runtime as well.

If I'm correct runtime crate would only need:

runtime-benchmarks = [
	"frame-support/runtime-benchmarks",
]
try-runtime = [
	"frame-support/try-runtime",
]

github-merge-queue bot pushed a commit that referenced this issue Jul 24, 2024
…port doesn't have try-runtime. (#5099)

Status: Ready for review

Fix #5092

Introduce a new macro in frame-support which discard content if
`try-runtime` is not enabled.

Use this macro inside `frame-support-procedural` to generate code only
when `frame-support` is compiled with `try-runtime`.

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
TarekkMA pushed a commit to moonbeam-foundation/polkadot-sdk that referenced this issue Aug 2, 2024
…port doesn't have try-runtime. (paritytech#5099)

Status: Ready for review

Fix paritytech#5092

Introduce a new macro in frame-support which discard content if
`try-runtime` is not enabled.

Use this macro inside `frame-support-procedural` to generate code only
when `frame-support` is compiled with `try-runtime`.

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
2 participants