From 8e1b44b29c5347cf288aaa89137df3bae2ffe864 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 8 Oct 2019 16:53:32 -0700 Subject: [PATCH] Make more code work with no_std. (#407) * Make more code work with no_std. no_std support is still incomplete, but this patch takes care of the bulk of the straightforward parts. --- build.rs | 2 +- fuzz/fuzz_targets/compile.rs | 4 +- lightbeam/src/function_body.rs | 3 +- lightbeam/src/module.rs | 4 +- misc/wasmtime-py/src/function.rs | 6 +- misc/wasmtime-py/src/import.rs | 6 +- misc/wasmtime-py/src/instance.rs | 6 +- misc/wasmtime-py/src/lib.rs | 2 +- misc/wasmtime-py/src/memory.rs | 8 +- misc/wasmtime-py/src/module.rs | 4 +- misc/wasmtime-py/src/value.rs | 2 +- tests/instantiate.rs | 6 +- wasmtime-api/Cargo.toml | 7 +- wasmtime-api/examples/hello.rs | 6 +- wasmtime-api/examples/memory.rs | 2 +- wasmtime-api/src/callable.rs | 3 +- wasmtime-api/src/context.rs | 6 +- wasmtime-api/src/externals.rs | 11 +- wasmtime-api/src/instance.rs | 10 +- wasmtime-api/src/lib.rs | 9 ++ wasmtime-api/src/module.rs | 7 +- wasmtime-api/src/ref.rs | 9 +- wasmtime-api/src/runtime.rs | 10 +- wasmtime-api/src/trampoline/code_memory.rs | 4 +- wasmtime-api/src/trampoline/create_handle.rs | 11 +- wasmtime-api/src/trampoline/func.rs | 5 +- wasmtime-api/src/trampoline/global.rs | 1 + wasmtime-api/src/trampoline/memory.rs | 4 +- wasmtime-api/src/trampoline/mod.rs | 2 +- wasmtime-api/src/trampoline/table.rs | 4 +- wasmtime-api/src/trap.rs | 2 + wasmtime-api/src/types.rs | 12 +- wasmtime-api/src/values.rs | 2 +- wasmtime-api/src/wasm.rs | 32 +++--- wasmtime-api/tests/import_calling_export.rs | 6 +- wasmtime-debug/Cargo.toml | 3 +- wasmtime-debug/src/gc.rs | 6 +- wasmtime-debug/src/lib.rs | 15 ++- wasmtime-debug/src/read_debuginfo.rs | 3 + .../src/transform/address_transform.rs | 13 ++- wasmtime-debug/src/transform/attr.rs | 3 +- wasmtime-debug/src/transform/expression.rs | 5 +- wasmtime-debug/src/transform/line_program.rs | 5 +- wasmtime-debug/src/transform/mod.rs | 2 +- .../src/transform/range_info_builder.rs | 1 + wasmtime-debug/src/transform/simulate.rs | 4 +- wasmtime-debug/src/transform/unit.rs | 4 +- wasmtime-debug/src/transform/utils.rs | 1 + wasmtime-debug/src/write_debuginfo.rs | 4 +- wasmtime-environ/src/address_map.rs | 2 +- wasmtime-environ/src/cache.rs | 2 +- wasmtime-environ/src/cache/config.rs | 6 +- wasmtime-environ/src/cache/config/tests.rs | 2 +- wasmtime-environ/src/cache/tests.rs | 6 +- wasmtime-environ/src/cache/worker.rs | 6 +- wasmtime-environ/src/cache/worker/tests.rs | 2 +- wasmtime-environ/src/compilation.rs | 2 +- wasmtime-environ/src/cranelift.rs | 2 +- wasmtime-environ/src/func_environ.rs | 2 +- wasmtime-environ/src/lib.rs | 8 +- wasmtime-environ/src/module.rs | 6 +- wasmtime-environ/src/module_environ.rs | 6 +- wasmtime-interface-types/Cargo.toml | 10 +- wasmtime-interface-types/src/lib.rs | 12 +- wasmtime-interface-types/src/value.rs | 5 +- wasmtime-jit/Cargo.toml | 6 +- wasmtime-jit/src/action.rs | 4 +- wasmtime-jit/src/code_memory.rs | 6 +- wasmtime-jit/src/compiler.rs | 6 +- wasmtime-jit/src/context.rs | 12 +- wasmtime-jit/src/instantiate.rs | 10 +- wasmtime-jit/src/lib.rs | 15 +-- wasmtime-jit/src/link.rs | 4 +- wasmtime-jit/src/namespace.rs | 2 +- wasmtime-obj/src/context.rs | 6 +- wasmtime-obj/src/data_segment.rs | 2 + wasmtime-obj/src/function.rs | 1 + wasmtime-obj/src/lib.rs | 2 + wasmtime-obj/src/module.rs | 1 + wasmtime-obj/src/table.rs | 2 + wasmtime-runtime/Cargo.toml | 3 + wasmtime-runtime/src/imports.rs | 2 +- wasmtime-runtime/src/instance.rs | 22 ++-- wasmtime-runtime/src/jit_int.rs | 7 +- wasmtime-runtime/src/lib.rs | 12 ++ wasmtime-runtime/src/memory.rs | 4 +- wasmtime-runtime/src/mmap.rs | 4 +- wasmtime-runtime/src/sig_registry.rs | 10 +- wasmtime-runtime/src/signalhandlers.rs | 2 +- wasmtime-runtime/src/table.rs | 8 +- wasmtime-runtime/src/trap_registry.rs | 4 +- wasmtime-runtime/src/traphandlers.rs | 2 +- wasmtime-wasi-c/src/instantiate.rs | 4 +- wasmtime-wasi-c/src/syscalls.rs | 2 +- wasmtime-wasi-c/src/translate.rs | 2 +- wasmtime-wasi-c/src/wasm32.rs | 104 +++++++++--------- wasmtime-wasi/src/instantiate.rs | 4 +- wasmtime-wasi/src/lib.rs | 2 + wasmtime-wast/src/lib.rs | 1 + wasmtime-wast/src/spectest.rs | 6 +- 100 files changed, 380 insertions(+), 270 deletions(-) diff --git a/build.rs b/build.rs index 9697d9903a..de13239e47 100644 --- a/build.rs +++ b/build.rs @@ -204,7 +204,7 @@ fn ignore(testsuite: &str, name: &str, strategy: &str) -> bool { if unsafe { strtof( b"8.8817847263968443574e-16" as *const u8 as *const libc::c_char, - std::ptr::null_mut(), + core::ptr::null_mut(), ) } .to_bits() diff --git a/fuzz/fuzz_targets/compile.rs b/fuzz/fuzz_targets/compile.rs index 1749fdffd8..f6d0b5c32a 100644 --- a/fuzz/fuzz_targets/compile.rs +++ b/fuzz/fuzz_targets/compile.rs @@ -8,10 +8,10 @@ extern crate wasmparser; extern crate wasmtime_environ; extern crate wasmtime_jit; +use alloc::rc::Rc; +use core::cell::RefCell; use cranelift_codegen::settings; -use std::cell::RefCell; use std::collections::HashMap; -use std::rc::Rc; use wasmparser::validate; use wasmtime_jit::{CompilationStrategy, CompiledModule, Compiler, NullResolver}; diff --git a/lightbeam/src/function_body.rs b/lightbeam/src/function_body.rs index f578b64f6f..113d1788b5 100644 --- a/lightbeam/src/function_body.rs +++ b/lightbeam/src/function_body.rs @@ -5,11 +5,12 @@ use crate::backend::{ use crate::error::Error; use crate::microwasm::*; use crate::module::{ModuleContext, SigType, Signature}; +use core::{fmt, mem}; use cranelift_codegen::binemit; use dynasmrt::DynasmApi; use either::{Either, Left, Right}; use multi_mut::HashMapMultiMut; -use std::{collections::HashMap, fmt, hash::Hash, mem}; +use std::{collections::HashMap, hash::Hash}; #[derive(Debug)] struct Block { diff --git a/lightbeam/src/module.rs b/lightbeam/src/module.rs index 9a61ae9925..2070695908 100644 --- a/lightbeam/src/module.rs +++ b/lightbeam/src/module.rs @@ -2,11 +2,11 @@ use crate::backend::TranslatedCodeSection; use crate::error::Error; use crate::microwasm; use crate::translate_sections; +use core::{convert::TryInto, mem}; use cranelift_codegen::{ ir::{self, AbiParam, Signature as CraneliftSignature}, isa, }; -use std::{convert::TryInto, mem}; use wasmparser::{FuncType, MemoryType, ModuleReader, SectionCode, Type}; pub trait AsValueType { @@ -162,7 +162,7 @@ impl ExecutableModule { self.context .as_ref() .map(|ctx| (&**ctx) as *const VmCtx as *const u8) - .unwrap_or(std::ptr::null()), + .unwrap_or(core::ptr::null()), ) } diff --git a/misc/wasmtime-py/src/function.rs b/misc/wasmtime-py/src/function.rs index 887bcbc896..d3421ae6f7 100644 --- a/misc/wasmtime-py/src/function.rs +++ b/misc/wasmtime-py/src/function.rs @@ -1,11 +1,13 @@ //! Support for a calling of a bounds (exported) function. +extern crate alloc; + use pyo3::prelude::*; use pyo3::types::PyTuple; use crate::value::{pyobj_to_value, value_to_pyobj}; -use std::cell::RefCell; -use std::rc::Rc; +use alloc::rc::Rc; +use core::cell::RefCell; use cranelift_codegen::ir; use wasmtime_interface_types::ModuleData; diff --git a/misc/wasmtime-py/src/import.rs b/misc/wasmtime-py/src/import.rs index b9f7eb4b6c..d744193247 100644 --- a/misc/wasmtime-py/src/import.rs +++ b/misc/wasmtime-py/src/import.rs @@ -1,5 +1,7 @@ //! Support for a calling of an imported function. +extern crate alloc; + use pyo3::prelude::*; use pyo3::types::{PyAny, PyDict, PyTuple}; @@ -18,10 +20,10 @@ use target_lexicon::HOST; use wasmtime_environ::{Export, Module}; use wasmtime_runtime::{Imports, InstanceHandle, VMContext, VMFunctionBody}; +use alloc::rc::Rc; +use core::cell::RefCell; use core::cmp; -use std::cell::RefCell; use std::collections::{HashMap, HashSet}; -use std::rc::Rc; struct BoundPyFunction { name: String, diff --git a/misc/wasmtime-py/src/instance.rs b/misc/wasmtime-py/src/instance.rs index 98307f7465..1baa5ea83b 100644 --- a/misc/wasmtime-py/src/instance.rs +++ b/misc/wasmtime-py/src/instance.rs @@ -1,12 +1,14 @@ //! WebAssembly Instance API object. +extern crate alloc; + use pyo3::prelude::*; use pyo3::types::PyDict; use crate::function::Function; use crate::memory::Memory; -use std::cell::RefCell; -use std::rc::Rc; +use alloc::rc::Rc; +use core::cell::RefCell; use cranelift_codegen::ir; use cranelift_codegen::ir::types; diff --git a/misc/wasmtime-py/src/lib.rs b/misc/wasmtime-py/src/lib.rs index ab745ff8da..69a1af5218 100644 --- a/misc/wasmtime-py/src/lib.rs +++ b/misc/wasmtime-py/src/lib.rs @@ -7,7 +7,7 @@ use crate::import::into_instance_from_obj; use crate::instance::Instance; use crate::memory::Memory; use crate::module::Module; -use std::cell::RefCell; +use core::cell::RefCell; use std::rc::Rc; use wasmtime_interface_types::ModuleData; diff --git a/misc/wasmtime-py/src/memory.rs b/misc/wasmtime-py/src/memory.rs index 072e45cb8f..6bd338372f 100644 --- a/misc/wasmtime-py/src/memory.rs +++ b/misc/wasmtime-py/src/memory.rs @@ -1,15 +1,17 @@ //! WebAssembly Memory API object. +extern crate alloc; + use pyo3::class::PyBufferProtocol; use pyo3::exceptions::BufferError; use pyo3::ffi; use pyo3::prelude::*; -use std::cell::RefCell; +use alloc::rc::Rc; +use core::cell::RefCell; +use core::ptr; use std::ffi::CStr; use std::os::raw::{c_int, c_void}; -use std::ptr; -use std::rc::Rc; use wasmtime_environ::MemoryPlan; use wasmtime_jit::{Context, InstanceHandle}; diff --git a/misc/wasmtime-py/src/module.rs b/misc/wasmtime-py/src/module.rs index 9aecdee883..5dd22a65ff 100644 --- a/misc/wasmtime-py/src/module.rs +++ b/misc/wasmtime-py/src/module.rs @@ -1,8 +1,10 @@ //! WebAssembly Module API object. +extern crate alloc; + use pyo3::prelude::*; -use std::rc::Rc; +use alloc::rc::Rc; #[pyclass] pub struct Module { diff --git a/misc/wasmtime-py/src/value.rs b/misc/wasmtime-py/src/value.rs index 35a45a4167..5542468752 100644 --- a/misc/wasmtime-py/src/value.rs +++ b/misc/wasmtime-py/src/value.rs @@ -4,8 +4,8 @@ use pyo3::exceptions::Exception; use pyo3::prelude::*; use pyo3::types::PyAny; +use core::ptr; use cranelift_codegen::ir; -use std::ptr; use wasmtime_interface_types::Value; pub fn pyobj_to_value(_: Python, p: &PyAny) -> PyResult { diff --git a/tests/instantiate.rs b/tests/instantiate.rs index 00c29c09d1..3da32b1d97 100644 --- a/tests/instantiate.rs +++ b/tests/instantiate.rs @@ -1,12 +1,14 @@ +extern crate alloc; + +use alloc::rc::Rc; +use core::cell::RefCell; use cranelift_codegen::settings; use cranelift_codegen::settings::Configurable; -use std::cell::RefCell; use std::collections::HashMap; use std::fs::File; use std::io; use std::io::Read; use std::path::PathBuf; -use std::rc::Rc; use wabt; use wasmtime_jit::{instantiate, CompilationStrategy, Compiler, NullResolver}; diff --git a/wasmtime-api/Cargo.toml b/wasmtime-api/Cargo.toml index 629a37e3da..93125ea07c 100644 --- a/wasmtime-api/Cargo.toml +++ b/wasmtime-api/Cargo.toml @@ -20,15 +20,18 @@ cranelift-frontend = "0.44.0" wasmtime-runtime = { path="../wasmtime-runtime" } wasmtime-environ = { path="../wasmtime-environ" } wasmtime-jit = { path="../wasmtime-jit" } -wasmparser = "0.39.1" +wasmparser = { version = "0.39.1", default-features = false } failure = { version = "0.1.3", default-features = false } failure_derive = { version = "0.1.3", default-features = false } target-lexicon = { version = "0.8.1", default-features = false } region = "2.0.0" +hashbrown = { version = "0.6.0", optional = true } [features] -default = [] +default = ["std"] +std = ["cranelift-codegen/std", "cranelift-wasm/std", "wasmtime-environ/std", "wasmparser/std"] wasm-c-api = [] +core = ["hashbrown/nightly", "cranelift-codegen/core", "cranelift-wasm/core", "wasmtime-environ/core", "wasmparser/core"] [dev-dependencies] # for wasmtime.rs diff --git a/wasmtime-api/examples/hello.rs b/wasmtime-api/examples/hello.rs index 4323ac4a70..819c3f27e7 100644 --- a/wasmtime-api/examples/hello.rs +++ b/wasmtime-api/examples/hello.rs @@ -1,9 +1,11 @@ //! Translation of hello example +extern crate alloc; + +use alloc::rc::Rc; +use core::cell::Ref; use failure::{bail, format_err, Error}; -use std::cell::Ref; use std::fs::read; -use std::rc::Rc; use wasmtime_api::*; struct HelloCallback; diff --git a/wasmtime-api/examples/memory.rs b/wasmtime-api/examples/memory.rs index 8a9f1f8c54..ad184d8ec1 100644 --- a/wasmtime-api/examples/memory.rs +++ b/wasmtime-api/examples/memory.rs @@ -1,7 +1,7 @@ //! Translation of the memory example +use core::cell::Ref; use failure::{bail, format_err, Error}; -use std::cell::Ref; use std::fs::read; use wasmtime_api::*; diff --git a/wasmtime-api/src/callable.rs b/wasmtime-api/src/callable.rs index 6a8aab973e..0de7726fb5 100644 --- a/wasmtime-api/src/callable.rs +++ b/wasmtime-api/src/callable.rs @@ -3,7 +3,8 @@ use crate::runtime::Store; use crate::trap::Trap; use crate::types::FuncType; use crate::values::Val; -use std::rc::Rc; +use alloc::rc::Rc; +use alloc::vec::Vec; use crate::trampoline::generate_func_export; use cranelift_codegen::ir; diff --git a/wasmtime-api/src/context.rs b/wasmtime-api/src/context.rs index 3016288c59..e27a295601 100644 --- a/wasmtime-api/src/context.rs +++ b/wasmtime-api/src/context.rs @@ -1,6 +1,6 @@ -use std::cell::{RefCell, RefMut}; -use std::hash::{Hash, Hasher}; -use std::rc::Rc; +use alloc::rc::Rc; +use core::cell::{RefCell, RefMut}; +use core::hash::{Hash, Hasher}; use wasmtime_jit::{CompilationStrategy, Compiler, Features}; diff --git a/wasmtime-api/src/externals.rs b/wasmtime-api/src/externals.rs index c06045a3d5..fbdab1cfb6 100644 --- a/wasmtime-api/src/externals.rs +++ b/wasmtime-api/src/externals.rs @@ -5,9 +5,10 @@ use crate::trampoline::{generate_global_export, generate_memory_export, generate use crate::trap::Trap; use crate::types::{ExternType, FuncType, GlobalType, MemoryType, TableType, ValType}; use crate::values::{from_checked_anyfunc, into_checked_anyfunc, Val}; -use std::rc::Rc; -use std::result::Result; -use std::slice; +use alloc::boxed::Box; +use alloc::rc::Rc; +use core::result::Result; +use core::slice; use wasmtime_runtime::InstanceHandle; // Externals @@ -171,8 +172,8 @@ impl Func { } } -impl std::fmt::Debug for Func { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Func { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "Func") } } diff --git a/wasmtime-api/src/instance.rs b/wasmtime-api/src/instance.rs index a3bc0274e4..5bd8cb3e69 100644 --- a/wasmtime-api/src/instance.rs +++ b/wasmtime-api/src/instance.rs @@ -3,10 +3,14 @@ use crate::externals::Extern; use crate::module::Module; use crate::r#ref::HostRef; use crate::runtime::Store; +use crate::{HashMap, HashSet}; +use alloc::borrow::ToOwned; +use alloc::boxed::Box; +use alloc::rc::Rc; +use alloc::string::{String, ToString}; +use alloc::vec::Vec; +use core::cell::RefCell; use failure::Error; -use std::cell::RefCell; -use std::collections::{HashMap, HashSet}; -use std::rc::Rc; use wasmtime_jit::{instantiate, Resolver}; use wasmtime_runtime::{Export, InstanceHandle}; diff --git a/wasmtime-api/src/lib.rs b/wasmtime-api/src/lib.rs index 7248dc8616..71a3c82077 100644 --- a/wasmtime-api/src/lib.rs +++ b/wasmtime-api/src/lib.rs @@ -1,5 +1,7 @@ //! Wasmtime embed API. Based on wasm-c-api. +#![cfg_attr(not(feature = "std"), no_std)] + mod callable; mod context; mod externals; @@ -17,6 +19,8 @@ pub mod wasm; #[macro_use] extern crate failure_derive; +#[macro_use] +extern crate alloc; pub use crate::callable::Callable; pub use crate::externals::*; @@ -27,3 +31,8 @@ pub use crate::runtime::{Config, Engine, Store}; pub use crate::trap::Trap; pub use crate::types::*; pub use crate::values::*; + +#[cfg(not(feature = "std"))] +use hashbrown::{hash_map, HashMap, HashSet}; +#[cfg(feature = "std")] +use std::collections::{hash_map, HashMap, HashSet}; diff --git a/wasmtime-api/src/module.rs b/wasmtime-api/src/module.rs index 0caed03b14..db58f3e1a5 100644 --- a/wasmtime-api/src/module.rs +++ b/wasmtime-api/src/module.rs @@ -4,6 +4,9 @@ use crate::types::{ ExportType, ExternType, FuncType, GlobalType, ImportType, Limits, MemoryType, Mutability, TableType, ValType, }; +use alloc::boxed::Box; +use alloc::string::String; +use alloc::vec::Vec; use failure::Error; use wasmparser::{validate, ExternalKind, ImportSectionEntryType, ModuleReader, SectionCode}; @@ -12,7 +15,7 @@ fn into_memory_type(mt: wasmparser::MemoryType) -> MemoryType { assert!(!mt.shared); MemoryType::new(Limits::new( mt.limits.initial, - mt.limits.maximum.unwrap_or(::std::u32::MAX), + mt.limits.maximum.unwrap_or(::core::u32::MAX), )) } @@ -53,7 +56,7 @@ fn into_table_type(tt: wasmparser::TableType) -> TableType { let ty = into_valtype(&tt.element_type); let limits = Limits::new( tt.limits.initial, - tt.limits.maximum.unwrap_or(::std::u32::MAX), + tt.limits.maximum.unwrap_or(::core::u32::MAX), ); TableType::new(ty, limits) } diff --git a/wasmtime-api/src/ref.rs b/wasmtime-api/src/ref.rs index c6010c0624..098ec639e4 100644 --- a/wasmtime-api/src/ref.rs +++ b/wasmtime-api/src/ref.rs @@ -1,7 +1,8 @@ -use std::any::Any; -use std::cell::{self, RefCell}; -use std::fmt; -use std::rc::{Rc, Weak}; +use alloc::boxed::Box; +use alloc::rc::{Rc, Weak}; +use core::any::Any; +use core::cell::{self, RefCell}; +use core::fmt; pub trait HostInfo { fn finalize(&mut self) {} diff --git a/wasmtime-api/src/runtime.rs b/wasmtime-api/src/runtime.rs index 535120091e..e3e0f4359a 100644 --- a/wasmtime-api/src/runtime.rs +++ b/wasmtime-api/src/runtime.rs @@ -1,6 +1,8 @@ -use std::cell::RefCell; -use std::collections::HashMap; -use std::rc::Rc; +use crate::HashMap; +use alloc::boxed::Box; +use alloc::rc::Rc; +use alloc::string::String; +use core::cell::RefCell; use crate::context::{create_compiler, Context}; use crate::r#ref::HostRef; @@ -132,7 +134,7 @@ impl Store { &mut self, signature: &ir::Signature, ) -> wasmtime_runtime::VMSharedSignatureIndex { - use std::collections::hash_map::Entry; + use crate::hash_map::Entry; let index = self.context().compiler().signatures().register(signature); match self.signature_cache.entry(index) { Entry::Vacant(v) => { diff --git a/wasmtime-api/src/trampoline/code_memory.rs b/wasmtime-api/src/trampoline/code_memory.rs index b117f52289..87d1422944 100644 --- a/wasmtime-api/src/trampoline/code_memory.rs +++ b/wasmtime-api/src/trampoline/code_memory.rs @@ -1,10 +1,10 @@ //! Memory management for executable code. // Copy of wasmtime's wasmtime-jit/src/code_memory.rs +use alloc::string::String; +use alloc::vec::Vec; use core::{cmp, mem}; use region; -use std::string::String; -use std::vec::Vec; use wasmtime_runtime::{Mmap, VMFunctionBody}; /// Memory manager for executable code. diff --git a/wasmtime-api/src/trampoline/create_handle.rs b/wasmtime-api/src/trampoline/create_handle.rs index f765eed993..20649c10d0 100644 --- a/wasmtime-api/src/trampoline/create_handle.rs +++ b/wasmtime-api/src/trampoline/create_handle.rs @@ -7,10 +7,13 @@ use failure::Error; use wasmtime_environ::Module; use wasmtime_runtime::{Imports, InstanceHandle, VMFunctionBody}; -use std::any::Any; -use std::cell::{RefCell, RefMut}; -use std::collections::{HashMap, HashSet}; -use std::rc::Rc; +use crate::{HashMap, HashSet}; +use alloc::boxed::Box; +use alloc::rc::Rc; +use alloc::string::String; +use alloc::vec::Vec; +use core::any::Any; +use core::cell::{RefCell, RefMut}; use crate::runtime::Store; diff --git a/wasmtime-api/src/trampoline/func.rs b/wasmtime-api/src/trampoline/func.rs index 3107ed28f4..8b87f91ae8 100644 --- a/wasmtime-api/src/trampoline/func.rs +++ b/wasmtime-api/src/trampoline/func.rs @@ -14,8 +14,11 @@ use failure::Error; use wasmtime_environ::{Export, Module}; use wasmtime_runtime::{InstanceHandle, VMContext, VMFunctionBody}; +use alloc::boxed::Box; +use alloc::rc::Rc; +use alloc::string::ToString; +use alloc::vec::Vec; use core::cmp; -use std::rc::Rc; use crate::{Callable, FuncType, Store, Trap, Val}; diff --git a/wasmtime-api/src/trampoline/global.rs b/wasmtime-api/src/trampoline/global.rs index a650170dcb..1e38c2fa3c 100644 --- a/wasmtime-api/src/trampoline/global.rs +++ b/wasmtime-api/src/trampoline/global.rs @@ -1,3 +1,4 @@ +use alloc::boxed::Box; use cranelift_entity::PrimaryMap; use failure::Error; use wasmtime_environ::Module; diff --git a/wasmtime-api/src/trampoline/memory.rs b/wasmtime-api/src/trampoline/memory.rs index 9b65fde3d6..21c5c3e9dc 100644 --- a/wasmtime-api/src/trampoline/memory.rs +++ b/wasmtime-api/src/trampoline/memory.rs @@ -1,3 +1,5 @@ +use alloc::boxed::Box; +use alloc::string::ToString; use cranelift_entity::PrimaryMap; use failure::Error; use wasmtime_environ::Module; @@ -13,7 +15,7 @@ pub fn create_handle_with_memory(memory: &MemoryType) -> Result Result Limits { Limits { min, - max: ::std::u32::MAX, + max: ::core::u32::MAX, } } @@ -257,7 +261,7 @@ impl TableType { false }); let ty = ValType::FuncRef; - let limits = Limits::new(table.minimum, table.maximum.unwrap_or(::std::u32::MAX)); + let limits = Limits::new(table.minimum, table.maximum.unwrap_or(::core::u32::MAX)); TableType::new(ty, limits) } } @@ -280,7 +284,7 @@ impl MemoryType { pub(crate) fn from_cranelift_memory(memory: cranelift_wasm::Memory) -> MemoryType { MemoryType::new(Limits::new( memory.minimum, - memory.maximum.unwrap_or(::std::u32::MAX), + memory.maximum.unwrap_or(::core::u32::MAX), )) } } @@ -296,7 +300,7 @@ impl From for Name { } } -impl ::std::string::ToString for Name { +impl ::alloc::string::ToString for Name { fn to_string(&self) -> String { self.0.to_owned() } diff --git a/wasmtime-api/src/values.rs b/wasmtime-api/src/values.rs index 561f3ddcc8..13b2959220 100644 --- a/wasmtime-api/src/values.rs +++ b/wasmtime-api/src/values.rs @@ -2,7 +2,7 @@ use crate::externals::Func; use crate::r#ref::{AnyRef, HostRef}; use crate::runtime::Store; use crate::types::ValType; -use std::ptr; +use core::ptr; use cranelift_codegen::ir; use wasmtime_jit::RuntimeValue; diff --git a/wasmtime-api/src/wasm.rs b/wasmtime-api/src/wasm.rs index 049dccfe03..356466f0ac 100644 --- a/wasmtime-api/src/wasm.rs +++ b/wasmtime-api/src/wasm.rs @@ -10,11 +10,11 @@ use super::{ HostInfo, HostRef, ImportType, Instance, Limits, Memory, MemoryType, Module, Name, Store, Table, TableType, Trap, Val, ValType, }; -use std::boxed::Box; -use std::mem; -use std::ptr; -use std::rc::Rc; -use std::slice; +use alloc::boxed::Box; +use alloc::rc::Rc; +use core::mem; +use core::ptr; +use core::slice; macro_rules! declare_vec { ($name:ident, $elem_ty:path) => { @@ -345,12 +345,12 @@ pub struct wasm_func_t { func: HostRef, ext: Option>, } -pub type wasm_func_callback_t = ::std::option::Option< +pub type wasm_func_callback_t = ::core::option::Option< unsafe extern "C" fn(args: *const wasm_val_t, results: *mut wasm_val_t) -> *mut wasm_trap_t, >; -pub type wasm_func_callback_with_env_t = ::std::option::Option< +pub type wasm_func_callback_with_env_t = ::core::option::Option< unsafe extern "C" fn( - env: *mut ::std::os::raw::c_void, + env: *mut ::core::ffi::c_void, args: *const wasm_val_t, results: *mut wasm_val_t, ) -> *mut wasm_trap_t, @@ -569,8 +569,8 @@ impl Into> for wasm_trap_t { struct CallbackWithEnv { callback: wasm_func_callback_with_env_t, - env: *mut ::std::os::raw::c_void, - finalizer: ::std::option::Option, + env: *mut ::core::ffi::c_void, + finalizer: ::core::option::Option, } impl Callable for CallbackWithEnv { @@ -801,8 +801,8 @@ pub unsafe extern "C" fn wasm_func_new_with_env( store: *mut wasm_store_t, ty: *const wasm_functype_t, callback: wasm_func_callback_with_env_t, - env: *mut ::std::os::raw::c_void, - finalizer: ::std::option::Option, + env: *mut ::core::ffi::c_void, + finalizer: ::core::option::Option, ) -> *mut wasm_func_t { let store = (*store).store.clone(); let ty = (*ty).functype.clone(); @@ -1618,8 +1618,8 @@ pub unsafe extern "C" fn wasm_tabletype_new( } struct HostInfoState { - info: *mut ::std::os::raw::c_void, - finalizer: ::std::option::Option, + info: *mut ::core::ffi::c_void, + finalizer: ::core::option::Option, } impl HostInfo for HostInfoState { @@ -1635,8 +1635,8 @@ impl HostInfo for HostInfoState { #[no_mangle] pub unsafe extern "C" fn wasm_instance_set_host_info_with_finalizer( instance: *mut wasm_instance_t, - info: *mut ::std::os::raw::c_void, - finalizer: ::std::option::Option, + info: *mut ::core::ffi::c_void, + finalizer: ::core::option::Option, ) { let info = if info.is_null() && finalizer.is_none() { None diff --git a/wasmtime-api/tests/import_calling_export.rs b/wasmtime-api/tests/import_calling_export.rs index 06ea4c0361..deee58ce4a 100644 --- a/wasmtime-api/tests/import_calling_export.rs +++ b/wasmtime-api/tests/import_calling_export.rs @@ -1,6 +1,8 @@ -use std::cell::{Ref, RefCell}; +extern crate alloc; + +use alloc::rc::Rc; +use core::cell::{Ref, RefCell}; use std::fs::read; -use std::rc::Rc; use wasmtime_api::*; #[test] diff --git a/wasmtime-debug/Cargo.toml b/wasmtime-debug/Cargo.toml index 6bc77fcdcb..bffab92744 100644 --- a/wasmtime-debug/Cargo.toml +++ b/wasmtime-debug/Cargo.toml @@ -22,11 +22,12 @@ wasmtime-environ = { path = "../wasmtime-environ", default-features = false } target-lexicon = { version = "0.8.1", default-features = false } failure = { version = "0.1.3", default-features = false } failure_derive = { version = "0.1.3", default-features = false } +hashbrown = { version = "0.6.0", optional = true } [features] default = ["std"] std = ["cranelift-codegen/std", "cranelift-wasm/std", "wasmtime-environ/std"] -core = ["cranelift-codegen/core", "cranelift-wasm/core"] +core = ["hashbrown/nightly", "cranelift-codegen/core", "cranelift-wasm/core"] [badges] maintenance = { status = "experimental" } diff --git a/wasmtime-debug/src/gc.rs b/wasmtime-debug/src/gc.rs index f97a7ef093..edd4344705 100644 --- a/wasmtime-debug/src/gc.rs +++ b/wasmtime-debug/src/gc.rs @@ -1,9 +1,9 @@ use crate::transform::AddressTransform; +use crate::{HashMap, HashSet}; +use alloc::vec::Vec; use gimli::constants; use gimli::read; use gimli::{Reader, UnitSectionOffset}; -use std::collections::{HashMap, HashSet}; -use std::vec::Vec; #[derive(Debug)] pub struct Dependencies { @@ -20,7 +20,7 @@ impl Dependencies { } fn add_edge(&mut self, a: UnitSectionOffset, b: UnitSectionOffset) { - use std::collections::hash_map::Entry; + use crate::hash_map::Entry; match self.edges.entry(a) { Entry::Occupied(mut o) => { o.get_mut().insert(b); diff --git a/wasmtime-debug/src/lib.rs b/wasmtime-debug/src/lib.rs index 9ed090e69c..ea28e59ba5 100644 --- a/wasmtime-debug/src/lib.rs +++ b/wasmtime-debug/src/lib.rs @@ -1,10 +1,18 @@ //! Debug utils for WebAssembly using Cranelift. + +use alloc::string::String; +use alloc::vec::Vec; use cranelift_codegen::isa::TargetFrontendConfig; use faerie::{Artifact, Decl}; use failure::Error; use target_lexicon::{BinaryFormat, Triple}; use wasmtime_environ::{ModuleAddressMap, ModuleVmctxInfo, ValueLabelsRanges}; +#[cfg(not(feature = "std"))] +use hashbrown::{hash_map, HashMap, HashSet}; +#[cfg(feature = "std")] +use std::collections::{hash_map, HashMap, HashSet}; + pub use crate::read_debuginfo::{read_debuginfo, DebugInfoData, WasmFileInfo}; pub use crate::transform::transform_dwarf; pub use crate::write_debuginfo::{emit_dwarf, ResolvedSymbol, SymbolResolver}; @@ -16,6 +24,7 @@ mod write_debuginfo; #[macro_use] extern crate failure_derive; +extern crate alloc; struct FunctionRelocResolver {} impl SymbolResolver for FunctionRelocResolver { @@ -71,12 +80,12 @@ pub fn emit_debugsections_image( assert!(funcs.len() > 0); let mut segment_body: (usize, usize) = (!0, 0); for (body_ptr, body_len) in funcs.iter() { - segment_body.0 = ::std::cmp::min(segment_body.0, *body_ptr as usize); - segment_body.1 = ::std::cmp::max(segment_body.1, *body_ptr as usize + body_len); + segment_body.0 = ::core::cmp::min(segment_body.0, *body_ptr as usize); + segment_body.1 = ::core::cmp::max(segment_body.1, *body_ptr as usize + body_len); } let segment_body = (segment_body.0 as *const u8, segment_body.1 - segment_body.0); - let body = unsafe { ::std::slice::from_raw_parts(segment_body.0, segment_body.1) }; + let body = unsafe { ::core::slice::from_raw_parts(segment_body.0, segment_body.1) }; obj.declare_with("all", Decl::function(), body.to_vec())?; emit_dwarf(&mut obj, dwarf, &resolver)?; diff --git a/wasmtime-debug/src/read_debuginfo.rs b/wasmtime-debug/src/read_debuginfo.rs index fab07ec9eb..de0efe270b 100644 --- a/wasmtime-debug/src/read_debuginfo.rs +++ b/wasmtime-debug/src/read_debuginfo.rs @@ -1,3 +1,6 @@ +use alloc::boxed::Box; +use alloc::string::String; +use alloc::vec::Vec; use std::collections::HashMap; use std::path::PathBuf; use wasmparser::{self, ModuleReader, SectionCode}; diff --git a/wasmtime-debug/src/transform/address_transform.rs b/wasmtime-debug/src/transform/address_transform.rs index 2b0f1558ce..dc0fbfac6d 100644 --- a/wasmtime-debug/src/transform/address_transform.rs +++ b/wasmtime-debug/src/transform/address_transform.rs @@ -1,12 +1,13 @@ +use crate::HashMap; use crate::WasmFileInfo; +use alloc::boxed::Box; +use alloc::collections::BTreeMap; +use alloc::vec::Vec; +use core::iter::FromIterator; use cranelift_codegen::ir::SourceLoc; use cranelift_entity::{EntityRef, PrimaryMap}; use cranelift_wasm::DefinedFuncIndex; use gimli::write; -use std::boxed::Box; -use std::collections::{BTreeMap, HashMap}; -use std::iter::FromIterator; -use std::vec::Vec; use wasmtime_environ::{FunctionAddressMap, ModuleAddressMap}; pub type GeneratedAddress = usize; @@ -160,7 +161,7 @@ fn build_function_lookup( active_ranges.clone().into_boxed_slice(), ); } - active_ranges.retain(|r| ranges[*r].wasm_end.cmp(&wasm_start) != std::cmp::Ordering::Less); + active_ranges.retain(|r| ranges[*r].wasm_end.cmp(&wasm_start) != core::cmp::Ordering::Less); active_ranges.push(range_index); last_wasm_pos = Some(wasm_start); } @@ -491,10 +492,10 @@ impl AddressTransform { mod tests { use super::{build_function_lookup, get_wasm_code_offset, AddressTransform}; use crate::read_debuginfo::WasmFileInfo; + use core::iter::FromIterator; use cranelift_codegen::ir::SourceLoc; use cranelift_entity::PrimaryMap; use gimli::write::Address; - use std::iter::FromIterator; use wasmtime_environ::{FunctionAddressMap, InstructionAddressMap, ModuleAddressMap}; #[test] diff --git a/wasmtime-debug/src/transform/attr.rs b/wasmtime-debug/src/transform/attr.rs index 166a7cf9cf..75d959d84e 100644 --- a/wasmtime-debug/src/transform/attr.rs +++ b/wasmtime-debug/src/transform/attr.rs @@ -1,5 +1,6 @@ +use crate::HashMap; +use alloc::vec::Vec; use failure::Error; -use std::collections::HashMap; use gimli; diff --git a/wasmtime-debug/src/transform/expression.rs b/wasmtime-debug/src/transform/expression.rs index 68be19f639..7fa43185df 100644 --- a/wasmtime-debug/src/transform/expression.rs +++ b/wasmtime-debug/src/transform/expression.rs @@ -1,3 +1,5 @@ +use crate::{HashMap, HashSet}; +use alloc::vec::Vec; use cranelift_codegen::ir::{StackSlots, ValueLabel, ValueLoc}; use cranelift_codegen::isa::RegUnit; use cranelift_codegen::ValueLabelsRanges; @@ -6,7 +8,6 @@ use cranelift_wasm::{get_vmctx_value_label, DefinedFuncIndex}; use failure::Error; use gimli::write; use gimli::{self, Expression, Operation, Reader, ReaderOffset, Register, X86_64}; -use std::collections::{HashMap, HashSet}; use super::address_transform::AddressTransform; @@ -193,7 +194,7 @@ impl CompiledExpression { addr_tr: &AddressTransform, frame_info: Option<&FunctionFrameInfo>, endian: gimli::RunTimeEndian, - ) -> std::vec::Vec<(write::Address, u64, write::Expression)> { + ) -> alloc::vec::Vec<(write::Address, u64, write::Expression)> { if scope.len() == 0 { return vec![]; } diff --git a/wasmtime-debug/src/transform/line_program.rs b/wasmtime-debug/src/transform/line_program.rs index 812d183fed..1375d6ccd6 100644 --- a/wasmtime-debug/src/transform/line_program.rs +++ b/wasmtime-debug/src/transform/line_program.rs @@ -1,7 +1,8 @@ +use alloc::collections::BTreeMap; +use alloc::vec::Vec; +use core::iter::FromIterator; use cranelift_entity::EntityRef; use failure::Error; -use std::collections::BTreeMap; -use std::iter::FromIterator; use gimli; diff --git a/wasmtime-debug/src/transform/mod.rs b/wasmtime-debug/src/transform/mod.rs index f55f1f0f6a..b18940d11c 100644 --- a/wasmtime-debug/src/transform/mod.rs +++ b/wasmtime-debug/src/transform/mod.rs @@ -1,9 +1,9 @@ use crate::gc::build_dependencies; use crate::DebugInfoData; +use crate::HashSet; use cranelift_codegen::isa::TargetFrontendConfig; use failure::Error; use simulate::generate_simulated_dwarf; -use std::collections::HashSet; use wasmtime_environ::{ModuleAddressMap, ModuleVmctxInfo, ValueLabelsRanges}; use gimli; diff --git a/wasmtime-debug/src/transform/range_info_builder.rs b/wasmtime-debug/src/transform/range_info_builder.rs index bc75155564..0ba45b0487 100644 --- a/wasmtime-debug/src/transform/range_info_builder.rs +++ b/wasmtime-debug/src/transform/range_info_builder.rs @@ -1,3 +1,4 @@ +use alloc::vec::Vec; use cranelift_entity::EntityRef; use cranelift_wasm::DefinedFuncIndex; use failure::Error; diff --git a/wasmtime-debug/src/transform/simulate.rs b/wasmtime-debug/src/transform/simulate.rs index 8457fd36a1..9ebfdf658b 100644 --- a/wasmtime-debug/src/transform/simulate.rs +++ b/wasmtime-debug/src/transform/simulate.rs @@ -1,9 +1,11 @@ use crate::read_debuginfo::WasmFileInfo; pub use crate::read_debuginfo::{DebugInfoData, FunctionMetadata, WasmType}; +use crate::{HashMap, HashSet}; +use alloc::string::String; +use alloc::vec::Vec; use cranelift_entity::EntityRef; use cranelift_wasm::get_vmctx_value_label; use failure::Error; -use std::collections::{HashMap, HashSet}; use std::path::PathBuf; use wasmtime_environ::{ModuleVmctxInfo, ValueLabelsRanges}; diff --git a/wasmtime-debug/src/transform/unit.rs b/wasmtime-debug/src/transform/unit.rs index e4a200476c..d3a092d1a3 100644 --- a/wasmtime-debug/src/transform/unit.rs +++ b/wasmtime-debug/src/transform/unit.rs @@ -1,6 +1,8 @@ +use crate::{HashMap, HashSet}; +use alloc::string::String; +use alloc::vec::Vec; use cranelift_entity::EntityRef; use failure::Error; -use std::collections::{HashMap, HashSet}; use wasmtime_environ::{ModuleVmctxInfo, ValueLabelsRanges}; use gimli; diff --git a/wasmtime-debug/src/transform/utils.rs b/wasmtime-debug/src/transform/utils.rs index 3ef407fb85..b691c62edb 100644 --- a/wasmtime-debug/src/transform/utils.rs +++ b/wasmtime-debug/src/transform/utils.rs @@ -1,3 +1,4 @@ +use alloc::vec::Vec; use cranelift_wasm::DefinedFuncIndex; use failure::Error; use wasmtime_environ::{ModuleVmctxInfo, ValueLabelsRanges}; diff --git a/wasmtime-debug/src/write_debuginfo.rs b/wasmtime-debug/src/write_debuginfo.rs index 48b6b6a2d3..4a0583a2ae 100644 --- a/wasmtime-debug/src/write_debuginfo.rs +++ b/wasmtime-debug/src/write_debuginfo.rs @@ -1,9 +1,11 @@ +use alloc::string::String; +use alloc::vec::Vec; use gimli::write::{Address, Dwarf, EndianVec, Result, Sections, Writer}; use gimli::{RunTimeEndian, SectionId}; +use core::result; use faerie::artifact::{Decl, SectionKind}; use faerie::*; -use std::result; #[derive(Clone)] struct DebugReloc { diff --git a/wasmtime-environ/src/address_map.rs b/wasmtime-environ/src/address_map.rs index 8c3c53be80..b3aeafa997 100644 --- a/wasmtime-environ/src/address_map.rs +++ b/wasmtime-environ/src/address_map.rs @@ -1,11 +1,11 @@ //! Data structures to provide transformation of the source // addresses of a WebAssembly module into the native code. +use alloc::vec::Vec; use cranelift_codegen::ir; use cranelift_entity::PrimaryMap; use cranelift_wasm::DefinedFuncIndex; use serde::{Deserialize, Serialize}; -use std::vec::Vec; /// Single source location to generated address mapping. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] diff --git a/wasmtime-environ/src/cache.rs b/wasmtime-environ/src/cache.rs index 499fb4c141..27b1ff9f97 100644 --- a/wasmtime-environ/src/cache.rs +++ b/wasmtime-environ/src/cache.rs @@ -2,6 +2,7 @@ use crate::address_map::{ModuleAddressMap, ValueLabelsRanges}; use crate::compilation::{Compilation, Relocations, Traps}; use crate::module::Module; use crate::module_environ::FunctionBodyData; +use alloc::string::{String, ToString}; use core::hash::Hasher; use cranelift_codegen::{ir, isa}; use cranelift_entity::PrimaryMap; @@ -13,7 +14,6 @@ use sha2::{Digest, Sha256}; use std::fs; use std::io::Write; use std::path::{Path, PathBuf}; -use std::string::{String, ToString}; #[macro_use] // for tests mod config; diff --git a/wasmtime-environ/src/cache/config.rs b/wasmtime-environ/src/cache/config.rs index 4777a51d58..4487318052 100644 --- a/wasmtime-environ/src/cache/config.rs +++ b/wasmtime-environ/src/cache/config.rs @@ -1,6 +1,9 @@ //! Module for configuring the cache system. use super::worker; +use alloc::string::{String, ToString}; +use alloc::vec::Vec; +use core::time::Duration; use directories::ProjectDirs; use lazy_static::lazy_static; use log::{debug, error, trace, warn}; @@ -13,10 +16,7 @@ use std::fmt::Debug; use std::fs; use std::mem; use std::path::{Path, PathBuf}; -use std::string::{String, ToString}; use std::sync::atomic::{AtomicBool, Ordering}; -use std::time::Duration; -use std::vec::Vec; // wrapped, so we have named section in config, // also, for possible future compatibility diff --git a/wasmtime-environ/src/cache/config/tests.rs b/wasmtime-environ/src/cache/config/tests.rs index 7a9094a2ad..33c252611f 100644 --- a/wasmtime-environ/src/cache/config/tests.rs +++ b/wasmtime-environ/src/cache/config/tests.rs @@ -1,7 +1,7 @@ use super::CacheConfig; +use core::time::Duration; use std::fs; use std::path::PathBuf; -use std::time::Duration; use tempfile::{self, TempDir}; // note: config loading during validation creates cache directory to canonicalize its path, diff --git a/wasmtime-environ/src/cache/tests.rs b/wasmtime-environ/src/cache/tests.rs index ac4677e6e2..e1b006bf03 100644 --- a/wasmtime-environ/src/cache/tests.rs +++ b/wasmtime-environ/src/cache/tests.rs @@ -3,17 +3,17 @@ use super::*; use crate::address_map::{FunctionAddressMap, InstructionAddressMap}; use crate::compilation::{CodeAndJTOffsets, Relocation, RelocationTarget, TrapInformation}; use crate::module::{MemoryPlan, MemoryStyle, Module}; +use alloc::boxed::Box; +use alloc::vec::Vec; +use core::cmp::min; use cranelift_codegen::{binemit, ir, isa, settings, ValueLocRange}; use cranelift_entity::EntityRef; use cranelift_entity::{PrimaryMap, SecondaryMap}; use cranelift_wasm::{DefinedFuncIndex, FuncIndex, Global, GlobalInit, Memory, SignatureIndex}; use rand::rngs::SmallRng; use rand::{Rng, SeedableRng}; -use std::boxed::Box; -use std::cmp::min; use std::fs; use std::str::FromStr; -use std::vec::Vec; use target_lexicon::triple; // Since cache system is a global thing, each test needs to be run in seperate process. diff --git a/wasmtime-environ/src/cache/worker.rs b/wasmtime-environ/src/cache/worker.rs index 5a512dc4ca..469bccd8eb 100644 --- a/wasmtime-environ/src/cache/worker.rs +++ b/wasmtime-environ/src/cache/worker.rs @@ -6,10 +6,12 @@ //! Background tasks can be CPU intensive, but the worker thread has low priority. use super::{cache_config, fs_write_atomic, CacheConfig}; +use alloc::vec::Vec; +use core::cmp; +use core::time::Duration; use log::{debug, info, trace, warn}; use serde::{Deserialize, Serialize}; use spin::Once; -use std::cmp; use std::collections::HashMap; use std::ffi::OsStr; use std::fs; @@ -19,10 +21,8 @@ use std::sync::mpsc::{sync_channel, Receiver, SyncSender}; #[cfg(test)] use std::sync::{Arc, Condvar, Mutex}; use std::thread; -use std::time::Duration; #[cfg(not(test))] use std::time::SystemTime; -use std::vec::Vec; #[cfg(test)] use tests::system_time_stub::SystemTimeStub as SystemTime; diff --git a/wasmtime-environ/src/cache/worker/tests.rs b/wasmtime-environ/src/cache/worker/tests.rs index f1323fd7ef..b283eae527 100644 --- a/wasmtime-environ/src/cache/worker/tests.rs +++ b/wasmtime-environ/src/cache/worker/tests.rs @@ -1,6 +1,6 @@ use super::*; use crate::cache::config::tests::test_prolog; -use std::iter::repeat; +use core::iter::repeat; use std::process; // load_config! comes from crate::cache(::config::tests); diff --git a/wasmtime-environ/src/compilation.rs b/wasmtime-environ/src/compilation.rs index 7d5c936fc9..139c51fcf1 100644 --- a/wasmtime-environ/src/compilation.rs +++ b/wasmtime-environ/src/compilation.rs @@ -4,12 +4,12 @@ use crate::address_map::{ModuleAddressMap, ValueLabelsRanges}; use crate::module; use crate::module_environ::FunctionBodyData; +use alloc::vec::Vec; use cranelift_codegen::{binemit, ir, isa, CodegenError}; use cranelift_entity::PrimaryMap; use cranelift_wasm::{DefinedFuncIndex, FuncIndex, WasmError}; use serde::{Deserialize, Serialize}; use std::ops::Range; -use std::vec::Vec; /// Compiled machine code: body and jump table offsets. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] diff --git a/wasmtime-environ/src/cranelift.rs b/wasmtime-environ/src/cranelift.rs index 9468adb3c8..3857012d81 100644 --- a/wasmtime-environ/src/cranelift.rs +++ b/wasmtime-environ/src/cranelift.rs @@ -14,6 +14,7 @@ use crate::func_environ::{ }; use crate::module::Module; use crate::module_environ::FunctionBodyData; +use alloc::vec::Vec; use cranelift_codegen::binemit; use cranelift_codegen::ir; use cranelift_codegen::ir::ExternalName; @@ -22,7 +23,6 @@ use cranelift_codegen::Context; use cranelift_entity::PrimaryMap; use cranelift_wasm::{DefinedFuncIndex, FuncIndex, FuncTranslator}; use rayon::prelude::{IntoParallelRefIterator, ParallelIterator}; -use std::vec::Vec; /// Implementation of a relocation sink that just saves all the information for later pub struct RelocSink { diff --git a/wasmtime-environ/src/func_environ.rs b/wasmtime-environ/src/func_environ.rs index d0bdc98e09..2161ae4439 100644 --- a/wasmtime-environ/src/func_environ.rs +++ b/wasmtime-environ/src/func_environ.rs @@ -1,6 +1,7 @@ use crate::module::{MemoryPlan, MemoryStyle, Module, TableStyle}; use crate::vmoffsets::VMOffsets; use crate::WASM_PAGE_SIZE; +use alloc::vec::Vec; use core::clone::Clone; use core::convert::TryFrom; use cranelift_codegen::cursor::FuncCursor; @@ -17,7 +18,6 @@ use cranelift_wasm::{ }; #[cfg(feature = "lightbeam")] use cranelift_wasm::{DefinedFuncIndex, DefinedGlobalIndex, DefinedMemoryIndex, DefinedTableIndex}; -use std::vec::Vec; /// Compute an `ir::ExternalName` for a given wasm function index. pub fn get_func_name(func_index: FuncIndex) -> ir::ExternalName { diff --git a/wasmtime-environ/src/lib.rs b/wasmtime-environ/src/lib.rs index cd9db5063f..861d5404d5 100644 --- a/wasmtime-environ/src/lib.rs +++ b/wasmtime-environ/src/lib.rs @@ -24,14 +24,8 @@ clippy::use_self ) )] -#![no_std] -#[cfg(not(feature = "std"))] -#[macro_use] -extern crate alloc as std; -#[cfg(feature = "std")] -#[macro_use] -extern crate std; +extern crate alloc; #[macro_use] extern crate failure_derive; diff --git a/wasmtime-environ/src/module.rs b/wasmtime-environ/src/module.rs index bc7b33138f..88595230ad 100644 --- a/wasmtime-environ/src/module.rs +++ b/wasmtime-environ/src/module.rs @@ -2,6 +2,9 @@ use crate::module_environ::FunctionBodyData; use crate::tunables::Tunables; +use alloc::boxed::Box; +use alloc::string::String; +use alloc::vec::Vec; use core::hash::{Hash, Hasher}; use cranelift_codegen::ir; use cranelift_entity::{EntityRef, PrimaryMap}; @@ -10,9 +13,6 @@ use cranelift_wasm::{ GlobalIndex, Memory, MemoryIndex, SignatureIndex, Table, TableIndex, }; use indexmap::IndexMap; -use std::boxed::Box; -use std::string::String; -use std::vec::Vec; /// A WebAssembly table initializer. #[derive(Clone, Debug, Hash)] diff --git a/wasmtime-environ/src/module_environ.rs b/wasmtime-environ/src/module_environ.rs index c96a199ee8..3b42ff42d6 100644 --- a/wasmtime-environ/src/module_environ.rs +++ b/wasmtime-environ/src/module_environ.rs @@ -1,6 +1,9 @@ use crate::func_environ::FuncEnvironment; use crate::module::{Export, MemoryPlan, Module, TableElements, TablePlan}; use crate::tunables::Tunables; +use alloc::boxed::Box; +use alloc::string::String; +use alloc::vec::Vec; use core::convert::TryFrom; use cranelift_codegen::ir; use cranelift_codegen::ir::{AbiParam, ArgumentPurpose}; @@ -10,9 +13,6 @@ use cranelift_wasm::{ self, translate_module, DefinedFuncIndex, FuncIndex, Global, GlobalIndex, Memory, MemoryIndex, SignatureIndex, Table, TableIndex, WasmResult, }; -use std::boxed::Box; -use std::string::String; -use std::vec::Vec; /// Contains function data: byte code and its offset in the module. #[derive(Hash)] diff --git a/wasmtime-interface-types/Cargo.toml b/wasmtime-interface-types/Cargo.toml index 5bea175d3b..d5843c24c0 100644 --- a/wasmtime-interface-types/Cargo.toml +++ b/wasmtime-interface-types/Cargo.toml @@ -11,10 +11,10 @@ readme = "README.md" edition = "2018" [dependencies] -cranelift-codegen = "0.44.0" -failure = "0.1" +cranelift-codegen = { version = "0.44.0", default-features = false } +failure = { version = "0.1", default-features = false } walrus = "0.12.0" -wasmparser = "0.39.1" +wasmparser = { version = "0.39.1", default-features = false } wasm-webidl-bindings = "0.5.0" -wasmtime-jit = { path = '../wasmtime-jit' } -wasmtime-runtime = { path = '../wasmtime-runtime' } +wasmtime-jit = { path = '../wasmtime-jit', default-features = false } +wasmtime-runtime = { path = '../wasmtime-runtime', default-features = false } diff --git a/wasmtime-interface-types/src/lib.rs b/wasmtime-interface-types/src/lib.rs index 51e9f16c78..b393a862cc 100644 --- a/wasmtime-interface-types/src/lib.rs +++ b/wasmtime-interface-types/src/lib.rs @@ -7,11 +7,17 @@ #![deny(missing_docs)] +#[macro_use] +extern crate alloc; + +use alloc::boxed::Box; +use alloc::string::ToString; +use alloc::vec::Vec; +use core::convert::TryFrom; +use core::slice; +use core::str; use cranelift_codegen::ir; use failure::{bail, format_err, Error}; -use std::convert::TryFrom; -use std::slice; -use std::str; use wasm_webidl_bindings::ast; use wasmtime_jit::{ActionOutcome, Context, RuntimeValue}; use wasmtime_runtime::{Export, InstanceHandle}; diff --git a/wasmtime-interface-types/src/value.rs b/wasmtime-interface-types/src/value.rs index 48fd610c61..67fb206182 100644 --- a/wasmtime-interface-types/src/value.rs +++ b/wasmtime-interface-types/src/value.rs @@ -1,5 +1,6 @@ -use std::convert::TryFrom; -use std::fmt; +use alloc::string::{String, ToString}; +use core::convert::TryFrom; +use core::fmt; /// The set of all possible WebAssembly Interface Types #[derive(Debug, Clone)] diff --git a/wasmtime-jit/Cargo.toml b/wasmtime-jit/Cargo.toml index 2b000a0fad..324b698818 100644 --- a/wasmtime-jit/Cargo.toml +++ b/wasmtime-jit/Cargo.toml @@ -23,12 +23,12 @@ failure = { version = "0.1.3", default-features = false } failure_derive = { version = "0.1.3", default-features = false } target-lexicon = { version = "0.8.1", default-features = false } hashbrown = { version = "0.6.0", optional = true } -wasmparser = "0.39.1" +wasmparser = { version = "0.39.1", default-features = false } [features] default = ["std"] -std = ["cranelift-codegen/std", "cranelift-wasm/std", "wasmtime-environ/std"] -core = ["hashbrown/nightly", "cranelift-codegen/core", "cranelift-wasm/core", "wasmtime-environ/core"] +std = ["cranelift-codegen/std", "cranelift-wasm/std", "wasmtime-environ/std", "wasmtime-debug/std", "wasmparser/std"] +core = ["hashbrown/nightly", "cranelift-codegen/core", "cranelift-wasm/core", "wasmtime-environ/core", "wasmtime-debug/core", "wasmparser/core"] lightbeam = ["wasmtime-environ/lightbeam"] [badges] diff --git a/wasmtime-jit/src/action.rs b/wasmtime-jit/src/action.rs index 301c01091a..44306b9e84 100644 --- a/wasmtime-jit/src/action.rs +++ b/wasmtime-jit/src/action.rs @@ -2,11 +2,11 @@ use crate::compiler::Compiler; use crate::instantiate::SetupError; +use alloc::string::String; +use alloc::vec::Vec; use core::cmp::max; use core::{fmt, mem, ptr, slice}; use cranelift_codegen::ir; -use std::string::String; -use std::vec::Vec; use wasmtime_runtime::{wasmtime_call_trampoline, Export, InstanceHandle, VMInvokeArgument}; /// A runtime value. diff --git a/wasmtime-jit/src/code_memory.rs b/wasmtime-jit/src/code_memory.rs index 641577ad9d..48b86a6cda 100644 --- a/wasmtime-jit/src/code_memory.rs +++ b/wasmtime-jit/src/code_memory.rs @@ -1,10 +1,10 @@ //! Memory management for executable code. +use alloc::boxed::Box; +use alloc::string::String; +use alloc::vec::Vec; use core::{cmp, mem}; use region; -use std::boxed::Box; -use std::string::String; -use std::vec::Vec; use wasmtime_runtime::{Mmap, VMFunctionBody}; /// Memory manager for executable code. diff --git a/wasmtime-jit/src/compiler.rs b/wasmtime-jit/src/compiler.rs index 0cf7bf8625..7c472a3293 100644 --- a/wasmtime-jit/src/compiler.rs +++ b/wasmtime-jit/src/compiler.rs @@ -4,6 +4,9 @@ use super::HashMap; use crate::code_memory::CodeMemory; use crate::instantiate::SetupError; use crate::target_tunables::target_tunables; +use alloc::boxed::Box; +use alloc::string::String; +use alloc::vec::Vec; use core::convert::TryFrom; use cranelift_codegen::ir::InstBuilder; use cranelift_codegen::isa::{TargetFrontendConfig, TargetIsa}; @@ -12,9 +15,6 @@ use cranelift_codegen::{binemit, ir}; use cranelift_entity::{EntityRef, PrimaryMap}; use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext}; use cranelift_wasm::{DefinedFuncIndex, DefinedMemoryIndex}; -use std::boxed::Box; -use std::string::String; -use std::vec::Vec; use wasmtime_debug::{emit_debugsections_image, DebugInfoData}; use wasmtime_environ::{ Compilation, CompileError, Compiler as _C, FunctionBodyData, Module, ModuleVmctxInfo, diff --git a/wasmtime-jit/src/context.rs b/wasmtime-jit/src/context.rs index 22b2b94bae..8ab7454ce8 100644 --- a/wasmtime-jit/src/context.rs +++ b/wasmtime-jit/src/context.rs @@ -1,15 +1,15 @@ use crate::action::{get, inspect_memory, invoke}; +use crate::HashMap; use crate::{ instantiate, ActionError, ActionOutcome, CompilationStrategy, Compiler, InstanceHandle, Namespace, RuntimeValue, SetupError, }; +use alloc::boxed::Box; +use alloc::rc::Rc; +use alloc::string::{String, ToString}; +use core::cell::RefCell; +use core::{fmt, str}; use cranelift_codegen::isa::TargetIsa; -use std::boxed::Box; -use std::cell::RefCell; -use std::collections::HashMap; -use std::rc::Rc; -use std::string::{String, ToString}; -use std::{fmt, str}; use wasmparser::{validate, OperatorValidatorConfig, ValidatingParserConfig}; /// Indicates an unknown instance was specified. diff --git a/wasmtime-jit/src/instantiate.rs b/wasmtime-jit/src/instantiate.rs index a35daf74b2..72bfc16e3f 100644 --- a/wasmtime-jit/src/instantiate.rs +++ b/wasmtime-jit/src/instantiate.rs @@ -7,14 +7,15 @@ use super::HashMap; use crate::compiler::Compiler; use crate::link::link_module; use crate::resolver::Resolver; +use alloc::boxed::Box; +use alloc::rc::Rc; +use alloc::string::String; +use alloc::vec::Vec; use core::cell::RefCell; use cranelift_entity::{BoxedSlice, PrimaryMap}; use cranelift_wasm::{DefinedFuncIndex, SignatureIndex}; -use std::boxed::Box; +#[cfg(feature = "std")] use std::io::Write; -use std::rc::Rc; -use std::string::String; -use std::vec::Vec; use wasmtime_debug::read_debuginfo; use wasmtime_environ::{ CompileError, DataInitializer, DataInitializerLocation, Module, ModuleEnvironment, @@ -117,6 +118,7 @@ impl<'data> RawCompiledModule<'data> { // Make all code compiled thus far executable. compiler.publish_compiled_code(); + #[cfg(feature = "std")] let dbg_jit_registration = if let Some(img) = dbg_image { let mut bytes = Vec::new(); bytes.write_all(&img).expect("all written"); diff --git a/wasmtime-jit/src/lib.rs b/wasmtime-jit/src/lib.rs index bc16699429..7d3ab62dad 100644 --- a/wasmtime-jit/src/lib.rs +++ b/wasmtime-jit/src/lib.rs @@ -21,19 +21,14 @@ clippy::use_self ) )] -#![no_std] + +#[macro_use] +extern crate alloc; #[cfg(not(feature = "std"))] -#[macro_use] -extern crate alloc as std; +use hashbrown::{hash_map, HashMap, HashSet}; #[cfg(feature = "std")] -#[macro_use] -extern crate std; - -#[cfg(not(feature = "std"))] -use hashbrown::{hash_map, HashMap}; -#[cfg(feature = "std")] -use std::collections::{hash_map, HashMap}; +use std::collections::{hash_map, HashMap, HashSet}; #[macro_use] extern crate failure_derive; diff --git a/wasmtime-jit/src/link.rs b/wasmtime-jit/src/link.rs index dab57be99e..323b07d2be 100644 --- a/wasmtime-jit/src/link.rs +++ b/wasmtime-jit/src/link.rs @@ -1,13 +1,13 @@ //! Linking for JIT-compiled code. use crate::resolver::Resolver; +use crate::HashSet; +use alloc::vec::Vec; use core::ptr::write_unaligned; use cranelift_codegen::binemit::Reloc; use cranelift_codegen::ir::JumpTableOffsets; use cranelift_entity::PrimaryMap; use cranelift_wasm::{DefinedFuncIndex, Global, GlobalInit, Memory, Table, TableElementType}; -use std::collections::HashSet; -use std::vec::Vec; use wasmtime_environ::{ MemoryPlan, MemoryStyle, Module, Relocation, RelocationTarget, Relocations, TablePlan, }; diff --git a/wasmtime-jit/src/namespace.rs b/wasmtime-jit/src/namespace.rs index 558a6285e2..acddc6da10 100644 --- a/wasmtime-jit/src/namespace.rs +++ b/wasmtime-jit/src/namespace.rs @@ -4,7 +4,7 @@ use super::HashMap; use crate::resolver::Resolver; -use std::string::String; +use alloc::string::String; use wasmtime_runtime::{Export, InstanceHandle}; /// A namespace containing instances keyed by name. diff --git a/wasmtime-obj/src/context.rs b/wasmtime-obj/src/context.rs index f5bf37633a..f16ff1b2a7 100644 --- a/wasmtime-obj/src/context.rs +++ b/wasmtime-obj/src/context.rs @@ -1,9 +1,11 @@ +use alloc::boxed::Box; +use alloc::vec::Vec; +use core::ptr; use cranelift_codegen::isa::TargetFrontendConfig; use cranelift_entity::EntityRef; use cranelift_wasm::GlobalInit; use std::collections::hash_map::Entry; use std::collections::HashMap; -use std::ptr; use wasmtime_environ::{Module, TargetSharedSignatureIndex, VMOffsets}; pub struct TableRelocation { @@ -28,7 +30,7 @@ pub fn layout_vmcontext( let target_index = match signature_registry.entry(sig) { Entry::Occupied(o) => *o.get(), Entry::Vacant(v) => { - assert!(signature_registry_len <= ::std::u32::MAX as usize); + assert!(signature_registry_len <= ::core::u32::MAX as usize); let id = TargetSharedSignatureIndex::new(signature_registry_len as u32); signature_registry_len += 1; *v.insert(id) diff --git a/wasmtime-obj/src/data_segment.rs b/wasmtime-obj/src/data_segment.rs index c4ce8862cd..6554c9c245 100644 --- a/wasmtime-obj/src/data_segment.rs +++ b/wasmtime-obj/src/data_segment.rs @@ -1,3 +1,5 @@ +use alloc::string::String; +use alloc::vec::Vec; use faerie::{Artifact, Decl}; use wasmtime_environ::DataInitializer; diff --git a/wasmtime-obj/src/function.rs b/wasmtime-obj/src/function.rs index 59d3fcf049..45f2e95dac 100644 --- a/wasmtime-obj/src/function.rs +++ b/wasmtime-obj/src/function.rs @@ -1,3 +1,4 @@ +use alloc::string::String; use cranelift_codegen::settings; use cranelift_codegen::settings::Configurable; use cranelift_entity::EntityRef; diff --git a/wasmtime-obj/src/lib.rs b/wasmtime-obj/src/lib.rs index f4d9dc2d00..a95af9e66a 100644 --- a/wasmtime-obj/src/lib.rs +++ b/wasmtime-obj/src/lib.rs @@ -26,6 +26,8 @@ ) )] +extern crate alloc; + mod context; mod data_segment; mod function; diff --git a/wasmtime-obj/src/module.rs b/wasmtime-obj/src/module.rs index d35e652251..23fbf0b07b 100644 --- a/wasmtime-obj/src/module.rs +++ b/wasmtime-obj/src/module.rs @@ -2,6 +2,7 @@ use crate::context::layout_vmcontext; use crate::data_segment::{declare_data_segment, emit_data_segment}; use crate::function::{declare_functions, emit_functions}; use crate::table::{declare_table, emit_table}; +use alloc::string::String; use cranelift_codegen::isa::TargetFrontendConfig; use faerie::{Artifact, Decl, Link}; use wasmtime_environ::{Compilation, DataInitializer, Module, Relocations}; diff --git a/wasmtime-obj/src/table.rs b/wasmtime-obj/src/table.rs index 269e50927c..0fced2d5c8 100644 --- a/wasmtime-obj/src/table.rs +++ b/wasmtime-obj/src/table.rs @@ -1,3 +1,5 @@ +use alloc::string::String; +use alloc::vec::Vec; use faerie::{Artifact, Decl}; /// Declares data segment symbol diff --git a/wasmtime-runtime/Cargo.toml b/wasmtime-runtime/Cargo.toml index 82a7685112..63774d01e5 100644 --- a/wasmtime-runtime/Cargo.toml +++ b/wasmtime-runtime/Cargo.toml @@ -23,6 +23,8 @@ memoffset = "0.5.1" failure = { version = "0.1.3", default-features = false } failure_derive = { version = "0.1.3", default-features = false } indexmap = "1.0.2" +hashbrown = { version = "0.6.0", optional = true } +spin = { version = "0.5.2", optional = true } [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "0.3.7", features = ["winbase", "memoryapi"] } @@ -33,6 +35,7 @@ cc = "1.0" [features] default = ["std"] std = ["cranelift-codegen/std", "cranelift-wasm/std", "wasmtime-environ/std"] +core = ["hashbrown/nightly", "cranelift-codegen/core", "cranelift-wasm/core", "wasmtime-environ/core", "spin"] [badges] maintenance = { status = "experimental" } diff --git a/wasmtime-runtime/src/imports.rs b/wasmtime-runtime/src/imports.rs index 082f799ae6..3e670eb2cc 100644 --- a/wasmtime-runtime/src/imports.rs +++ b/wasmtime-runtime/src/imports.rs @@ -1,8 +1,8 @@ use crate::instance::InstanceHandle; use crate::vmcontext::{VMFunctionImport, VMGlobalImport, VMMemoryImport, VMTableImport}; +use crate::HashSet; use cranelift_entity::{BoxedSlice, PrimaryMap}; use cranelift_wasm::{FuncIndex, GlobalIndex, MemoryIndex, TableIndex}; -use std::collections::HashSet; /// Resolved import pointers. #[derive(Clone)] diff --git a/wasmtime-runtime/src/instance.rs b/wasmtime-runtime/src/instance.rs index 603851ac9c..40c8e33d22 100644 --- a/wasmtime-runtime/src/instance.rs +++ b/wasmtime-runtime/src/instance.rs @@ -15,9 +15,15 @@ use crate::vmcontext::{ VMGlobalDefinition, VMGlobalImport, VMMemoryDefinition, VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport, }; +use crate::{HashMap, HashSet}; +use alloc::borrow::ToOwned; +use alloc::boxed::Box; +use alloc::rc::Rc; +use alloc::string::{String, ToString}; use core::any::Any; use core::borrow::Borrow; use core::cell::RefCell; +use core::convert::TryFrom; use core::slice; use core::{mem, ptr}; use cranelift_entity::EntityRef; @@ -27,12 +33,6 @@ use cranelift_wasm::{ GlobalIndex, GlobalInit, MemoryIndex, SignatureIndex, TableIndex, }; use indexmap; -use std::borrow::ToOwned; -use std::boxed::Box; -use std::collections::{HashMap, HashSet}; -use std::convert::TryFrom; -use std::rc::Rc; -use std::string::{String, ToString}; use wasmtime_environ::{DataInitializer, Module, TableElements, VMOffsets}; fn signature_id( @@ -613,9 +613,9 @@ impl Instance { } pub(crate) fn lookup_global_export(&self, field: &str) -> Option { - let cell: &RefCell>> = + let cell: &RefCell>> = self.global_exports.borrow(); - let map: &mut HashMap> = + let map: &mut HashMap> = &mut cell.borrow_mut(); if let Some(Some(export)) = map.get(field) { return Some(export.clone()); @@ -790,10 +790,10 @@ impl InstanceHandle { // Collect the exports for the global export map. for (field, decl) in &instance.module.exports { - use std::collections::hash_map::Entry::*; - let cell: &RefCell>> = + use crate::hash_map::Entry::*; + let cell: &RefCell>> = instance.global_exports.borrow(); - let map: &mut HashMap> = + let map: &mut HashMap> = &mut cell.borrow_mut(); match map.entry(field.to_string()) { Vacant(entry) => { diff --git a/wasmtime-runtime/src/jit_int.rs b/wasmtime-runtime/src/jit_int.rs index 22b70d39d4..c83709b341 100644 --- a/wasmtime-runtime/src/jit_int.rs +++ b/wasmtime-runtime/src/jit_int.rs @@ -2,8 +2,9 @@ //! the __jit_debug_register_code() and __jit_debug_descriptor to register //! or unregister generated object images with debuggers. -use std::boxed::Box; -use std::ptr; +use alloc::boxed::Box; +use alloc::vec::Vec; +use core::ptr; #[repr(C)] struct JITCodeEntry { @@ -40,7 +41,7 @@ extern "C" fn __jit_debug_register_code() { // Hack to not allow inlining even when Rust wants to do it in release mode. let x = 3; unsafe { - std::ptr::read_volatile(&x); + core::ptr::read_volatile(&x); } } diff --git a/wasmtime-runtime/src/lib.rs b/wasmtime-runtime/src/lib.rs index ba11084596..f0e9dc4d56 100644 --- a/wasmtime-runtime/src/lib.rs +++ b/wasmtime-runtime/src/lib.rs @@ -21,6 +21,7 @@ clippy::use_self ) )] +#![cfg_attr(not(feature = "std"), no_std)] #[macro_use] extern crate lazy_static; @@ -28,6 +29,7 @@ extern crate lazy_static; extern crate memoffset; #[macro_use] extern crate failure_derive; +extern crate alloc; mod export; mod imports; @@ -59,5 +61,15 @@ pub use crate::vmcontext::{ VMTableDefinition, VMTableImport, }; +#[cfg(not(feature = "std"))] +use hashbrown::{hash_map, HashMap, HashSet}; +#[cfg(feature = "std")] +use std::collections::{hash_map, HashMap, HashSet}; + +#[cfg(not(feature = "std"))] +use spin::{RwLock, RwLockReadGuard, RwLockWriteGuard}; +#[cfg(feature = "std")] +use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}; + /// Version number of this crate. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/wasmtime-runtime/src/memory.rs b/wasmtime-runtime/src/memory.rs index 7957c0e066..121cbc34a2 100644 --- a/wasmtime-runtime/src/memory.rs +++ b/wasmtime-runtime/src/memory.rs @@ -4,8 +4,8 @@ use crate::mmap::Mmap; use crate::vmcontext::VMMemoryDefinition; -use std::convert::TryFrom; -use std::string::String; +use alloc::string::String; +use core::convert::TryFrom; use wasmtime_environ::{MemoryPlan, MemoryStyle, WASM_MAX_PAGES, WASM_PAGE_SIZE}; /// A linear memory instance. diff --git a/wasmtime-runtime/src/mmap.rs b/wasmtime-runtime/src/mmap.rs index 7cd024e905..1e15cd2dc3 100644 --- a/wasmtime-runtime/src/mmap.rs +++ b/wasmtime-runtime/src/mmap.rs @@ -1,14 +1,14 @@ //! Low-level abstraction for allocating and managing zero-filled pages //! of memory. +use alloc::string::{String, ToString}; +use alloc::vec::Vec; use core::ptr; use core::slice; use errno; #[cfg(not(target_os = "windows"))] use libc; use region; -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 { diff --git a/wasmtime-runtime/src/sig_registry.rs b/wasmtime-runtime/src/sig_registry.rs index 77196f392e..dfa59da845 100644 --- a/wasmtime-runtime/src/sig_registry.rs +++ b/wasmtime-runtime/src/sig_registry.rs @@ -2,9 +2,9 @@ //! signature checking. use crate::vmcontext::VMSharedSignatureIndex; +use crate::{hash_map, HashMap}; +use core::convert::TryFrom; use cranelift_codegen::ir; -use std::collections::{hash_map, HashMap}; -use std::convert::TryFrom; /// WebAssembly requires that the caller and callee signatures in an indirect /// call must match. To implement this efficiently, keep a registry of all @@ -29,11 +29,11 @@ impl SignatureRegistry { match self.signature_hash.entry(sig.clone()) { hash_map::Entry::Occupied(entry) => *entry.get(), hash_map::Entry::Vacant(entry) => { - // Keep `signature_hash` len under 2**32 -- VMSharedSignatureIndex::new(std::u32::MAX) + // Keep `signature_hash` len under 2**32 -- VMSharedSignatureIndex::new(core::u32::MAX) // is reserved for VMSharedSignatureIndex::default(). debug_assert!( - len < std::u32::MAX as usize, - "Invariant check: signature_hash.len() < std::u32::MAX" + len < core::u32::MAX as usize, + "Invariant check: signature_hash.len() < core::u32::MAX" ); let sig_id = VMSharedSignatureIndex::new(u32::try_from(len).unwrap()); entry.insert(sig_id); diff --git a/wasmtime-runtime/src/signalhandlers.rs b/wasmtime-runtime/src/signalhandlers.rs index a383e54995..e0f1031b4d 100644 --- a/wasmtime-runtime/src/signalhandlers.rs +++ b/wasmtime-runtime/src/signalhandlers.rs @@ -5,9 +5,9 @@ #![allow(non_snake_case)] use crate::vmcontext::VMContext; +use crate::RwLock; use core::borrow::{Borrow, BorrowMut}; use core::cell::Cell; -use std::sync::RwLock; #[derive(Default)] struct TrapContext { diff --git a/wasmtime-runtime/src/table.rs b/wasmtime-runtime/src/table.rs index b8c9c3e831..06c3bb0030 100644 --- a/wasmtime-runtime/src/table.rs +++ b/wasmtime-runtime/src/table.rs @@ -3,9 +3,9 @@ //! `Table` is to WebAssembly tables what `LinearMemory` is to WebAssembly linear memories. use crate::vmcontext::{VMCallerCheckedAnyfunc, VMTableDefinition}; +use alloc::vec::Vec; +use core::convert::{TryFrom, TryInto}; use cranelift_wasm::TableElementType; -use std::convert::{TryFrom, TryInto}; -use std::vec::Vec; use wasmtime_environ::{TablePlan, TableStyle}; /// A table instance. @@ -25,7 +25,7 @@ impl Table { } }; assert!( - plan.table.minimum <= std::u32::MAX, + plan.table.minimum <= core::u32::MAX, "Invariant check: vec.len() <= u32::MAX" ); match plan.style { @@ -60,7 +60,7 @@ impl Table { } }; assert!( - new_len <= std::u32::MAX, + new_len <= core::u32::MAX, "Invariant check: vec.len() <= u32::MAX" ); self.vec.resize( diff --git a/wasmtime-runtime/src/trap_registry.rs b/wasmtime-runtime/src/trap_registry.rs index b62d58392b..33bcf2b0e3 100644 --- a/wasmtime-runtime/src/trap_registry.rs +++ b/wasmtime-runtime/src/trap_registry.rs @@ -1,7 +1,7 @@ +use crate::HashMap; +use crate::{RwLock, RwLockReadGuard, RwLockWriteGuard}; use cranelift_codegen::ir; use lazy_static::lazy_static; -use std::collections::HashMap; -use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}; lazy_static! { static ref REGISTRY: RwLock = RwLock::new(TrapRegistry::default()); diff --git a/wasmtime-runtime/src/traphandlers.rs b/wasmtime-runtime/src/traphandlers.rs index c3b4ab84e2..8c8b32b7e4 100644 --- a/wasmtime-runtime/src/traphandlers.rs +++ b/wasmtime-runtime/src/traphandlers.rs @@ -4,10 +4,10 @@ use crate::trap_registry::get_trap_registry; use crate::trap_registry::TrapDescription; use crate::vmcontext::{VMContext, VMFunctionBody}; +use alloc::string::{String, ToString}; use core::cell::Cell; use core::ptr; use cranelift_codegen::ir; -use std::string::String; extern "C" { fn WasmtimeCallTrampoline( diff --git a/wasmtime-wasi-c/src/instantiate.rs b/wasmtime-wasi-c/src/instantiate.rs index 991aaaa50a..5df40a33d1 100644 --- a/wasmtime-wasi-c/src/instantiate.rs +++ b/wasmtime-wasi-c/src/instantiate.rs @@ -2,17 +2,17 @@ use crate::host::{ argv_environ_init, argv_environ_values, fd_prestats, fd_prestats_init, fd_prestats_insert, fd_table, fd_table_init, fd_table_insert_existing, }; +use alloc::rc::Rc; +use core::cell::RefCell; use cranelift_codegen::ir::types; use cranelift_codegen::{ir, isa}; use cranelift_entity::PrimaryMap; use cranelift_wasm::DefinedFuncIndex; -use std::cell::RefCell; use std::collections::HashMap; use std::ffi::CString; use std::fs::File; use std::mem; use std::os::unix::io::AsRawFd; -use std::rc::Rc; use syscalls; use target_lexicon::HOST; use wasmtime_environ::{translate_signature, Export, Module}; diff --git a/wasmtime-wasi-c/src/syscalls.rs b/wasmtime-wasi-c/src/syscalls.rs index 66743c05e9..77dd18db01 100644 --- a/wasmtime-wasi-c/src/syscalls.rs +++ b/wasmtime-wasi-c/src/syscalls.rs @@ -1,8 +1,8 @@ use crate::host::{argv_environ_values, fd_prestats, fd_table}; use crate::instantiate::WASIState; +use core::convert::TryFrom; use cranelift_codegen::ir::types::{Type, I32, I64}; use host; -use std::convert::TryFrom; use std::{mem, ptr, slice, str}; use translate::*; use wasm32; diff --git a/wasmtime-wasi-c/src/translate.rs b/wasmtime-wasi-c/src/translate.rs index d3dd1007c3..ccc78c8f00 100644 --- a/wasmtime-wasi-c/src/translate.rs +++ b/wasmtime-wasi-c/src/translate.rs @@ -1,5 +1,5 @@ +use core::convert::TryFrom; use host; -use std::convert::TryFrom; use std::mem::{align_of, size_of, zeroed}; use std::slice; use wasm32; diff --git a/wasmtime-wasi-c/src/wasm32.rs b/wasmtime-wasi-c/src/wasm32.rs index 8847674ce8..c674e21cfe 100644 --- a/wasmtime-wasi-c/src/wasm32.rs +++ b/wasmtime-wasi-c/src/wasm32.rs @@ -107,7 +107,7 @@ fn bindgen_test_layout_fsid_t() { concat!("Alignment of ", stringify!(fsid_t)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).__val as *const _ as usize }, + unsafe { &(*(::core::ptr::null::())).__val as *const _ as usize }, 0usize, concat!( "Offset of field: ", @@ -166,7 +166,7 @@ fn bindgen_test_layout_wasi_dirent_t() { concat!("Size of: ", stringify!(__wasi_dirent_t)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_next as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_dirent_t>())).d_next as *const _ as usize }, 0usize, concat!( "Offset of field: ", @@ -176,7 +176,7 @@ fn bindgen_test_layout_wasi_dirent_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_ino as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_dirent_t>())).d_ino as *const _ as usize }, 8usize, concat!( "Offset of field: ", @@ -186,7 +186,7 @@ fn bindgen_test_layout_wasi_dirent_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_namlen as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_dirent_t>())).d_namlen as *const _ as usize }, 16usize, concat!( "Offset of field: ", @@ -196,7 +196,7 @@ fn bindgen_test_layout_wasi_dirent_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_type as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_dirent_t>())).d_type as *const _ as usize }, 20usize, concat!( "Offset of field: ", @@ -248,7 +248,7 @@ fn bindgen_test_layout___wasi_event_t___wasi_event_u___wasi_event_u_fd_readwrite ); assert_eq!( unsafe { - &(*(::std::ptr::null::<__wasi_event_t___wasi_event_u___wasi_event_u_fd_readwrite_t>())) + &(*(::core::ptr::null::<__wasi_event_t___wasi_event_u___wasi_event_u_fd_readwrite_t>())) .nbytes as *const _ as usize }, 0usize, @@ -261,7 +261,7 @@ fn bindgen_test_layout___wasi_event_t___wasi_event_u___wasi_event_u_fd_readwrite ); assert_eq!( unsafe { - &(*(::std::ptr::null::<__wasi_event_t___wasi_event_u___wasi_event_u_fd_readwrite_t>())) + &(*(::core::ptr::null::<__wasi_event_t___wasi_event_u___wasi_event_u_fd_readwrite_t>())) .flags as *const _ as usize }, 8usize, @@ -287,7 +287,7 @@ fn bindgen_test_layout___wasi_event_t___wasi_event_u() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::<__wasi_event_t___wasi_event_u>())).fd_readwrite as *const _ + &(*(::core::ptr::null::<__wasi_event_t___wasi_event_u>())).fd_readwrite as *const _ as usize }, 0usize, @@ -312,7 +312,7 @@ fn bindgen_test_layout___wasi_event_t() { concat!("Alignment of ", stringify!(__wasi_event_t)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).userdata as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_event_t>())).userdata as *const _ as usize }, 0usize, concat!( "Offset of field: ", @@ -322,7 +322,7 @@ fn bindgen_test_layout___wasi_event_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).error as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_event_t>())).error as *const _ as usize }, 8usize, concat!( "Offset of field: ", @@ -332,7 +332,7 @@ fn bindgen_test_layout___wasi_event_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).type_ as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_event_t>())).type_ as *const _ as usize }, 10usize, concat!( "Offset of field: ", @@ -342,7 +342,7 @@ fn bindgen_test_layout___wasi_event_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).u as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_event_t>())).u as *const _ as usize }, 16usize, concat!( "Offset of field: ", @@ -388,7 +388,7 @@ fn bindgen_test_layout___wasi_prestat_t___wasi_prestat_u___wasi_prestat_u_dir_t( ); assert_eq!( unsafe { - &(*(::std::ptr::null::<__wasi_prestat_t___wasi_prestat_u___wasi_prestat_u_dir_t>())) + &(*(::core::ptr::null::<__wasi_prestat_t___wasi_prestat_u___wasi_prestat_u_dir_t>())) .pr_name_len as *const _ as usize }, 0usize, @@ -417,7 +417,7 @@ fn bindgen_test_layout___wasi_prestat_t___wasi_prestat_u() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::<__wasi_prestat_t___wasi_prestat_u>())).dir as *const _ as usize + &(*(::core::ptr::null::<__wasi_prestat_t___wasi_prestat_u>())).dir as *const _ as usize }, 0usize, concat!( @@ -441,7 +441,7 @@ fn bindgen_test_layout___wasi_prestat_t() { concat!("Alignment of ", stringify!(__wasi_prestat_t)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_prestat_t>())).pr_type as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_prestat_t>())).pr_type as *const _ as usize }, 0usize, concat!( "Offset of field: ", @@ -451,7 +451,7 @@ fn bindgen_test_layout___wasi_prestat_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_prestat_t>())).u as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_prestat_t>())).u as *const _ as usize }, 4usize, concat!( "Offset of field: ", @@ -488,7 +488,7 @@ fn bindgen_test_layout_wasi_event_t__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::<__wasi_event_t__bindgen_ty_1__bindgen_ty_1>())).nbytes + &(*(::core::ptr::null::<__wasi_event_t__bindgen_ty_1__bindgen_ty_1>())).nbytes as *const _ as usize }, 0usize, @@ -501,8 +501,8 @@ fn bindgen_test_layout_wasi_event_t__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::<__wasi_event_t__bindgen_ty_1__bindgen_ty_1>())).flags as *const _ - as usize + &(*(::core::ptr::null::<__wasi_event_t__bindgen_ty_1__bindgen_ty_1>())).flags + as *const _ as usize }, 8usize, concat!( @@ -540,7 +540,7 @@ fn bindgen_test_layout_wasi_event_t__bindgen_ty_1__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::<__wasi_event_t__bindgen_ty_1__bindgen_ty_2>())).signal + &(*(::core::ptr::null::<__wasi_event_t__bindgen_ty_1__bindgen_ty_2>())).signal as *const _ as usize }, 0usize, @@ -553,7 +553,7 @@ fn bindgen_test_layout_wasi_event_t__bindgen_ty_1__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::<__wasi_event_t__bindgen_ty_1__bindgen_ty_2>())).exitcode + &(*(::core::ptr::null::<__wasi_event_t__bindgen_ty_1__bindgen_ty_2>())).exitcode as *const _ as usize }, 4usize, @@ -575,7 +575,7 @@ fn bindgen_test_layout_wasi_event_t__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::<__wasi_event_t__bindgen_ty_1>())).fd_readwrite as *const _ + &(*(::core::ptr::null::<__wasi_event_t__bindgen_ty_1>())).fd_readwrite as *const _ as usize }, 0usize, @@ -595,7 +595,7 @@ fn bindgen_test_layout_wasi_event_t() { concat!("Size of: ", stringify!(__wasi_event_t)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).userdata as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_event_t>())).userdata as *const _ as usize }, 0usize, concat!( "Offset of field: ", @@ -605,7 +605,7 @@ fn bindgen_test_layout_wasi_event_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).error as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_event_t>())).error as *const _ as usize }, 8usize, concat!( "Offset of field: ", @@ -615,7 +615,7 @@ fn bindgen_test_layout_wasi_event_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).type_ as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_event_t>())).type_ as *const _ as usize }, 10usize, concat!( "Offset of field: ", @@ -642,7 +642,7 @@ fn bindgen_test_layout_wasi_fdstat_t() { concat!("Size of: ", stringify!(__wasi_fdstat_t)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_filetype as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_fdstat_t>())).fs_filetype as *const _ as usize }, 0usize, concat!( "Offset of field: ", @@ -652,7 +652,7 @@ fn bindgen_test_layout_wasi_fdstat_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_flags as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_fdstat_t>())).fs_flags as *const _ as usize }, 2usize, concat!( "Offset of field: ", @@ -662,7 +662,7 @@ fn bindgen_test_layout_wasi_fdstat_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_rights_base as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_fdstat_t>())).fs_rights_base as *const _ as usize }, 8usize, concat!( "Offset of field: ", @@ -673,7 +673,7 @@ fn bindgen_test_layout_wasi_fdstat_t() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_rights_inheriting as *const _ as usize + &(*(::core::ptr::null::<__wasi_fdstat_t>())).fs_rights_inheriting as *const _ as usize }, 16usize, concat!( @@ -704,7 +704,7 @@ fn bindgen_test_layout_wasi_filestat_t() { concat!("Size of: ", stringify!(__wasi_filestat_t)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).st_dev as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_filestat_t>())).st_dev as *const _ as usize }, 0usize, concat!( "Offset of field: ", @@ -714,7 +714,7 @@ fn bindgen_test_layout_wasi_filestat_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).st_ino as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_filestat_t>())).st_ino as *const _ as usize }, 8usize, concat!( "Offset of field: ", @@ -724,7 +724,7 @@ fn bindgen_test_layout_wasi_filestat_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).st_filetype as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_filestat_t>())).st_filetype as *const _ as usize }, 16usize, concat!( "Offset of field: ", @@ -734,7 +734,7 @@ fn bindgen_test_layout_wasi_filestat_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).st_nlink as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_filestat_t>())).st_nlink as *const _ as usize }, 20usize, concat!( "Offset of field: ", @@ -744,7 +744,7 @@ fn bindgen_test_layout_wasi_filestat_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).st_size as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_filestat_t>())).st_size as *const _ as usize }, 24usize, concat!( "Offset of field: ", @@ -754,7 +754,7 @@ fn bindgen_test_layout_wasi_filestat_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).st_atim as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_filestat_t>())).st_atim as *const _ as usize }, 32usize, concat!( "Offset of field: ", @@ -764,7 +764,7 @@ fn bindgen_test_layout_wasi_filestat_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).st_mtim as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_filestat_t>())).st_mtim as *const _ as usize }, 40usize, concat!( "Offset of field: ", @@ -774,7 +774,7 @@ fn bindgen_test_layout_wasi_filestat_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).st_ctim as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_filestat_t>())).st_ctim as *const _ as usize }, 48usize, concat!( "Offset of field: ", @@ -803,7 +803,7 @@ fn bindgen_test_layout_wasi_ciovec_t() { concat!("Alignment of ", stringify!(__wasi_ciovec_t)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_ciovec_t>())).buf as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_ciovec_t>())).buf as *const _ as usize }, 0usize, concat!( "Offset of field: ", @@ -813,7 +813,7 @@ fn bindgen_test_layout_wasi_ciovec_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_ciovec_t>())).buf_len as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_ciovec_t>())).buf_len as *const _ as usize }, 4usize, concat!( "Offset of field: ", @@ -842,7 +842,7 @@ fn bindgen_test_layout_wasi_iovec_t() { concat!("Alignment of ", stringify!(__wasi_iovec_t)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_iovec_t>())).buf as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_iovec_t>())).buf as *const _ as usize }, 0usize, concat!( "Offset of field: ", @@ -852,7 +852,7 @@ fn bindgen_test_layout_wasi_iovec_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_iovec_t>())).buf_len as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_iovec_t>())).buf_len as *const _ as usize }, 4usize, concat!( "Offset of field: ", @@ -913,7 +913,7 @@ fn bindgen_test_layout___wasi_subscription_t___wasi_subscription_u___wasi_subscr ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + &(*(::core::ptr::null::< __wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_clock_t, >())) .identifier as *const _ as usize @@ -928,7 +928,7 @@ fn bindgen_test_layout___wasi_subscription_t___wasi_subscription_u___wasi_subscr ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + &(*(::core::ptr::null::< __wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_clock_t, >())) .clock_id as *const _ as usize @@ -943,7 +943,7 @@ fn bindgen_test_layout___wasi_subscription_t___wasi_subscription_u___wasi_subscr ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + &(*(::core::ptr::null::< __wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_clock_t, >())) .timeout as *const _ as usize @@ -958,7 +958,7 @@ fn bindgen_test_layout___wasi_subscription_t___wasi_subscription_u___wasi_subscr ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + &(*(::core::ptr::null::< __wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_clock_t, >())) .precision as *const _ as usize @@ -973,7 +973,7 @@ fn bindgen_test_layout___wasi_subscription_t___wasi_subscription_u___wasi_subscr ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + &(*(::core::ptr::null::< __wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_clock_t, >())) .flags as *const _ as usize @@ -1021,7 +1021,7 @@ fn bindgen_test_layout___wasi_subscription_t___wasi_subscription_u___wasi_subscr ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + &(*(::core::ptr::null::< __wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_fd_readwrite_t, >())) .fd as *const _ as usize @@ -1057,7 +1057,7 @@ fn bindgen_test_layout___wasi_subscription_t___wasi_subscription_u() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::<__wasi_subscription_t___wasi_subscription_u>())).clock + &(*(::core::ptr::null::<__wasi_subscription_t___wasi_subscription_u>())).clock as *const _ as usize }, 0usize, @@ -1070,7 +1070,7 @@ fn bindgen_test_layout___wasi_subscription_t___wasi_subscription_u() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::<__wasi_subscription_t___wasi_subscription_u>())).fd_readwrite + &(*(::core::ptr::null::<__wasi_subscription_t___wasi_subscription_u>())).fd_readwrite as *const _ as usize }, 0usize, @@ -1095,7 +1095,7 @@ fn bindgen_test_layout___wasi_subscription_t() { concat!("Alignment of ", stringify!(__wasi_subscription_t)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_subscription_t>())).userdata as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_subscription_t>())).userdata as *const _ as usize }, 0usize, concat!( "Offset of field: ", @@ -1105,7 +1105,7 @@ fn bindgen_test_layout___wasi_subscription_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_subscription_t>())).type_ as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_subscription_t>())).type_ as *const _ as usize }, 8usize, concat!( "Offset of field: ", @@ -1115,7 +1115,7 @@ fn bindgen_test_layout___wasi_subscription_t() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_subscription_t>())).u as *const _ as usize }, + unsafe { &(*(::core::ptr::null::<__wasi_subscription_t>())).u as *const _ as usize }, 16usize, concat!( "Offset of field: ", diff --git a/wasmtime-wasi/src/instantiate.rs b/wasmtime-wasi/src/instantiate.rs index 0b83681280..a1e0d107d0 100644 --- a/wasmtime-wasi/src/instantiate.rs +++ b/wasmtime-wasi/src/instantiate.rs @@ -1,12 +1,12 @@ use super::syscalls; +use alloc::rc::Rc; +use core::cell::RefCell; use cranelift_codegen::ir::types; use cranelift_codegen::{ir, isa}; use cranelift_entity::PrimaryMap; use cranelift_wasm::DefinedFuncIndex; -use std::cell::RefCell; use std::collections::HashMap; use std::fs::File; -use std::rc::Rc; use target_lexicon::HOST; use wasi_common::WasiCtxBuilder; use wasmtime_environ::{translate_signature, Export, Module}; diff --git a/wasmtime-wasi/src/lib.rs b/wasmtime-wasi/src/lib.rs index 8b34268600..8e32b671d6 100644 --- a/wasmtime-wasi/src/lib.rs +++ b/wasmtime-wasi/src/lib.rs @@ -1,3 +1,5 @@ +extern crate alloc; + mod instantiate; mod syscalls; diff --git a/wasmtime-wast/src/lib.rs b/wasmtime-wast/src/lib.rs index f99ada52a9..f4e05ec02a 100644 --- a/wasmtime-wast/src/lib.rs +++ b/wasmtime-wast/src/lib.rs @@ -22,6 +22,7 @@ ) )] +extern crate alloc; #[macro_use] extern crate failure_derive; diff --git a/wasmtime-wast/src/spectest.rs b/wasmtime-wast/src/spectest.rs index e82eb09c13..63c4f38878 100644 --- a/wasmtime-wast/src/spectest.rs +++ b/wasmtime-wast/src/spectest.rs @@ -1,10 +1,10 @@ +use alloc::rc::Rc; +use core::cell::RefCell; use cranelift_codegen::ir::types; use cranelift_codegen::{ir, isa}; use cranelift_entity::PrimaryMap; use cranelift_wasm::{DefinedFuncIndex, Global, GlobalInit, Memory, Table, TableElementType}; -use std::cell::RefCell; -use std::collections::HashMap; -use std::rc::Rc; +use std::collections::hash_map::HashMap; use target_lexicon::HOST; use wasmtime_environ::{translate_signature, Export, MemoryPlan, Module, TablePlan}; use wasmtime_jit::target_tunables;