add no_std feature and use hashmap_core only on no_std

This commit is contained in:
Julius Rakow 2018-08-25 01:48:39 +02:00
parent 3c75f65105
commit 3b82da15df
No known key found for this signature in database
GPG Key ID: 9AABD9B859435A93
6 changed files with 26 additions and 4 deletions

View File

@ -14,11 +14,14 @@ exclude = [ "/res/*", "/tests/*", "/fuzz/*", "/benches/*" ]
default = ["std"]
# Disable for no_std support
std = ["parity-wasm/std"]
# Enable for no_std support
# hashmap_core only works on no_std
no_std = ["hashmap_core"]
[dependencies]
parity-wasm = { version = "0.31", default-features = false }
byteorder = "1.0"
hashmap_core = "0.1.9"
hashmap_core = { version = "0.1.9", optional = true }
memory_units = "0.3.0"
nan-preserving-float = "0.1.0"

View File

@ -29,11 +29,14 @@ cargo test
# `no_std` support
This crate supports `no_std` environments.
If the `std` feature is disabled, `no_std` is supported.
Use like that:
Enable the `no_std` feature and disable default features:
```toml
[dependencies]
parity-wasm = { version = "0.31", default-features = false }
parity-wasm = {
version = "0.31",
default-features = false,
features = "no_std"
}
```
`no_std` requires the `core` and `alloc` libraries and a nightly compiler.

View File

@ -1,6 +1,11 @@
#[allow(unused_imports)]
use alloc::prelude::*;
#[cfg(feature = "std")]
use std::collections::HashMap;
#[cfg(not(feature = "std"))]
use hashmap_core::HashMap;
use global::GlobalRef;
use memory::MemoryRef;
use func::FuncRef;

View File

@ -119,6 +119,7 @@ extern crate assert_matches;
extern crate parity_wasm;
extern crate byteorder;
#[cfg(not(feature = "std"))]
extern crate hashmap_core;
extern crate memory_units as memory_units_crate;

View File

@ -5,7 +5,12 @@ use runner::check_function_args;
use Trap;
use core::cell::RefCell;
use core::fmt;
#[cfg(feature = "std")]
use std::collections::HashMap;
#[cfg(not(feature = "std"))]
use hashmap_core::HashMap;
use parity_wasm::elements::{External, InitExpr, Internal, Instruction, ResizableLimits, Type};
use {Module, Error, Signature, MemoryInstance, RuntimeValue, TableInstance};
use imports::ImportResolver;

View File

@ -3,7 +3,12 @@ use alloc::prelude::*;
#[cfg(feature = "std")]
use std::error;
use core::fmt;
#[cfg(feature = "std")]
use std::collections::HashSet;
#[cfg(not(feature = "std"))]
use hashmap_core::HashSet;
use parity_wasm::elements::{
BlockType, External, GlobalEntry, GlobalType, Internal, MemoryType, Module, Instruction,
ResizableLimits, TableType, ValueType, InitExpr, Type,