Skip to content
This repository has been archived by the owner on Sep 19, 2019. It is now read-only.

Errors when using ethereum-types in no_std context #36

Closed
moriaab opened this issue Jun 10, 2018 · 8 comments
Closed

Errors when using ethereum-types in no_std context #36

moriaab opened this issue Jun 10, 2018 · 8 comments

Comments

@moriaab
Copy link

moriaab commented Jun 10, 2018

When trying to use ethereum-types in no_std context:
ethereum-types = { version = "0.3", default-features = false }
get the following errors:

error: cannot find macro `format!` in this scope
  --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/ethereum-types-0.3.2/src/hash.rs:72:1
   |
72 | construct_hash!(H32, 4);
   | ^^^^^^^^^^^^^^^^^^^^^^^^
   |
   
error[E0412]: cannot find type `String` in this scope
  --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/ethereum-types-0.3.2/src/hash.rs:73:1
   |
73 | construct_hash!(H64, 8);
   | ^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
@niklasad1
Copy link
Member

Ok, I haven't tested but I think we need to explictly use alloc crate to use heap allocated things such as String

I guess we need something like

#[cfg(not(feature = "std"))] {
mod no_std {
  extern crate alloc;
  pub use alloc::string::{String, ToString};
  pub use alloc::vec::Vec;
}

@moriaab
Copy link
Author

moriaab commented Jun 11, 2018

Thank you, but can you please give me an example how should I use this?

@tomusdrw
Copy link
Contributor

@niklasad1 Do we actually need the function causing issues in no_std? Maybe let's just remove it in that context.

@niklasad1
Copy link
Member

@tomusdrw Good question, I will check it out!

But it compiles using alloc and exporting String and ToOwned but I was unlucky before missed to disable the default-features so I accidental compiled both std and no_std for ethereum_types lol!

@niklasad1
Copy link
Member

@tomusdrw

So I have looked a bit at this and the problem is that ethbloom requires std via its features and compiles fixed_hash as std and that cases all these errors.

So, the easiest way to fix this would be

[target.'cfg(not(feature = "std"))'.dependencies]
ethbloom = { path = "../ethbloom", version = "0.5.0", default-features = false }

[target.'cfg(feature = "std")'.dependencies]
ethbloom = { path = "../ethbloom", version = "0.5.0"}

But, ofcourse this doesn't work yet /cc rust-lang/cargo#2524

So, we need to refactor the features in ethbloom to solve this otherwise we will end up with both std and no-std!

@tomusdrw
Copy link
Contributor

why not include ethbloom without default features always? and then relay the same features on ethereum-types (which is already done anyway I believe; so ethereum-types/std implies ethbloom/std)

@niklasad1
Copy link
Member

Yeah, you are right that's clever submitting PR soon!

@niklasad1
Copy link
Member

ethereum-types 0.4 is now released which solved this issue!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants