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;

View File

@@ -20,12 +20,13 @@ wasmtime-runtime = { path = "../runtime" }
region = "1.0.0"
failure = { version = "0.1.3", default-features = false }
failure_derive = { version = "0.1.3", default-features = false }
target-lexicon = "0.2.0"
target-lexicon = { version = "0.2.0", 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", "wasmtime-environ/core"]
core = ["hashmap_core", "cranelift-codegen/core", "cranelift-wasm/core", "wasmtime-environ/core"]
[badges]
maintenance = { status = "experimental" }

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;

View File

@@ -13,16 +13,17 @@ use crate::vmcontext::{
VMGlobalImport, VMMemoryDefinition, VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition,
VMTableImport,
};
use core::slice;
use core::{mem, ptr};
use cranelift_entity::EntityRef;
use cranelift_entity::{BoxedSlice, PrimaryMap};
use cranelift_wasm::{
DefinedFuncIndex, DefinedGlobalIndex, DefinedMemoryIndex, DefinedTableIndex, FuncIndex,
GlobalIndex, GlobalInit, MemoryIndex, SignatureIndex, TableIndex,
};
use std::borrow::ToOwned;
use std::rc::Rc;
use std::slice;
use std::string::String;
use std::{mem, ptr};
use wasmtime_environ::{DataInitializer, Module, TableElements, VMOffsets};
fn signature_id(

View File

@@ -21,15 +21,24 @@
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};
use errno;
use region;
#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc;
#[macro_use]
extern crate lazy_static;
use libc;
@@ -66,10 +75,3 @@ pub use crate::vmcontext::{
VMContext, VMFunctionBody, VMFunctionImport, VMGlobalDefinition, VMGlobalImport,
VMMemoryDefinition, VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport,
};
#[cfg(not(feature = "std"))]
mod std {
pub use alloc::{string, vec};
pub use core::*;
pub use core::{i32, str, u32};
}

View File

@@ -1,12 +1,13 @@
//! Low-level abstraction for allocating and managing zero-filled pages
//! of memory.
use core::ptr;
use core::slice;
use errno;
use libc;
use region;
use std::ptr;
use std::slice;
use std::string::String;
use std::string::{String, ToString};
use std::vec::Vec;
/// Round `size` up to the nearest multiple of `page_size`.
fn round_up_to_page_size(size: usize, page_size: usize) -> usize {

View File

@@ -1,10 +1,10 @@
//! Implement a registry of function signatures, for fast indirect call
//! signature checking.
use super::{hash_map, HashMap};
use crate::vmcontext::VMSharedSignatureIndex;
use cast;
use cranelift_codegen::ir;
use std::collections::{hash_map, HashMap};
/// WebAssembly requires that the caller and callee signatures in an indirect
/// call must match. To implement this efficiently, keep a registry of all

View File

@@ -5,8 +5,8 @@
#![allow(non_snake_case)]
use crate::vmcontext::VMContext;
use std::borrow::{Borrow, BorrowMut};
use std::cell::RefCell;
use core::borrow::{Borrow, BorrowMut};
use core::cell::RefCell;
use std::sync::RwLock;
include!(concat!(env!("OUT_DIR"), "/signalhandlers.rs"));

View File

@@ -4,6 +4,7 @@
use crate::vmcontext::{VMCallerCheckedAnyfunc, VMTableDefinition};
use cranelift_wasm::TableElementType;
use std::vec::Vec;
use wasmtime_environ::{TablePlan, TableStyle};
/// A table instance.

View File

@@ -3,11 +3,12 @@
use crate::signalhandlers::jmp_buf;
use crate::vmcontext::{VMContext, VMFunctionBody};
use core::cell::{Cell, RefCell};
use core::mem;
use core::ptr;
use libc::c_int;
use std::cell::{Cell, RefCell};
use std::mem;
use std::ptr;
use std::string::String;
use std::vec::Vec;
// Currently we uset setjmp/longjmp to unwind out of a signal handler
// and back to the point where WebAssembly was called (via `call_wasm`).

View File

@@ -2,7 +2,7 @@
//! fields that compiled wasm code accesses directly.
use crate::instance::InstanceContents;
use std::{ptr, u32};
use core::{ptr, u32};
/// An imported function.
#[derive(Debug, Copy, Clone)]
@@ -18,7 +18,7 @@ pub struct VMFunctionImport {
#[cfg(test)]
mod test_vmfunction_import {
use super::VMFunctionImport;
use std::mem::size_of;
use core::mem::size_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -50,7 +50,7 @@ pub struct VMFunctionBody(u8);
#[cfg(test)]
mod test_vmfunction_body {
use super::VMFunctionBody;
use std::mem::size_of;
use core::mem::size_of;
#[test]
fn check_vmfunction_body_offsets() {
@@ -73,7 +73,7 @@ pub struct VMTableImport {
#[cfg(test)]
mod test_vmtable_import {
use super::VMTableImport;
use std::mem::size_of;
use core::mem::size_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -110,7 +110,7 @@ pub struct VMMemoryImport {
#[cfg(test)]
mod test_vmmemory_import {
use super::VMMemoryImport;
use std::mem::size_of;
use core::mem::size_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -144,7 +144,7 @@ pub struct VMGlobalImport {
#[cfg(test)]
mod test_vmglobal_import {
use super::VMGlobalImport;
use std::mem::size_of;
use core::mem::size_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -178,7 +178,7 @@ pub struct VMMemoryDefinition {
#[cfg(test)]
mod test_vmmemory_definition {
use super::VMMemoryDefinition;
use std::mem::size_of;
use core::mem::size_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -221,7 +221,7 @@ pub struct VMTableDefinition {
#[cfg(test)]
mod test_vmtable_definition {
use super::VMTableDefinition;
use std::mem::size_of;
use core::mem::size_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -257,7 +257,7 @@ pub struct VMGlobalDefinition {
#[cfg(test)]
mod test_vmglobal_definition {
use super::VMGlobalDefinition;
use std::mem::{align_of, size_of};
use core::mem::{align_of, size_of};
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -391,7 +391,7 @@ pub struct VMSharedSignatureIndex(u32);
#[cfg(test)]
mod test_vmshared_signature_index {
use super::VMSharedSignatureIndex;
use std::mem::size_of;
use core::mem::size_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -427,7 +427,7 @@ pub struct VMCallerCheckedAnyfunc {
#[cfg(test)]
mod test_vmcaller_checked_anyfunc {
use super::VMCallerCheckedAnyfunc;
use std::mem::size_of;
use core::mem::size_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]