2

I am currently facing this Error:

  Using rustc version: rustc 1.62.0-nightly (e85edd9a8 2022-04-28)

     Compiling frame-support v4.0.0-dev (https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.19#174735ea)
  error: cannot find macro `vec` in this scope
    --> /home/creestl/.cargo/git/checkouts/substrate-7e08433d4c370a21/174735e/frame/support/src/traits/storage.rs:77:17
     |
  77 |         let mut res = vec![];
     |                       ^^^
     |
     = note: consider importing one of these items:
             codec::alloc::vec
             crate::sp_std::vec
             scale_info::prelude::vec
             sp_std::vec

(it says that std macro is used when building for no-std)
The frame-support import in my Cargo.toml looks like this:

frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.19" }

***snip***

[features]
default = ["std"]
std = [
    "parity-scale-codec/std",
    "scale-info/std",
    "frame-support/std",
    "frame-system/std",
    "frame-benchmarking/std",
]

So I did not modify any code of that pallet. It is not some kind of custom pallet. This code above is from substrate-node-template.

To build a node I use cargo build --release command.

I know that runtime builds in no-std. But I haven't had such error with that pallet before.

[UPD] I get the same error with finality-grandpa as well

error: cannot find macro `format` in this scope
    --> /home/creestl/.cargo/git/checkouts/substrate-7e08433d4c370a21/174735e/primitives/finality-grandpa/src/lib.rs:43:2
     |
  43 |     app_crypto!(ed25519, GRANDPA);
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: consider importing one of these items:
             alloc::format
             scale_info::prelude::format
     = note: this error originates in the macro `$crate::app_crypto_public_common_if_std` (in Nightly builds, run with -Z macro-backtrace for more info)

Please assist. I've been trying to fix this for several days now.

5
  • What did you modify about your project? Did you make sure to add the std feature to any imported crates?
    – Shawn Tabrizi
    Apr 30 at 12:55
  • Basically, I'm trying to implement PoW (smth like Kulupu's but more simple) on top of node template. I've added primitives, difficulty pallets and one more pallet with my custom Sha256 PoW logic. I doublechecked that each crate's std is listed in [features]
    – CREESTL
    Apr 30 at 14:03
  • The error here is almost certainly due to some missing feature stuff. I would start with the base node-template, and make changes one by one, checking each time it compiles.
    – Shawn Tabrizi
    Apr 30 at 14:09
  • That would be the best solution, but it would take me too much time to go back to the start and do the same steps once again:( That's why I'm trying to fix it the other way.
    – CREESTL
    Apr 30 at 14:14
  • 1
    Strange, I am getting the same error: cannot find macro 'format' in this scope when doing a cargo check in my runtime folder. this started after I added a new pallet to my runtime, and updated the versions in the cargo.toml in the runtime. definitely a dependency problem, still trying to figure it out..... May 2 at 6:27

1 Answer 1

2

I fixed it. First let me explain how I got this error. I cloned Kulupu's difficulty pallet. And it required Kulupu's primitives as one of the dependencies. So I cloned them as well so the Cargo.toml dependencies section of my primitives crate looked like this:

[dependencies]
parity-scale-codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.19" }
sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.19" } 

But building the runtime failed with this wasm32 kind of error. First to fix this error I added the following to the Cargo.toml of my primitives crate:

getrandom = {version = "0.2", features= ["js"] }

So it's dependencies section looked like this:

[dependencies]
parity-scale-codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.19" }
sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.19" }
getrandom = {version = "0.2", features= ["js"] }

Then I tried to build runtime again. At this point I got the std macros bug described in my question above.

The solution was pretty simple (even though I spent a week figuring it out):

  • Deleted all unused dependencies from the Cargo.toml of my primitives crate. That fixed the wasm32 error and thus made the getrandom = {version = "0.2", features= ["js"] } line useless as well. To be more specific, the sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.19" } line was causing some inner conflict. So I could have deleted only this one, but I decided to get rid of everything that was unused. After that the runtime built fine. Final contents of Cargo.toml of my primitives crate:
***snip***

[dependencies]
sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.19" }

[features]
default = ["std"]
std = [
    "sp-core/std", 
]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.