rust-web3 icon indicating copy to clipboard operation
rust-web3 copied to clipboard

support `no_std`

Open rphmeier opened this issue 8 years ago • 10 comments
trafficstars

rphmeier avatar Jan 23 '17 14:01 rphmeier

I would like to take a crack at this over the next few weeks, if possible. I eventually need to use this library in a Substrate runtime to have an Ethereum bridge to my chain.

@rphmeier @tomusdrw What do you think would be a good start to support this?

fubuloubu avatar Aug 13 '19 20:08 fubuloubu

@fubuloubu If your goal is to compile to WASM, I think that:

$ cargo check --target wasm32-unknown-unknown --no-default-features

would be a good starting point. Then fixing dependencies one-by-one to make sure they compile when targeting wasm (i.e. avoid threads, io, etc).

tomusdrw avatar Aug 13 '19 21:08 tomusdrw

Oh, great tip! Thanks!

I have a smaller library to upgrade first, so this will get me there eventually.

fubuloubu avatar Aug 13 '19 22:08 fubuloubu

@tomusdrw would it be okay to upgrade all uses of HashMap to use BTreeMap instead?


Edit: I'm working through the error list of doing this upgrade, down to some 36 errors from 300+, so making good progress!

fubuloubu avatar Aug 14 '19 04:08 fubuloubu

We may also have to make a decision on what functionality we want to feature-gate to std only. For instance, we almost definitely want to leave the transport traits, but the implementations for WebSockets, IPC, and http almost definitely require std.

rphmeier avatar Aug 14 '19 09:08 rphmeier

I just re-read that you want to use it inside substrate runtime. This will cause additional issues and require no_std feature and depending on core/alloc stuff.

Switching to BTreeMap imho should be feature-gated as well, it can have pretty big performance impact.

tomusdrw avatar Aug 14 '19 10:08 tomusdrw

Cool, well I'll see if I can get it working in a branch and will maybe submit a PR to figure out how to handle gating with no_std. Sound like a good plan?

fubuloubu avatar Aug 14 '19 12:08 fubuloubu

The other big issue I had is std::error::Error/std::io::Error. Not sure how best to handle this, but it doesn't look trivial to swap out from my limited knowledge.

fubuloubu avatar Aug 14 '19 13:08 fubuloubu

I've been thinking about this a bit more, and it probably makes more sense if just the Web3-specific types are available as no_std, perhaps as a separate crate.

A great example of this is Bytes, which I am using in the https://github.com/ethpm/ethpm-rs repo to serialize/deserialize ethPM packages. Other types would be very helpful as well.

fubuloubu avatar Nov 19 '19 20:11 fubuloubu

Any progress on no_std support?

ioannist avatar May 27 '22 13:05 ioannist