7

I'm using an extern crate in my Substrate 1.0 runtime module (based on node-template) which gives a compile error of

duplicate lang item in crate 'std' (which 'myexternalcrate' depends on): 'panic_impl'.

= note: first defined in crate `sr_io` (which `node_template_runtime` depends on).

If I understand the message correctly then I think this might be a common problem if developers want to include external crates that rely on std features which already implemented in sr-io, but I'm not sure if that is correct.

I have seen this issue here, which appears to have been fixed in sr-io but that does not appear to be the cause here.

Is their another approach to resolve this?

EDIT: Adding in changes to Cargo.toml We are attempting to pull in crate called nacl

[dependencies]
nacl = {version = "0.3.0", default-features = false}

Added in lib.rs

extern crate nacl;

in the runtime module

use nacl::public_box::*;
T9b
  • 3,312
  • 5
  • 31
  • 50
  • The issue is most certainly something related to `std`. See [this](https://github.com/shawntabrizi/substrate-module-template/blob/master/HOWTO.md#forgetting-cfg_attr-for-no_std) and [this](https://github.com/shawntabrizi/substrate-module-template/blob/master/HOWTO.md#adding-new-dependencies) – Shawn Tabrizi Dec 18 '19 at 09:35
  • In general, can you share the changes you made in the `cargo.toml` file when importing the external crate? – Shawn Tabrizi Dec 18 '19 at 09:37
  • Added more info. – T9b Dec 18 '19 at 09:43

2 Answers2

6

The crate you are trying to use (rust-nacl) does not support no_std, and thus cannot be used within the Substrate runtime environment.

The options are:

  • Find another crate which does support no_std and has similar functionality: https://crates.io/keywords/no_std
  • Update/Write a crate to support no_std (which may not be that bad depending on the crate).
Shawn Tabrizi
  • 12,206
  • 1
  • 38
  • 69
0

To clarify Shawn Tabrizi's answer above... To use another crate that supports no_std:

imported_crate = { git = "...", default-features = false, branch = "..." }

OR to write a crate to support no_std :

#![cfg_attr(not(feature = "std"), no_std)]

more about no_std: https://substrate.stackexchange.com/questions/1307/how-to-resolve-duplicate-lang-item-error

Russo
  • 2,186
  • 2
  • 26
  • 42