Update no_std support.

This `no_std` support isn't complete though, as some dependencies
don't support it.
This commit is contained in:
Dan Gohman
2019-01-03 14:00:03 -08:00
parent f6c2fe7d2d
commit ca2fdc5ccb
21 changed files with 81 additions and 70 deletions

View File

@@ -17,11 +17,12 @@ cranelift-wasm = "0.26.0"
cast = { version = "0.2.2", default-features = false }
failure = { version = "0.1.3", default-features = false }
failure_derive = { version = "0.1.3", default-features = false }
hashmap_core = { version = "0.1.9", optional = true }
[features]
default = ["std"]
std = ["cranelift-codegen/std", "cranelift-wasm/std"]
core = ["cranelift-codegen/core", "cranelift-wasm/core"]
core = ["hashmap_core", "cranelift-codegen/core", "cranelift-wasm/core"]
[badges]
maintenance = { status = "experimental" }

View File

@@ -2,6 +2,7 @@ use crate::module::{MemoryPlan, MemoryStyle, Module, TableStyle};
use crate::vmoffsets::VMOffsets;
use crate::WASM_PAGE_SIZE;
use cast;
use core::clone::Clone;
use cranelift_codegen::cursor::FuncCursor;
use cranelift_codegen::ir;
use cranelift_codegen::ir::condcodes::*;
@@ -16,7 +17,6 @@ use cranelift_wasm::{
self, FuncIndex, GlobalIndex, GlobalVariable, MemoryIndex, SignatureIndex, TableIndex,
WasmResult,
};
use std::clone::Clone;
use std::vec::Vec;
/// Compute an `ir::ExternalName` for a given wasm function index.

View File

@@ -24,14 +24,23 @@
clippy::use_self
)
)]
#![cfg_attr(not(feature = "std"), no_std)]
#![no_std]
#![cfg_attr(not(feature = "std"), feature(alloc))]
use cranelift_wasm;
#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc;
extern crate alloc as std;
#[cfg(feature = "std")]
#[macro_use]
extern crate std;
#[cfg(not(feature = "std"))]
use hashmap_core::HashMap;
#[cfg(feature = "std")]
use std::collections::HashMap;
use cast;
use cranelift_wasm;
use failure;
#[macro_use]
extern crate failure_derive;
@@ -63,10 +72,3 @@ pub const WASM_PAGE_SIZE: u32 = 0x10000;
/// The number of pages we can have before we run out of byte index space.
pub const WASM_MAX_PAGES: u32 = 0x10000;
#[cfg(not(feature = "std"))]
mod std {
pub use alloc::{string, vec};
pub use core::*;
pub use core::{i32, str, u32};
}

View File

@@ -1,5 +1,6 @@
//! Data structures for representing decoded wasm modules.
use super::HashMap;
use crate::tunables::Tunables;
use cranelift_codegen::ir;
use cranelift_entity::{EntityRef, PrimaryMap};
@@ -7,7 +8,6 @@ use cranelift_wasm::{
DefinedFuncIndex, DefinedGlobalIndex, DefinedMemoryIndex, DefinedTableIndex, FuncIndex, Global,
GlobalIndex, Memory, MemoryIndex, SignatureIndex, Table, TableIndex,
};
use std::collections::HashMap;
use std::string::String;
use std::vec::Vec;

View File

@@ -1,6 +1,7 @@
use crate::func_environ::FuncEnvironment;
use crate::module::{Export, MemoryPlan, Module, TableElements, TablePlan};
use crate::tunables::Tunables;
use core::clone::Clone;
use cranelift_codegen::ir;
use cranelift_codegen::ir::{AbiParam, ArgumentPurpose};
use cranelift_codegen::isa::TargetFrontendConfig;
@@ -9,7 +10,6 @@ use cranelift_wasm::{
self, translate_module, DefinedFuncIndex, FuncIndex, Global, GlobalIndex, Memory, MemoryIndex,
SignatureIndex, Table, TableIndex, WasmResult,
};
use std::clone::Clone;
use std::string::String;
use std::vec::Vec;