I have this hierarchy in my substrate parachain project:
my_parachain/
├── ...
├── runtime folder
└── runtime-common folder
Cargo.lock
Cargo.toml
The above runtime-common has some constants and types that are used in my pallet-bridge's mock.rs and tests.rs, and also in my runtime/src/lib.rs
inside the runtime-common folder:
src/
└── lib.rs
Cargo.toml
inside the runtime-common/src/lib.rs:
pub mod constants {
//use node_primitives::Balance;
pub type Balance = u128;//from substrate/bin/node/primitives
pub const MICRO_CFG: Balance = 1_000_000_000_000; // 10−6 0.000001
pub const MILLI_CFG: Balance = 1_000 * MICRO_CFG; // 10−3 0.001
pub const CENTI_CFG: Balance = 10 * MILLI_CFG; // 10−2 0.01
pub const CFG: Balance = 100 * CENTI_CFG;
pub const NATIVE_TOKEN_TRANSFER_FEE: Balance = 2000 * CFG;
pub const NFT_TOKEN_TRANSFER_FEE: Balance = 20 * CFG;
}
inside the runtime-common/Cargo.toml
[package]
name = "runtime-common"
version = "1.0.0"
authors = ["Centrifuge"]
edition = "2021"
license = "LGPL-3.0"
homepage = ""
repository = ""
[dependencies]
[features]
default = ["std"]
std = [
]
runtime-benchmarks = [
]
I can add my bridge-pallet, chainbridge, and runtime-common in runtime/Cargo.toml as dependencies:
pallet-bridge = { path = "../pallets/bridge", default-features = false }
chainbridge = { git = "https://github.com/centrifuge/chainbridge-substrate.git", default-features = false, branch = "polkadot-v0.9.23" }
runtime-common = { path = "../runtime-common", default-features = false }
then cargo check
and cargo build
can run fine.
But after adding these code inside the runtime/src/lib.rs:
pub use runtime_common::{
constants::{
CFG, NATIVE_TOKEN_TRANSFER_FEE, NFT_TOKEN_TRANSFER_FEE, Balance,
}
};
then I got these errors:
Compiling h-runtime v0.0.1 (/mnt/sda3/polkadot/1pchain-chainbridge/runtime)
error: failed to run custom build command for `h-runtime v0.0.1 (/mnt/sda3/polkadot/1pchain-chainbridge/runtime)`
Caused by:
process didn't exit successfully: `/mnt/sda3/polkadot/1pchain-chainbridge/target/debug/build/h-runtime-1e48817ae1228872/build-script-build` (exit status: 1)
--- stdout
Information that should be included in a bug report.
Executing build command: "rustup" "run" "nightly" "cargo" "rustc" "--target=wasm32-unknown-unknown" "--manifest-path=/mnt/sda3/polkadot/1pchain-chainbridge/target/debug/wbuild/h-runtime/Cargo.toml" "--color=always" "--profile" "release"
Using rustc version: rustc 1.63.0-nightly (dc80ca78b 2022-06-21)
--- stderr
warning: Patch `fc-db v2.0.0-dev (https://github.com/PNetwork/frontier?branch=patch-polkadot-v0.9.23#d7b30f9c)` was not used in the crate graph.
Patch `fc-mapping-sync v2.0.0-dev (https://github.com/PNetwork/frontier?branch=patch-polkadot-v0.9.23#d7b30f9c)` was not used in the crate graph.
Patch `fc-rpc v2.0.0-dev (https://github.com/PNetwork/frontier?branch=patch-polkadot-v0.9.23#d7b30f9c)` was not used in the crate graph.
Patch `fc-rpc-core v1.1.0-dev (https://github.com/PNetwork/frontier?branch=patch-polkadot-v0.9.23#d7b30f9c)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
warning: associated function is never used: `initialize`
--> /mnt/sda3/polkadot/1pchain-chainbridge/pallets/bridge/src/lib.rs:470:5
|
470 | fn initialize(
| ^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: `pallet-bridge` (lib) generated 1 warning
Compiling h-runtime v0.0.1 (/mnt/sda3/polkadot/1pchain-chainbridge/runtime)
error: duplicate lang item in crate `std` (which `runtime_common` depends on): `panic_impl`.
|
= note: the lang item is first defined in crate `sp_io` (which `frame_support` depends on)
= note: first definition in `sp_io` loaded from /mnt/sda3/polkadot/1pchain-chainbridge/target/debug/wbuild/h-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-8c2aafc76099389a.rmeta
= note: second definition in `std` loaded from /home/user2038/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd-4faf99cd6c5513da.rlib
error: duplicate lang item in crate `std` (which `runtime_common` depends on): `oom`.
|
= note: the lang item is first defined in crate `sp_io` (which `frame_support` depends on)
= note: first definition in `sp_io` loaded from /mnt/sda3/polkadot/1pchain-chainbridge/target/debug/wbuild/h-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-8c2aafc76099389a.rmeta
= note: second definition in `std` loaded from /home/user2038/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd-4faf99cd6c5513da.rlib
error: could not compile `h-runtime` due to 2 previous errors
I am aware of this post How to resolve duplicate lang item error?
I have default-features = false
in my other Cargo.toml.
but for this runtime-common, I have no dependencies.
how can I make std not enabled by default in my runtime-common ?