-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add no_std support #122
Add no_std support #122
Conversation
Also had to add a |
Features should never / can't ever be negative. So the |
How else would you enable |
Does it not work via a cfg dependency? It may actually not, because cargo has tons of bugs around features and targets. |
I was not aware of cfg dependencies, thanks for the tip. |
Hello , thanks for such a great work! I don’t have much time to review because I’m travelling now @CryZe is right, using negative features is not recommended. You can add a new feature ‘core’ for this though. Take a look to a cranelift for example https://github.com/CraneStation/cranelift/blob/master/lib/codegen/Cargo.toml |
This is just using different names: But sure, I can rename it, if you want me to? |
oh sorry havent had a look into the PR. Yes, that’s should work! I think I would vote for ‘core’ because I think i’ve seen it more often used in such situations |
use std::rc::Rc; | ||
use std::cell::Cell; | ||
use alloc::rc::Rc; | ||
use core::cell::Cell; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing we do in Cranelift is to remap core
to std
in the top-level lib.rs here so that most files can just use std::
. This obviously isn't necessary, but since we have some crates that support no_std and some that don't, it's nice to the code more consistent between the two.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would have made rebasing a lot nicer, too 🙃
But in Parity we use feature with name |
@fckt |
Only the float handling in I have filed a PR for If the PR to |
default = ["std"] | ||
# Disable for no_std support | ||
std = ["parity-wasm/std", "byteorder/std"] | ||
# Enable for no_std support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are those comments outdated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. They match the readme section about no_std
.
use alloc::rc::Rc; | ||
use core::u32; | ||
use core::ops::Range; | ||
use core::cmp; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
core imports might be grouped
I'm trying to get this branch working with a real embedded environment (Rux microkernel!), but so far, it still needs some changes, and I would hope we can fix them! First,
The second issue I'm facing is missing
I have a branch that's working for Rux microkernel's demo propose at https://github.com/sorpaas/wasmi/tree/jrakow-nostd. That branch also contains some further modifications that make it work with older Rust nightly versions, which I guess we don't need here. |
I had actually solved the float issues locally by depending on The remaining blocker is eira-fransham/nan-preserving-float#1, which is inactive. |
@jrakow Would you mind also fixing the |
@sorpaas I was just writing a response to that as a second comment: As for |
BTW, the Rust issue for float operations in libcore is rust-lang/rfcs#2505. |
@jrakow Thanks! I still need to test whether your solutions work for me regarding Another situation is that it looks like current floating point implementations actually depend on some extern functions (which I have not yet understood why, see this). One of the possible solutions is to add a feature flag to disable all floating points operations from compiling -- we don't need them in deterministic environments like blockchain virtual machines, so it might be a good feature to have. Anyway, the above looks not trivial so I might just get another PR if I figured out something (and will definitely fix |
After chatting with @Vurich in private we decided to embed |
Looks like the Travis cache is getting too big. |
Finally we merged it! Thanks for the great job, @jrakow ! |
* add default-enabled std feature * use parity-wasm/std feature only if std is enabled * drop dependency on std::io * use hashmap_core instead of std::collections::HashMap * disable std::error in no_std * core and alloc all the things * mention no_std in readme * add no_std feature and use hashmap_core only on no_std * rename the no_std feature to core * drop dependency on byteorder/std * simplify float impl macro * remove some trailing whitespace * use libm for float math in no_std * add note about no_std panics of libm to readme * Embed nan-preserving-float crate. * Add no_std check to the Travis CI config * add missing dev-dependency
This PR should contain no breaking changes.
std
feature, enabled by default and sync it withparity-wasm/std
std::io
alloc
std::error
forno_std
core
andalloc
everywhere and substitutingstd
if available.This is -- as far as I know -- the accepted way to support
no_std
(as mentioned in thealloc
RFC).no_std
should probably be added to the Travis configuration.Nom has a working
no_std
Travis: https://github.com/Geal/nom/blob/master/.travis.yml.