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

@@ -2,11 +2,11 @@
use crate::compiler::Compiler;
use crate::instantiate::SetupError;
use core::cmp::max;
use core::{fmt, mem, ptr, slice};
use cranelift_codegen::ir;
use std::cmp::max;
use std::string::String;
use std::vec::Vec;
use std::{fmt, mem, ptr, slice};
use wasmtime_runtime::{wasmtime_call_trampoline, Export, Instance};
/// A runtime value.

View File

@@ -1,9 +1,9 @@
//! Memory management for executable code.
use core::{cmp, mem};
use region;
use std::string::String;
use std::vec::Vec;
use std::{cmp, mem};
use wasmtime_runtime::{Mmap, VMFunctionBody};
/// Memory manager for executable code.

View File

@@ -1,5 +1,6 @@
//! JIT compilation.
use super::HashMap;
use crate::code_memory::CodeMemory;
use crate::instantiate::SetupError;
use crate::target_tunables::target_tunables;
@@ -11,7 +12,6 @@ use cranelift_entity::PrimaryMap;
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
use cranelift_wasm::DefinedFuncIndex;
use std::boxed::Box;
use std::collections::HashMap;
use std::string::String;
use std::vec::Vec;
use wasmtime_environ::cranelift;
@@ -95,7 +95,7 @@ impl Compiler {
signature: &ir::Signature,
value_size: usize,
) -> Result<*const VMFunctionBody, SetupError> {
use std::collections::hash_map::Entry::{Occupied, Vacant};
use super::hash_map::Entry::{Occupied, Vacant};
Ok(match self.trampoline_park.entry(callee_address) {
Occupied(entry) => *entry.get(),
Vacant(entry) => {

View File

@@ -21,18 +21,26 @@
clippy::use_self
)
)]
#![cfg_attr(not(feature = "std"), no_std)]
#![no_std]
#![cfg_attr(not(feature = "std"), feature(alloc))]
#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc as std;
#[cfg(feature = "std")]
#[macro_use]
extern crate std;
#[cfg(not(feature = "std"))]
use hashmap_core::{map as hash_map, HashMap};
#[cfg(feature = "std")]
use std::collections::{hash_map, HashMap};
#[macro_use]
extern crate cranelift_entity;
use region;
#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc;
use failure;
use region;
#[macro_use]
extern crate failure_derive;
@@ -57,10 +65,3 @@ pub use crate::target_tunables::target_tunables;
// Re-export `Instance` so that users won't need to separately depend on
// wasmtime-runtime in common cases.
pub use wasmtime_runtime::{Instance, InstantiationError};
#[cfg(not(feature = "std"))]
mod std {
pub use alloc::{boxed, rc, string, vec};
pub use core::*;
pub use core::{i32, str, u32};
}

View File

@@ -1,10 +1,10 @@
//! Linking for JIT-compiled code.
use crate::resolver::Resolver;
use core::ptr::write_unaligned;
use cranelift_codegen::binemit::Reloc;
use cranelift_entity::PrimaryMap;
use cranelift_wasm::{DefinedFuncIndex, Global, GlobalInit, Memory, Table, TableElementType};
use std::ptr::write_unaligned;
use std::vec::Vec;
use wasmtime_environ::{
MemoryPlan, MemoryStyle, Module, Relocation, RelocationTarget, Relocations, TablePlan,

View File

@@ -2,12 +2,12 @@
//! to exports. This file provides one possible way to manage multiple instances
//! and resolve imports to exports among them.
use super::HashMap;
use crate::action::{get, inspect_memory, invoke};
use crate::action::{ActionError, ActionOutcome, RuntimeValue};
use crate::compiler::Compiler;
use crate::resolver::Resolver;
use cranelift_entity::PrimaryMap;
use std::collections::HashMap;
use std::string::String;
use wasmtime_runtime::{Export, Instance};

View File

@@ -1,4 +1,4 @@
use std::cmp::min;
use core::cmp::min;
use target_lexicon::{OperatingSystem, Triple};
use wasmtime_environ::Tunables;