What's different between these two features style?

[features]
default = ["std"]

std = [
	"substrate-std",
	"darwinia-std",
	"crates-std",
]

crates-std    = [
	"codec/std",
	"serde",
]
darwinia-std  = [
	"darwinia-balances/std",
	"darwinia-balances-rpc-runtime-api/std",
	"darwinia-claims/std",
	"darwinia-elections-phragmen/std",
	"darwinia-ethereum-backing/std",
	"darwinia-ethereum-linear-relay/std",
	"darwinia-ethereum-offchain/std",
	"darwinia-ethereum-relay/std",
	"darwinia-header-mmr/std",
	"darwinia-header-mmr-rpc-runtime-api/std",
	"darwinia-relayer-game/std",
	"darwinia-staking/std",
	"darwinia-staking-rpc-runtime-api/std",
	"darwinia-support/std",
	"darwinia-treasury/std",
	"ethereum-primitives/std",
]
substrate-std = [
	"frame-executive/std",
	"frame-support/std",
	"frame-system/std",
	"frame-system-rpc-runtime-api/std",
	"pallet-authority-discovery/std",
	"pallet-authorship/std",
	"pallet-babe/std",
	"pallet-collective/std",
	"pallet-finality-tracker/std",
	"pallet-grandpa/std",
	"pallet-im-online/std",
	"pallet-membership/std",
	"pallet-offences/std",
	"pallet-randomness-collective-flip/std",
	"pallet-session/std",
	"pallet-sudo/std",
	"pallet-timestamp/std",
	"pallet-transaction-payment/std",
	"pallet-transaction-payment-rpc-runtime-api/std",
	"sp-api/std",
	"sp-application-crypto/std",
	"sp-authority-discovery/std",
	"sp-block-builder/std",
	"sp-consensus-babe/std",
	"sp-core/std",
	"sp-inherents/std",
	"sp-io/std",
	"sp-offchain/std",
	"sp-runtime/std",
	"sp-session/std",
	"sp-staking/std",
	"sp-std/std",
	"sp-transaction-pool/std",
	"sp-version/std",
]
[features]
default = ["std"]

std = [
	"codec/std",
	"serde",
	"darwinia-balances/std",
	"darwinia-balances-rpc-runtime-api/std",
	"darwinia-claims/std",
	"darwinia-elections-phragmen/std",
	"darwinia-ethereum-backing/std",
	"darwinia-ethereum-linear-relay/std",
	"darwinia-ethereum-offchain/std",
	"darwinia-ethereum-relay/std",
	"darwinia-header-mmr/std",
	"darwinia-header-mmr-rpc-runtime-api/std",
	"darwinia-relayer-game/std",
	"darwinia-staking/std",
	"darwinia-staking-rpc-runtime-api/std",
	"darwinia-support/std",
	"darwinia-treasury/std",
	"ethereum-primitives/std",
	"frame-executive/std",
	"frame-support/std",
	"frame-system/std",
	"frame-system-rpc-runtime-api/std",
	"pallet-authority-discovery/std",
	"pallet-authorship/std",
	"pallet-babe/std",
	"pallet-collective/std",
	"pallet-finality-tracker/std",
	"pallet-grandpa/std",
	"pallet-im-online/std",
	"pallet-membership/std",
	"pallet-offences/std",
	"pallet-randomness-collective-flip/std",
	"pallet-session/std",
	"pallet-sudo/std",
	"pallet-timestamp/std",
	"pallet-transaction-payment/std",
	"pallet-transaction-payment-rpc-runtime-api/std",
	"sp-api/std",
	"sp-application-crypto/std",
	"sp-authority-discovery/std",
	"sp-block-builder/std",
	"sp-consensus-babe/std",
	"sp-core/std",
	"sp-inherents/std",
	"sp-io/std",
	"sp-offchain/std",
	"sp-runtime/std",
	"sp-session/std",
	"sp-staking/std",
	"sp-std/std",
	"sp-transaction-pool/std",
	"sp-version/std",
]

The first one can't pass the compile. I don't know why.

I got:

  error: cannot find macro `vec` in this scope
    --> /root/Documents/darwinia-network/common/bin/node-template/runtime/src/lib.rs:66:18
     |
  66 |                 samples.push(vec![samples.last().unwrap().last().unwrap() - 1]);
     | 

It seems some std missing. But I think these two features are the same.

darwinia-network/common doesn't have std enabled.

The two styles of features should be equivalent. Double-check that you haven't missed anything.

What else can I miss?

I change the first style to the second, then it passed.

All the other things are same.

Without seeing all of the Cargo manifests, we can't tell for sure. But to figure out the problem, you can work backwards. First, figure out what crate is responsible for enabling features in the crate with the error message. Then look to see what features are enabled for that crate. If it is not getting the right features, continue by seeing which crate is responsible for that, and so on.

Running cargo build -v might help verify which features are enabled for which crates.

Not only my repo, the substrate official repo also got this problem. So I'm pretty sure I didn't missing any std or sub-feature.

Hi, can you try it?

  1. git clone git@github.com:paritytech/substrate.git
  2. cd bin/node-template/runtime
  3. cargo b everything works good
  4. modify its toml file like https://github.com/paritytech/substrate/issues/6898
  5. cargo b under the bin/node-template/runtime

maybe you need wasm32-unknown-unknown for this compile

Then you'll get:

cannot find function `to_substrate_wasm_fn_return_value` in crate `self::sp_api_hidden_includes_IMPL_RUNTIME_APIS::sp_api`

Yes, I can reproduce that problem. (For anyone else playing along at home, I had to first reset the repository to 86f85949329f0b27b56c41cd02ae30413e62fa5e for it to work with the changes from the issue above.)

It looks like this happens because Parity's wasm-builder parses the [features] section itself, and has a hard-coded rule to exclude the "std" list but not any other lists. So any project that uses wasm-builder must use the expected name and structure for features that depend on libstd:

https://github.com/paritytech/substrate/blob/master/utils/wasm-builder/src/wasm_project.rs#L324-L349

4 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.