From 3b82da15dfe3bd3ff37cfb4f1e6edb63f523191c Mon Sep 17 00:00:00 2001 From: Julius Rakow Date: Sat, 25 Aug 2018 01:48:39 +0200 Subject: [PATCH] add no_std feature and use hashmap_core only on no_std --- Cargo.toml | 5 ++++- README.md | 9 ++++++--- src/imports.rs | 5 +++++ src/lib.rs | 1 + src/module.rs | 5 +++++ src/validation/mod.rs | 5 +++++ 6 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2d0b833..ff3f851 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/README.md b/README.md index e9c2c1f..9d29ee6 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/imports.rs b/src/imports.rs index 0ba8d2a..bb52eb4 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -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; diff --git a/src/lib.rs b/src/lib.rs index ecf600c..206c6e4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/module.rs b/src/module.rs index 94c2ec2..4718bc5 100644 --- a/src/module.rs +++ b/src/module.rs @@ -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; diff --git a/src/validation/mod.rs b/src/validation/mod.rs index 73794d8..fdb2d11 100644 --- a/src/validation/mod.rs +++ b/src/validation/mod.rs @@ -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,