diff --git a/Cargo.lock b/Cargo.lock index 55b910896..a2a18ddcb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2789,13 +2789,11 @@ dependencies = [ "thiserror", "wasm-bindgen", "wasm-bindgen-test", - "wasmer-artifact", "wasmer-compiler", "wasmer-compiler-cranelift", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-derive", - "wasmer-engine", "wasmer-engine-universal", "wasmer-types", "wasmer-vm", @@ -2804,16 +2802,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "wasmer-artifact" -version = "2.3.0" -dependencies = [ - "enumset", - "thiserror", - "wasmer-compiler", - "wasmer-types", -] - [[package]] name = "wasmer-bin-fuzz" version = "0.0.0" @@ -2846,11 +2834,11 @@ dependencies = [ "thiserror", "typetag", "wasmer", + "wasmer-compiler", "wasmer-compiler-cranelift", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-emscripten", - "wasmer-engine", "wasmer-engine-universal", "wasmer-middlewares", "wasmer-types", @@ -2894,7 +2882,6 @@ dependencies = [ "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-emscripten", - "wasmer-engine", "wasmer-engine-universal", "wasmer-types", "wasmer-vfs", @@ -2908,15 +2895,21 @@ dependencies = [ name = "wasmer-compiler" version = "2.3.0" dependencies = [ + "backtrace", "enumset", "hashbrown 0.11.2", + "lazy_static", + "memmap2", + "more-asserts", "rkyv", + "rustc-demangle", "serde", "serde_bytes", "smallvec", "target-lexicon 0.12.4", "thiserror", "wasmer-types", + "wasmer-vm", "wasmparser 0.83.0", ] @@ -3026,41 +3019,6 @@ dependencies = [ "wasmer", ] -[[package]] -name = "wasmer-engine" -version = "2.3.0" -dependencies = [ - "backtrace", - "enumset", - "lazy_static", - "memmap2", - "more-asserts", - "rustc-demangle", - "serde", - "serde_bytes", - "target-lexicon 0.12.4", - "thiserror", - "wasmer-artifact", - "wasmer-compiler", - "wasmer-types", - "wasmer-vm", -] - -[[package]] -name = "wasmer-engine-dummy" -version = "2.3.0" -dependencies = [ - "bincode", - "enumset", - "serde", - "serde_bytes", - "wasmer-artifact", - "wasmer-compiler", - "wasmer-engine", - "wasmer-types", - "wasmer-vm", -] - [[package]] name = "wasmer-engine-universal" version = "2.3.0" @@ -3071,7 +3029,6 @@ dependencies = [ "region", "rkyv", "wasmer-compiler", - "wasmer-engine", "wasmer-engine-universal-artifact", "wasmer-types", "wasmer-vm", @@ -3086,7 +3043,6 @@ dependencies = [ "enumset", "rkyv", "thiserror", - "wasmer-artifact", "wasmer-compiler", "wasmer-types", ] @@ -3180,7 +3136,6 @@ dependencies = [ "scopeguard", "serde", "thiserror", - "wasmer-artifact", "wasmer-types", "winapi", ] @@ -3301,8 +3256,6 @@ dependencies = [ "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-emscripten", - "wasmer-engine", - "wasmer-engine-dummy", "wasmer-engine-universal", "wasmer-middlewares", "wasmer-types", diff --git a/Cargo.toml b/Cargo.toml index ee61fa67c..0b4943212 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ wasmer-compiler-cranelift = { version = "=2.3.0", path = "lib/compiler-cranelift wasmer-compiler-singlepass = { version = "=2.3.0", path = "lib/compiler-singlepass", optional = true } wasmer-compiler-llvm = { version = "=2.3.0", path = "lib/compiler-llvm", optional = true } wasmer-emscripten = { version = "=2.3.0", path = "lib/emscripten", optional = true } -wasmer-engine = { version = "=2.3.0", path = "lib/engine" } wasmer-engine-universal = { version = "=2.3.0", path = "lib/engine-universal", optional = true } wasmer-wasi = { version = "=2.3.0", path = "lib/wasi", optional = true } wasmer-wast = { version = "=2.3.0", path = "tests/lib/wast", optional = true } @@ -39,7 +38,6 @@ members = [ "lib/compiler-llvm", "lib/derive", "lib/emscripten", - "lib/engine", "lib/engine-universal", "lib/object", "lib/vfs", @@ -72,7 +70,6 @@ anyhow = "1.0" criterion = "0.3" lazy_static = "1.4" serial_test = "0.5" -wasmer-engine-dummy = { path = "tests/lib/engine-dummy" } compiler-test-derive = { path = "tests/lib/compiler-test-derive" } tempfile = "3.1" # For logging tests using the `RUST_LOG=debug` when testing @@ -95,7 +92,6 @@ default = [ engine = [] universal = [ "wasmer-engine-universal", - "engine", ] cache = ["wasmer-cache"] wast = ["wasmer-wast"] diff --git a/lib/api/Cargo.toml b/lib/api/Cargo.toml index a6486397f..ad82e7771 100644 --- a/lib/api/Cargo.toml +++ b/lib/api/Cargo.toml @@ -22,7 +22,6 @@ edition = "2018" # Shared dependencies. [dependencies] # - Mandatory shared dependencies. -wasmer-artifact = { path = "../artifact", version = "=2.3.0" } indexmap = { version = "1.6", features = ["serde-1"] } cfg-if = "1.0" thiserror = "1.0" @@ -36,7 +35,6 @@ wat = { version = "1.0", optional = true } wasmer-vm = { path = "../vm", version = "=2.3.0" } wasmer-compiler = { path = "../compiler", version = "=2.3.0" } wasmer-derive = { path = "../derive", version = "=2.3.0" } -wasmer-engine = { path = "../engine", version = "=2.3.0" } wasmer-types = { path = "../types", version = "=2.3.0" } target-lexicon = { version = "0.12.2", default-features = false } # - Optional dependencies for `sys`. diff --git a/lib/api/src/js/error.rs b/lib/api/src/js/error.rs index 15fdcc3a4..8931d0fd6 100644 --- a/lib/api/src/js/error.rs +++ b/lib/api/src/js/error.rs @@ -90,7 +90,7 @@ pub enum WasmError { /// The Serialize error can occur when serializing a /// compiled Module into a binary. -/// Copied from wasmer_engine::SerializeError +/// Copied from wasmer_compiler::SerializeError #[derive(Debug)] #[cfg_attr(feature = "std", derive(Error))] pub enum SerializeError { @@ -104,7 +104,7 @@ pub enum SerializeError { /// The Deserialize error can occur when loading a /// compiled Module from a binary. -/// Copied from wasmer_engine::DeSerializeError +/// Copied from wasmer_compiler::DeSerializeError #[derive(Error, Debug)] pub enum DeserializeError { /// An IO error diff --git a/lib/api/src/js/externals/mod.rs b/lib/api/src/js/externals/mod.rs index ebcb2b9e0..33a5bc25d 100644 --- a/lib/api/src/js/externals/mod.rs +++ b/lib/api/src/js/externals/mod.rs @@ -44,7 +44,7 @@ impl Extern { } } - /// Create an `Extern` from an `wasmer_engine::Export`. + /// Create an `Extern` from an `wasmer_compiler::Export`. pub fn from_vm_export(store: &Store, export: Export) -> Self { match export { Export::Function(f) => Self::Function(Function::from_vm_export(store, f)), diff --git a/lib/api/src/js/trap.rs b/lib/api/src/js/trap.rs index 88a8d6d09..15211c7f7 100644 --- a/lib/api/src/js/trap.rs +++ b/lib/api/src/js/trap.rs @@ -53,7 +53,7 @@ impl RuntimeError { /// /// # Example /// ``` - /// let trap = wasmer_engine::RuntimeError::new("unexpected error"); + /// let trap = wasmer_compiler::RuntimeError::new("unexpected error"); /// assert_eq!("unexpected error", trap.message()); /// ``` pub fn new>(message: I) -> Self { diff --git a/lib/api/src/sys/exports.rs b/lib/api/src/sys/exports.rs index a89fab5e8..a613acdfc 100644 --- a/lib/api/src/sys/exports.rs +++ b/lib/api/src/sys/exports.rs @@ -5,7 +5,7 @@ use indexmap::IndexMap; use std::fmt; use std::iter::{ExactSizeIterator, FromIterator}; use thiserror::Error; -use wasmer_engine::Export; +use wasmer_compiler::Export; /// The `ExportError` can happen when trying to get a specific /// export [`Extern`] from the [`Instance`] exports. diff --git a/lib/api/src/sys/externals/function.rs b/lib/api/src/sys/externals/function.rs index 2fbb91f45..5f8b1eae1 100644 --- a/lib/api/src/sys/externals/function.rs +++ b/lib/api/src/sys/externals/function.rs @@ -12,7 +12,7 @@ use std::cmp::max; use std::ffi::c_void; use std::fmt; use std::sync::Arc; -use wasmer_engine::{Export, ExportFunction, ExportFunctionMetadata}; +use wasmer_compiler::{Export, ExportFunction, ExportFunctionMetadata}; use wasmer_vm::{ on_host_stack, raise_user_trap, resume_panic, wasmer_call_trampoline, ImportInitializerFuncPtr, VMCallerCheckedAnyfunc, VMDynamicFunctionContext, VMFuncRef, VMFunction, VMFunctionBody, diff --git a/lib/api/src/sys/externals/global.rs b/lib/api/src/sys/externals/global.rs index 70854091f..bb93e5151 100644 --- a/lib/api/src/sys/externals/global.rs +++ b/lib/api/src/sys/externals/global.rs @@ -7,7 +7,7 @@ use crate::sys::Mutability; use crate::sys::RuntimeError; use std::fmt; use std::sync::Arc; -use wasmer_engine::Export; +use wasmer_compiler::Export; use wasmer_vm::{Global as RuntimeGlobal, VMGlobal}; /// A WebAssembly `global` instance. diff --git a/lib/api/src/sys/externals/memory.rs b/lib/api/src/sys/externals/memory.rs index c5545a01a..5bb4135d4 100644 --- a/lib/api/src/sys/externals/memory.rs +++ b/lib/api/src/sys/externals/memory.rs @@ -8,7 +8,7 @@ use std::mem; use std::mem::MaybeUninit; use std::slice; use std::sync::Arc; -use wasmer_engine::Export; +use wasmer_compiler::Export; use wasmer_types::Pages; use wasmer_vm::{MemoryError, VMMemory}; diff --git a/lib/api/src/sys/externals/mod.rs b/lib/api/src/sys/externals/mod.rs index c0b36487d..df58d31df 100644 --- a/lib/api/src/sys/externals/mod.rs +++ b/lib/api/src/sys/externals/mod.rs @@ -15,7 +15,7 @@ use crate::sys::exports::{ExportError, Exportable}; use crate::sys::store::{Store, StoreObject}; use crate::sys::ExternType; use std::fmt; -use wasmer_engine::Export; +use wasmer_compiler::Export; /// An `Extern` is the runtime representation of an entity that /// can be imported or exported. @@ -44,7 +44,7 @@ impl Extern { } } - /// Create an `Extern` from an `wasmer_engine::Export`. + /// Create an `Extern` from an `wasmer_compiler::Export`. pub fn from_vm_export(store: &Store, export: Export) -> Self { match export { Export::Function(f) => Self::Function(Function::from_vm_export(store, f)), diff --git a/lib/api/src/sys/externals/table.rs b/lib/api/src/sys/externals/table.rs index a776e009e..d7a11013b 100644 --- a/lib/api/src/sys/externals/table.rs +++ b/lib/api/src/sys/externals/table.rs @@ -5,7 +5,7 @@ use crate::sys::types::{Val, ValFuncRef}; use crate::sys::RuntimeError; use crate::sys::TableType; use std::sync::Arc; -use wasmer_engine::Export; +use wasmer_compiler::Export; use wasmer_vm::{Table as RuntimeTable, TableElement, VMTable}; /// A WebAssembly `table` instance. diff --git a/lib/api/src/sys/imports.rs b/lib/api/src/sys/imports.rs index 47fc7e2a3..9a0c94c40 100644 --- a/lib/api/src/sys/imports.rs +++ b/lib/api/src/sys/imports.rs @@ -4,7 +4,7 @@ use crate::{Exports, Extern, Module}; use std::collections::HashMap; use std::fmt; -use wasmer_engine::LinkError; +use wasmer_compiler::LinkError; use wasmer_types::ImportError; /// All of the import data used when instantiating. diff --git a/lib/api/src/sys/instance.rs b/lib/api/src/sys/instance.rs index e2c560a88..b80f44e22 100644 --- a/lib/api/src/sys/instance.rs +++ b/lib/api/src/sys/instance.rs @@ -69,12 +69,12 @@ pub enum InstantiationError { HostEnvInitialization(HostEnvInitError), } -impl From for InstantiationError { - fn from(other: wasmer_engine::InstantiationError) -> Self { +impl From for InstantiationError { + fn from(other: wasmer_compiler::InstantiationError) -> Self { match other { - wasmer_engine::InstantiationError::Link(e) => Self::Link(e), - wasmer_engine::InstantiationError::Start(e) => Self::Start(e), - wasmer_engine::InstantiationError::CpuFeature(e) => Self::CpuFeature(e), + wasmer_compiler::InstantiationError::Link(e) => Self::Link(e), + wasmer_compiler::InstantiationError::Start(e) => Self::Start(e), + wasmer_compiler::InstantiationError::CpuFeature(e) => Self::CpuFeature(e), } } } diff --git a/lib/api/src/sys/mod.rs b/lib/api/src/sys/mod.rs index 4d54a613c..b7c8c531e 100644 --- a/lib/api/src/sys/mod.rs +++ b/lib/api/src/sys/mod.rs @@ -50,9 +50,10 @@ pub use target_lexicon::{Architecture, CallingConvention, OperatingSystem, Tripl pub use wasmer_compiler::{ wasmparser, CompilerConfig, FunctionMiddleware, MiddlewareReaderState, ModuleMiddleware, }; -pub use wasmer_compiler::{CpuFeature, Features, Target}; +pub use wasmer_compiler::{ + CpuFeature, Engine, Export, Features, FrameInfo, LinkError, RuntimeError, Target, Tunables, +}; pub use wasmer_derive::ValueType; -pub use wasmer_engine::{Engine, Export, FrameInfo, LinkError, RuntimeError, Tunables}; pub use wasmer_types::is_wasm; #[cfg(feature = "experimental-reference-types-extern-ref")] pub use wasmer_types::ExternRef; diff --git a/lib/api/src/sys/module.rs b/lib/api/src/sys/module.rs index 0ef97c4ed..77d69980c 100644 --- a/lib/api/src/sys/module.rs +++ b/lib/api/src/sys/module.rs @@ -7,7 +7,7 @@ use std::io; use std::path::Path; use std::sync::Arc; use thiserror::Error; -use wasmer_engine::Artifact; +use wasmer_compiler::Artifact; #[cfg(feature = "wat")] use wasmer_types::WasmError; use wasmer_types::{ diff --git a/lib/api/src/sys/native.rs b/lib/api/src/sys/native.rs index 3f204fc20..8145f6d12 100644 --- a/lib/api/src/sys/native.rs +++ b/lib/api/src/sys/native.rs @@ -12,7 +12,7 @@ use std::marker::PhantomData; use crate::sys::externals::function::{DynamicFunction, VMDynamicFunction}; use crate::sys::{FromToNativeWasmType, Function, RuntimeError, Store, WasmTypeList}; use std::panic::{catch_unwind, AssertUnwindSafe}; -use wasmer_engine::ExportFunction; +use wasmer_compiler::ExportFunction; use wasmer_types::NativeWasmType; use wasmer_vm::{VMDynamicFunctionContext, VMFunctionBody, VMFunctionEnvironment, VMFunctionKind}; diff --git a/lib/api/src/sys/store.rs b/lib/api/src/sys/store.rs index abfe04967..3f2db7f1b 100644 --- a/lib/api/src/sys/store.rs +++ b/lib/api/src/sys/store.rs @@ -3,7 +3,7 @@ use std::fmt; use std::sync::{Arc, RwLock}; #[cfg(all(feature = "compiler", feature = "engine"))] use wasmer_compiler::CompilerConfig; -use wasmer_engine::{Engine, Tunables}; +use wasmer_compiler::{Engine, Tunables}; use wasmer_vm::{init_traps, TrapHandler, TrapHandlerFn}; /// The store represents all global state that can be manipulated by diff --git a/lib/api/src/sys/tunables.rs b/lib/api/src/sys/tunables.rs index 2703aedbd..98e825469 100644 --- a/lib/api/src/sys/tunables.rs +++ b/lib/api/src/sys/tunables.rs @@ -2,8 +2,7 @@ use crate::sys::{MemoryType, Pages, TableType}; use std::ptr::NonNull; use std::sync::Arc; use target_lexicon::PointerWidth; -use wasmer_compiler::Target; -use wasmer_engine::Tunables; +use wasmer_compiler::{Target, Tunables}; use wasmer_vm::MemoryError; use wasmer_vm::{ LinearMemory, LinearTable, Memory, MemoryStyle, Table, TableStyle, VMMemoryDefinition, diff --git a/lib/api/src/sys/types.rs b/lib/api/src/sys/types.rs index 7ab7bca3a..7de09ffc5 100644 --- a/lib/api/src/sys/types.rs +++ b/lib/api/src/sys/types.rs @@ -70,7 +70,7 @@ impl ValFuncRef for Val { .engine() .lookup_signature(item.type_index) .expect("Signature not found in store"); - let export = wasmer_engine::ExportFunction { + let export = wasmer_compiler::ExportFunction { // TODO: // figure out if we ever need a value here: need testing with complicated import patterns metadata: None, diff --git a/lib/artifact/Cargo.toml b/lib/artifact/Cargo.toml deleted file mode 100644 index 566dc22d4..000000000 --- a/lib/artifact/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "wasmer-artifact" -version = "2.3.0" -description = "Wasmer Artifact abstraction" -categories = ["wasm"] -keywords = ["wasm", "webassembly", "engine"] -authors = ["Wasmer Engineering Team "] -repository = "https://github.com/wasmerio/wasmer" -license = "MIT OR Apache-2.0 WITH LLVM-exception " -readme = "README.md" -edition = "2018" - -[dependencies] -wasmer-types = { path = "../types", version = "=2.3.0" } -wasmer-compiler = { path = "../compiler", version = "=2.3.0" } -thiserror = "1.0" -enumset = "1.0" - -[badges] -maintenance = { status = "actively-developed" } diff --git a/lib/artifact/README.md b/lib/artifact/README.md deleted file mode 100644 index 7727f722d..000000000 --- a/lib/artifact/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# `wasmer-artifact` [![Build Status](https://github.com/wasmerio/wasmer/workflows/build/badge.svg?style=flat-square)](https://github.com/wasmerio/wasmer/actions?query=workflow%3Abuild) [![Join Wasmer Slack](https://img.shields.io/static/v1?label=Slack&message=join%20chat&color=brighgreen&style=flat-square)](https://slack.wasmer.io) [![MIT License](https://img.shields.io/github/license/wasmerio/wasmer.svg?style=flat-square)](https://github.com/wasmerio/wasmer/blob/master/LICENSE) - - -This crate is the general abstraction for creating Artifacts in Wasmer. - -### Acknowledgments - -This project borrowed some of the code of the trap implementation from -the [`wasmtime-api`], the code since then has evolved significantly. - -Please check [Wasmer `ATTRIBUTIONS`] to further see licenses and other -attributions of the project. - - -[`wasmer-engine-universal`]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-universal -[`wasmer-engine-dummy`]: https://github.com/wasmerio/wasmer/tree/master/tests/lib/engine-dummy -[`wasmtime-api`]: https://crates.io/crates/wasmtime -[Wasmer `ATTRIBUTIONS`]: https://github.com/wasmerio/wasmer/blob/master/ATTRIBUTIONS.md diff --git a/lib/artifact/src/funcbody.rs b/lib/artifact/src/funcbody.rs deleted file mode 100644 index 662623baa..000000000 --- a/lib/artifact/src/funcbody.rs +++ /dev/null @@ -1,17 +0,0 @@ -/// A placeholder byte-sized type which is just used to provide some amount of type -/// safety when dealing with pointers to JIT-compiled function bodies. Note that it's -/// deliberately not Copy, as we shouldn't be carelessly copying function body bytes -/// around. -#[repr(C)] -pub struct VMFunctionBody(u8); - -#[cfg(test)] -mod test_vmfunction_body { - use super::VMFunctionBody; - use std::mem::size_of; - - #[test] - fn check_vmfunction_body_offsets() { - assert_eq!(size_of::(), 1); - } -} diff --git a/lib/artifact/src/lib.rs b/lib/artifact/src/lib.rs deleted file mode 100644 index 7b0411203..000000000 --- a/lib/artifact/src/lib.rs +++ /dev/null @@ -1,51 +0,0 @@ -//! Generic Artifact abstraction for Wasmer Engines. - -#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)] -#![warn(unused_import_braces)] -#![cfg_attr( - feature = "cargo-clippy", - allow(clippy::new_without_default, clippy::new_without_default) -)] -#![cfg_attr( - feature = "cargo-clippy", - warn( - clippy::float_arithmetic, - clippy::mut_mut, - clippy::nonminimal_bool, - clippy::map_unwrap_or, - clippy::print_stdout, - clippy::unicode_not_nfc, - clippy::use_self - ) -)] - -mod artifact; -mod funcbody; - -pub use crate::artifact::{ArtifactCreate, MetadataHeader, Upcastable}; -pub use crate::funcbody::VMFunctionBody; - -/// Version number of this crate. -pub const VERSION: &str = env!("CARGO_PKG_VERSION"); - -/// A safe wrapper around `VMFunctionBody`. -#[derive(Clone, Copy, Debug)] -#[repr(transparent)] -pub struct FunctionBodyPtr(pub *const VMFunctionBody); - -impl std::ops::Deref for FunctionBodyPtr { - type Target = *const VMFunctionBody; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -/// # Safety -/// The VMFunctionBody that this points to is opaque, so there's no data to -/// read or write through this pointer. This is essentially a usize. -unsafe impl Send for FunctionBodyPtr {} -/// # Safety -/// The VMFunctionBody that this points to is opaque, so there's no data to -/// read or write through this pointer. This is essentially a usize. -unsafe impl Sync for FunctionBodyPtr {} diff --git a/lib/c-api/Cargo.toml b/lib/c-api/Cargo.toml index 3829f1255..e869b32b8 100644 --- a/lib/c-api/Cargo.toml +++ b/lib/c-api/Cargo.toml @@ -27,7 +27,7 @@ wasmer-compiler-cranelift = { version = "=2.3.0", path = "../compiler-cranelift" wasmer-compiler-singlepass = { version = "=2.3.0", path = "../compiler-singlepass", optional = true } wasmer-compiler-llvm = { version = "=2.3.0", path = "../compiler-llvm", optional = true } wasmer-emscripten = { version = "=2.3.0", path = "../emscripten", optional = true } -wasmer-engine = { version = "=2.3.0", path = "../engine" } +wasmer-compiler = { version = "=2.3.0", path = "../compiler" } wasmer-engine-universal = { version = "=2.3.0", path = "../engine-universal", optional = true } wasmer-middlewares = { version = "=2.3.0", path = "../middlewares", optional = true } wasmer-wasi = { version = "=2.3.0", path = "../wasi", default-features = false, features = ["host-fs", "sys"], optional = true } @@ -55,14 +55,12 @@ default = [ ] wat = ["wasmer-api/wat"] wasi = ["wasmer-wasi"] -engine = [] middlewares = [ "compiler", "wasmer-middlewares", ] universal = [ "wasmer-engine-universal", - "engine", ] compiler = [ "wasmer-api/compiler", diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index 556743a46..f4ad150b2 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -31,7 +31,6 @@ wasmer-compiler-cranelift = { version = "=2.3.0", path = "../compiler-cranelift" wasmer-compiler-singlepass = { version = "=2.3.0", path = "../compiler-singlepass", optional = true } wasmer-compiler-llvm = { version = "=2.3.0", path = "../compiler-llvm", optional = true } wasmer-emscripten = { version = "=2.3.0", path = "../emscripten", optional = true } -wasmer-engine = { version = "=2.3.0", path = "../engine" } wasmer-engine-universal = { version = "=2.3.0", path = "../engine-universal", optional = true } wasmer-vm = { version = "=2.3.0", path = "../vm" } wasmer-wasi = { version = "=2.3.0", path = "../wasi", optional = true } diff --git a/lib/compiler/Cargo.toml b/lib/compiler/Cargo.toml index a73fe072a..06116bfb5 100644 --- a/lib/compiler/Cargo.toml +++ b/lib/compiler/Cargo.toml @@ -22,6 +22,15 @@ serde_bytes = { version = "0.11", optional = true } smallvec = "1.6" rkyv = { version = "0.7.38", features = ["indexmap"] } +backtrace = "0.3" +rustc-demangle = "0.1" +memmap2 = "0.5" +more-asserts = "0.2" +lazy_static = "1.4" + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +wasmer-vm = { path = "../vm", version = "=2.3.0" } + [features] default = ["std", "enable-serde" ] # This feature is for compiler implementors, it enables using `Compiler` and diff --git a/lib/artifact/src/artifact.rs b/lib/compiler/src/artifact.rs similarity index 98% rename from lib/artifact/src/artifact.rs rename to lib/compiler/src/artifact.rs index 3b62e40b6..a6ac0f970 100644 --- a/lib/artifact/src/artifact.rs +++ b/lib/compiler/src/artifact.rs @@ -1,10 +1,12 @@ +//! Generic Artifact abstraction for Wasmer Engines. + +use crate::{CpuFeature, Features}; use enumset::EnumSet; use std::any::Any; use std::convert::TryInto; use std::path::Path; use std::sync::Arc; use std::{fs, mem}; -use wasmer_compiler::{CpuFeature, Features}; use wasmer_types::entity::PrimaryMap; use wasmer_types::{DeserializeError, SerializeError}; use wasmer_types::{ diff --git a/lib/engine/src/artifact.rs b/lib/compiler/src/engine/artifact.rs similarity index 97% rename from lib/engine/src/artifact.rs rename to lib/compiler/src/engine/artifact.rs index edd0af011..158247979 100644 --- a/lib/engine/src/artifact.rs +++ b/lib/compiler/src/engine/artifact.rs @@ -1,8 +1,7 @@ +use crate::CpuFeature; use crate::{resolve_imports, Export, InstantiationError, RuntimeError, Tunables}; +use crate::{ArtifactCreate, Upcastable}; use std::any::Any; -pub use wasmer_artifact::MetadataHeader; -use wasmer_artifact::{ArtifactCreate, Upcastable}; -use wasmer_compiler::CpuFeature; use wasmer_types::entity::BoxedSlice; use wasmer_types::{DataInitializer, FunctionIndex, LocalFunctionIndex, SignatureIndex}; use wasmer_vm::{ diff --git a/lib/engine/src/error.rs b/lib/compiler/src/engine/error.rs similarity index 97% rename from lib/engine/src/error.rs rename to lib/compiler/src/engine/error.rs index d420b8a9e..a1489585b 100644 --- a/lib/engine/src/error.rs +++ b/lib/compiler/src/engine/error.rs @@ -1,5 +1,5 @@ //! The WebAssembly possible errors -use crate::trap::RuntimeError; +use crate::engine::trap::RuntimeError; use thiserror::Error; pub use wasmer_types::{DeserializeError, ImportError, SerializeError}; diff --git a/lib/engine/src/export.rs b/lib/compiler/src/engine/export.rs similarity index 100% rename from lib/engine/src/export.rs rename to lib/compiler/src/engine/export.rs diff --git a/lib/engine/src/engine.rs b/lib/compiler/src/engine/inner.rs similarity index 97% rename from lib/engine/src/engine.rs rename to lib/compiler/src/engine/inner.rs index e3f350a19..7b5772ad0 100644 --- a/lib/engine/src/engine.rs +++ b/lib/compiler/src/engine/inner.rs @@ -1,12 +1,12 @@ //! Engine trait and associated types. -use crate::tunables::Tunables; +use crate::engine::tunables::Tunables; use crate::Artifact; +use crate::Target; use memmap2::Mmap; use std::path::Path; use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; use std::sync::Arc; -use wasmer_compiler::Target; use wasmer_types::{CompileError, DeserializeError, FunctionType}; use wasmer_vm::{VMCallerCheckedAnyfunc, VMFuncRef, VMSharedSignatureIndex}; diff --git a/lib/compiler/src/engine/mod.rs b/lib/compiler/src/engine/mod.rs new file mode 100644 index 000000000..a2c409588 --- /dev/null +++ b/lib/compiler/src/engine/mod.rs @@ -0,0 +1,17 @@ +//! Generic Engine abstraction for Wasmer Engines. + +mod artifact; +mod error; +mod export; +mod inner; +mod resolver; +mod trap; +mod tunables; + +pub use self::artifact::Artifact; +pub use self::error::{InstantiationError, LinkError}; +pub use self::export::{Export, ExportFunction, ExportFunctionMetadata}; +pub use self::inner::{Engine, EngineId}; +pub use self::resolver::resolve_imports; +pub use self::trap::*; +pub use self::tunables::Tunables; diff --git a/lib/engine/src/resolver.rs b/lib/compiler/src/engine/resolver.rs similarity index 100% rename from lib/engine/src/resolver.rs rename to lib/compiler/src/engine/resolver.rs diff --git a/lib/engine/src/trap/error.rs b/lib/compiler/src/engine/trap/error.rs similarity index 100% rename from lib/engine/src/trap/error.rs rename to lib/compiler/src/engine/trap/error.rs diff --git a/lib/engine/src/trap/frame_info.rs b/lib/compiler/src/engine/trap/frame_info.rs similarity index 100% rename from lib/engine/src/trap/frame_info.rs rename to lib/compiler/src/engine/trap/frame_info.rs diff --git a/lib/engine/src/trap/mod.rs b/lib/compiler/src/engine/trap/mod.rs similarity index 100% rename from lib/engine/src/trap/mod.rs rename to lib/compiler/src/engine/trap/mod.rs diff --git a/lib/engine/src/tunables.rs b/lib/compiler/src/engine/tunables.rs similarity index 99% rename from lib/engine/src/tunables.rs rename to lib/compiler/src/engine/tunables.rs index f07d5a78b..3fc01cc62 100644 --- a/lib/engine/src/tunables.rs +++ b/lib/compiler/src/engine/tunables.rs @@ -1,4 +1,4 @@ -use crate::error::LinkError; +use crate::engine::error::LinkError; use std::ptr::NonNull; use std::sync::Arc; use wasmer_types::entity::{EntityRef, PrimaryMap}; diff --git a/lib/compiler/src/lib.rs b/lib/compiler/src/lib.rs index 5df97948b..a63d271f9 100644 --- a/lib/compiler/src/lib.rs +++ b/lib/compiler/src/lib.rs @@ -9,7 +9,10 @@ #![warn(unused_import_braces)] #![cfg_attr(feature = "std", deny(unstable_features))] #![cfg_attr(not(feature = "std"), no_std)] -#![cfg_attr(feature = "cargo-clippy", allow(clippy::new_without_default))] +#![cfg_attr( + feature = "cargo-clippy", + allow(clippy::new_without_default, clippy::upper_case_acronyms) +)] #![cfg_attr( feature = "cargo-clippy", warn( @@ -48,6 +51,14 @@ mod lib { } } +mod artifact; +#[cfg(not(target_arch = "wasm32"))] +mod engine; + +pub use crate::artifact::*; +#[cfg(not(target_arch = "wasm32"))] +pub use crate::engine::*; + #[cfg(feature = "translator")] mod compiler; mod target; diff --git a/lib/engine-universal/Cargo.toml b/lib/engine-universal/Cargo.toml index d5ba2bfa0..a9c4c0c64 100644 --- a/lib/engine-universal/Cargo.toml +++ b/lib/engine-universal/Cargo.toml @@ -19,7 +19,6 @@ wasmer-compiler = { path = "../compiler", version = "=2.3.0", features = [ "translator", ] } wasmer-vm = { path = "../vm", version = "=2.3.0" } -wasmer-engine = { path = "../engine", version = "=2.3.0" } # flexbuffers = { path = "../../../flatbuffers/rust/flexbuffers", version = "0.1.0" } cfg-if = "1.0" leb128 = "0.2" diff --git a/lib/engine-universal/src/artifact.rs b/lib/engine-universal/src/artifact.rs index 85264a2be..112835331 100644 --- a/lib/engine-universal/src/artifact.rs +++ b/lib/engine-universal/src/artifact.rs @@ -7,12 +7,12 @@ use enumset::EnumSet; use std::sync::{Arc, Mutex}; #[cfg(feature = "compiler")] use wasmer_compiler::ModuleEnvironment; -use wasmer_compiler::{CpuFeature, Features, Triple}; -use wasmer_engine::{ +use wasmer_compiler::{ register_frame_info, Artifact, FunctionExtent, GlobalFrameInfoRegistration, MetadataHeader, }; +use wasmer_compiler::{CpuFeature, Features, Triple}; #[cfg(feature = "compiler")] -use wasmer_engine::{Engine, Tunables}; +use wasmer_compiler::{Engine, Tunables}; use wasmer_engine_universal_artifact::ArtifactCreate; use wasmer_engine_universal_artifact::{SerializableModule, UniversalArtifactBuild}; use wasmer_types::entity::{BoxedSlice, PrimaryMap}; diff --git a/lib/engine-universal/src/engine.rs b/lib/engine-universal/src/engine.rs index 84614c642..288959f68 100644 --- a/lib/engine-universal/src/engine.rs +++ b/lib/engine-universal/src/engine.rs @@ -5,7 +5,7 @@ use std::sync::{Arc, Mutex}; #[cfg(feature = "compiler")] use wasmer_compiler::Compiler; use wasmer_compiler::Target; -use wasmer_engine::{Artifact, Engine, EngineId, FunctionExtent, Tunables}; +use wasmer_compiler::{Artifact, Engine, EngineId, FunctionExtent, Tunables}; use wasmer_engine_universal_artifact::UniversalEngineBuilder; use wasmer_types::entity::PrimaryMap; use wasmer_types::FunctionBody; diff --git a/lib/engine-universal/src/link.rs b/lib/engine-universal/src/link.rs index 272453342..86a91476e 100644 --- a/lib/engine-universal/src/link.rs +++ b/lib/engine-universal/src/link.rs @@ -1,7 +1,7 @@ //! Linking for Universal-compiled code. use std::ptr::{read_unaligned, write_unaligned}; -use wasmer_engine::FunctionExtent; +use wasmer_compiler::FunctionExtent; use wasmer_engine_universal_artifact::get_libcall_trampoline; use wasmer_types::entity::PrimaryMap; use wasmer_types::{LocalFunctionIndex, ModuleInfo}; diff --git a/lib/engine/Cargo.toml b/lib/engine/Cargo.toml deleted file mode 100644 index 03c51bf7b..000000000 --- a/lib/engine/Cargo.toml +++ /dev/null @@ -1,33 +0,0 @@ -[package] -name = "wasmer-engine" -version = "2.3.0" -description = "Wasmer Engine abstraction" -categories = ["wasm"] -keywords = ["wasm", "webassembly", "engine"] -authors = ["Wasmer Engineering Team "] -repository = "https://github.com/wasmerio/wasmer" -license = "MIT OR Apache-2.0 WITH LLVM-exception " -readme = "README.md" -edition = "2018" - -[dependencies] -wasmer-types = { path = "../types", version = "=2.3.0" } -wasmer-compiler = { path = "../compiler", version = "=2.3.0" } -wasmer-artifact = { path = "../artifact", version = "=2.3.0" } -target-lexicon = { version = "0.12.2", default-features = false } -# flexbuffers = { path = "../../../flatbuffers/rust/flexbuffers", version = "0.1.0" } -backtrace = "0.3" -rustc-demangle = "0.1" -memmap2 = "0.5" -more-asserts = "0.2" -thiserror = "1.0" -serde = { version = "1.0", features = ["derive", "rc"] } -serde_bytes = { version = "0.11" } -lazy_static = "1.4" -enumset = "1.0" - -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] -wasmer-vm = { path = "../vm", version = "=2.3.0" } - -[badges] -maintenance = { status = "actively-developed" } diff --git a/lib/engine/README.md b/lib/engine/README.md deleted file mode 100644 index e5041e63e..000000000 --- a/lib/engine/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# `wasmer-engine` [![Build Status](https://github.com/wasmerio/wasmer/workflows/build/badge.svg?style=flat-square)](https://github.com/wasmerio/wasmer/actions?query=workflow%3Abuild) [![Join Wasmer Slack](https://img.shields.io/static/v1?label=Slack&message=join%20chat&color=brighgreen&style=flat-square)](https://slack.wasmer.io) [![MIT License](https://img.shields.io/github/license/wasmerio/wasmer.svg?style=flat-square)](https://github.com/wasmerio/wasmer/blob/master/LICENSE) - -This crate is the general abstraction for creating Engines in Wasmer. - -Wasmer Engines are mainly responsible for two things: -* Transform the compilation code (from any Wasmer Compiler) to - **create** an `Artifact`, -* **Load** an `Artifact` so it can be used by the user (normally, - pushing the code into executable memory and so on). - -It currently has one implementation: - -1. Universal with [`wasmer-engine-universal`], - -## Example Implementation - -Please check [`wasmer-engine-dummy`] for an example implementation for -an `Engine`. - -### Acknowledgments - -This project borrowed some of the code of the trap implementation from -the [`wasmtime-api`], the code since then has evolved significantly. - -Please check [Wasmer `ATTRIBUTIONS`] to further see licenses and other -attributions of the project. - - -[`wasmer-engine-universal`]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-universal -[`wasmer-engine-dummy`]: https://github.com/wasmerio/wasmer/tree/master/tests/lib/engine-dummy -[`wasmtime-api`]: https://crates.io/crates/wasmtime -[Wasmer `ATTRIBUTIONS`]: https://github.com/wasmerio/wasmer/blob/master/ATTRIBUTIONS.md diff --git a/lib/engine/src/lib.rs b/lib/engine/src/lib.rs deleted file mode 100644 index c290de399..000000000 --- a/lib/engine/src/lib.rs +++ /dev/null @@ -1,44 +0,0 @@ -//! Generic Engine abstraction for Wasmer Engines. - -#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)] -#![warn(unused_import_braces)] -#![cfg_attr( - feature = "cargo-clippy", - allow( - clippy::new_without_default, - clippy::upper_case_acronyms, - clippy::new_without_default - ) -)] -#![cfg_attr( - feature = "cargo-clippy", - warn( - clippy::float_arithmetic, - clippy::mut_mut, - clippy::nonminimal_bool, - clippy::map_unwrap_or, - clippy::print_stdout, - clippy::unicode_not_nfc, - clippy::use_self - ) -)] - -mod artifact; -mod engine; -mod error; -mod export; -mod resolver; -mod trap; -mod tunables; - -pub use crate::artifact::Artifact; -pub use crate::engine::{Engine, EngineId}; -pub use crate::error::{InstantiationError, LinkError}; -pub use crate::export::{Export, ExportFunction, ExportFunctionMetadata}; -pub use crate::resolver::resolve_imports; -pub use crate::trap::*; -pub use crate::tunables::Tunables; -pub use wasmer_artifact::{ArtifactCreate, MetadataHeader}; - -/// Version number of this crate. -pub const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/lib/universal-artifact/Cargo.toml b/lib/universal-artifact/Cargo.toml index e45c287bc..819d4e89d 100644 --- a/lib/universal-artifact/Cargo.toml +++ b/lib/universal-artifact/Cargo.toml @@ -11,7 +11,6 @@ readme = "README.md" edition = "2018" [dependencies] -wasmer-artifact = { path = "../artifact", version = "=2.3.0" } wasmer-types = { path = "../types", version = "=2.3.0" } wasmer-compiler = { path = "../compiler", version = "=2.3.0", features = ["translator", ] } thiserror = "1.0" diff --git a/lib/universal-artifact/src/artifact.rs b/lib/universal-artifact/src/artifact.rs index f33228388..92047ec35 100644 --- a/lib/universal-artifact/src/artifact.rs +++ b/lib/universal-artifact/src/artifact.rs @@ -9,7 +9,7 @@ use crate::{ArtifactCreate, UniversalEngineBuilder}; use enumset::EnumSet; use std::mem; use std::sync::Arc; -use wasmer_artifact::MetadataHeader; +use wasmer_compiler::MetadataHeader; use wasmer_compiler::{ CpuFeature, Features, ModuleEnvironment, ModuleMiddlewareChain, Target, Triple, }; diff --git a/lib/universal-artifact/src/lib.rs b/lib/universal-artifact/src/lib.rs index d3843a588..85cf7c676 100644 --- a/lib/universal-artifact/src/lib.rs +++ b/lib/universal-artifact/src/lib.rs @@ -28,7 +28,7 @@ pub use crate::artifact::UniversalArtifactBuild; pub use crate::engine::UniversalEngineBuilder; pub use crate::serialize::SerializableModule; pub use crate::trampoline::*; -pub use wasmer_artifact::{ArtifactCreate, MetadataHeader, Upcastable}; +pub use wasmer_compiler::{ArtifactCreate, MetadataHeader, Upcastable}; /// Version number of this crate. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/lib/vm/Cargo.toml b/lib/vm/Cargo.toml index 5eb0291bf..907a6602c 100644 --- a/lib/vm/Cargo.toml +++ b/lib/vm/Cargo.toml @@ -12,7 +12,6 @@ edition = "2018" [dependencies] wasmer-types = { path = "../types", version = "=2.3.0" } -wasmer-artifact = { path = "../artifact", version = "=2.3.0" } libc = { version = "^0.2", default-features = false } memoffset = "0.6" indexmap = { version = "1.6", features = ["serde-1"] } diff --git a/lib/vm/src/export.rs b/lib/vm/src/export.rs index be6e5e575..d50792c53 100644 --- a/lib/vm/src/export.rs +++ b/lib/vm/src/export.rs @@ -5,7 +5,8 @@ use crate::global::Global; use crate::instance::WeakOrStrongInstanceRef; use crate::memory::Memory; use crate::table::Table; -use crate::vmcontext::{VMFunctionBody, VMFunctionEnvironment, VMFunctionKind, VMTrampoline}; +use crate::vmcontext::{VMFunctionEnvironment, VMFunctionKind, VMTrampoline}; +use crate::VMFunctionBody; use std::sync::Arc; use wasmer_types::{FunctionType, MemoryStyle, MemoryType, TableStyle, TableType}; diff --git a/lib/vm/src/instance/mod.rs b/lib/vm/src/instance/mod.rs index f76711966..d9110fb4a 100644 --- a/lib/vm/src/instance/mod.rs +++ b/lib/vm/src/instance/mod.rs @@ -21,12 +21,11 @@ use crate::memory::{Memory, MemoryError}; use crate::table::{Table, TableElement}; use crate::trap::{catch_traps, Trap, TrapCode, TrapHandler}; use crate::vmcontext::{ - VMBuiltinFunctionsArray, VMCallerCheckedAnyfunc, VMContext, VMFunctionBody, - VMFunctionEnvironment, VMFunctionImport, VMFunctionKind, VMGlobalDefinition, VMGlobalImport, - VMMemoryDefinition, VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport, - VMTrampoline, + VMBuiltinFunctionsArray, VMCallerCheckedAnyfunc, VMContext, VMFunctionEnvironment, + VMFunctionImport, VMFunctionKind, VMGlobalDefinition, VMGlobalImport, VMMemoryDefinition, + VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport, VMTrampoline, }; -use crate::{FunctionBodyPtr, VMOffsets}; +use crate::{FunctionBodyPtr, VMFunctionBody, VMOffsets}; use crate::{VMFunction, VMGlobal, VMMemory, VMTable}; use memoffset::offset_of; use more_asserts::assert_lt; diff --git a/lib/vm/src/lib.rs b/lib/vm/src/lib.rs index 03bc0330d..1e5edd2d7 100644 --- a/lib/vm/src/lib.rs +++ b/lib/vm/src/lib.rs @@ -54,7 +54,6 @@ pub use crate::vmcontext::{ VMFunctionImport, VMFunctionKind, VMGlobalDefinition, VMGlobalImport, VMMemoryDefinition, VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport, VMTrampoline, }; -pub use wasmer_artifact::{FunctionBodyPtr, VMFunctionBody}; pub use wasmer_types::LibCall; pub use wasmer_types::MemoryStyle; pub use wasmer_types::TableStyle; @@ -82,3 +81,43 @@ impl std::ops::Deref for SectionBodyPtr { &self.0 } } + +/// A placeholder byte-sized type which is just used to provide some amount of type +/// safety when dealing with pointers to JIT-compiled function bodies. Note that it's +/// deliberately not Copy, as we shouldn't be carelessly copying function body bytes +/// around. +#[repr(C)] +pub struct VMFunctionBody(u8); + +#[cfg(test)] +mod test_vmfunction_body { + use super::VMFunctionBody; + use std::mem::size_of; + + #[test] + fn check_vmfunction_body_offsets() { + assert_eq!(size_of::(), 1); + } +} + +/// A safe wrapper around `VMFunctionBody`. +#[derive(Clone, Copy, Debug)] +#[repr(transparent)] +pub struct FunctionBodyPtr(pub *const VMFunctionBody); + +impl std::ops::Deref for FunctionBodyPtr { + type Target = *const VMFunctionBody; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +/// # Safety +/// The VMFunctionBody that this points to is opaque, so there's no data to +/// read or write through this pointer. This is essentially a usize. +unsafe impl Send for FunctionBodyPtr {} +/// # Safety +/// The VMFunctionBody that this points to is opaque, so there's no data to +/// read or write through this pointer. This is essentially a usize. +unsafe impl Sync for FunctionBodyPtr {} diff --git a/lib/vm/src/trap/traphandlers.rs b/lib/vm/src/trap/traphandlers.rs index 21b267829..263e53284 100644 --- a/lib/vm/src/trap/traphandlers.rs +++ b/lib/vm/src/trap/traphandlers.rs @@ -4,8 +4,8 @@ //! WebAssembly trap handling, which is built on top of the lower-level //! signalhandling mechanisms. -use crate::vmcontext::{VMFunctionBody, VMFunctionEnvironment, VMTrampoline}; -use crate::Trap; +use crate::vmcontext::{VMFunctionEnvironment, VMTrampoline}; +use crate::{Trap, VMFunctionBody}; use backtrace::Backtrace; use core::ptr::{read, read_unaligned}; use corosensei::stack::DefaultStack; diff --git a/lib/vm/src/vmcontext.rs b/lib/vm/src/vmcontext.rs index cb5f0ccb5..bb2257d14 100644 --- a/lib/vm/src/vmcontext.rs +++ b/lib/vm/src/vmcontext.rs @@ -12,13 +12,13 @@ use crate::table::Table; use crate::trap::{Trap, TrapCode}; use crate::VMBuiltinFunctionIndex; use crate::VMExternRef; +use crate::VMFunctionBody; use std::any::Any; use std::convert::TryFrom; use std::fmt; use std::ptr::{self, NonNull}; use std::sync::Arc; use std::u32; -pub use wasmer_artifact::VMFunctionBody; /// Union representing the first parameter passed when calling a function. /// diff --git a/tests/compilers/config.rs b/tests/compilers/config.rs index 0d5c94b9c..97dc6fe78 100644 --- a/tests/compilers/config.rs +++ b/tests/compilers/config.rs @@ -57,8 +57,6 @@ impl Config { } pub fn engine(&self, compiler_config: Box) -> Box { - #[cfg(not(feature = "engine"))] - compile_error!("Plese enable at least one engine via the features"); match &self.engine { #[cfg(feature = "universal")] Engine::Universal => { diff --git a/tests/lib/engine-dummy/Cargo.toml b/tests/lib/engine-dummy/Cargo.toml deleted file mode 100644 index 95b67d86d..000000000 --- a/tests/lib/engine-dummy/Cargo.toml +++ /dev/null @@ -1,30 +0,0 @@ -[package] -name = "wasmer-engine-dummy" -version = "2.3.0" -authors = ["Wasmer Engineering Team "] -description = "Wasmer placeholder engine" -license = "MIT" -edition = "2018" -publish = false - -[dependencies] -wasmer-artifact = { path = "../../../lib/artifact", version = "=2.3.0" } -wasmer-types = { path = "../../../lib/types", version = "=2.3.0" } -wasmer-compiler = { path = "../../../lib/compiler", version = "=2.3.0" } -wasmer-vm = { path = "../../../lib/vm", version = "=2.3.0" } -wasmer-engine = { path = "../../../lib/engine", version = "=2.3.0" } -serde = { version = "1.0", features = ["derive", "rc"], optional = true } -serde_bytes = { version = "0.11", optional = true } -bincode = { version = "1.2", optional = true } -enumset = "1.0" - -[features] -# Enable the `compiler` feature if you want the engine to compile -# and not be only on headless mode. -default = ["serialize", "compiler"] -compiler = ["wasmer-compiler/translator"] -serialize = ["serde", "serde_bytes", "bincode"] - -[badges] -# TODO: publish this crate again and deprecate it -maintenance = { status = "actively-developed" } diff --git a/tests/lib/engine-dummy/README.md b/tests/lib/engine-dummy/README.md deleted file mode 100644 index 50811dded..000000000 --- a/tests/lib/engine-dummy/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Wasmer Dummy Engine - -The Dummy engine is mainly using for testing and learning proposes. -We use it for testing compiler-less code on the `wasmer` API -to make sure the API behaves as we expect. - -It can also be used to learn on how to implement a custom engine for Wasmer. - -A dummy engine, can't instantiate a Module. However it can inspect the -information related to `ModuleInfo`. \ No newline at end of file diff --git a/tests/lib/engine-dummy/src/artifact.rs b/tests/lib/engine-dummy/src/artifact.rs deleted file mode 100644 index 89258a0a1..000000000 --- a/tests/lib/engine-dummy/src/artifact.rs +++ /dev/null @@ -1,267 +0,0 @@ -//! Define `DummyArtifact` to allow compiling and instantiating to be -//! done as separate steps. - -use crate::engine::DummyEngine; -use enumset::EnumSet; -#[cfg(feature = "serialize")] -use serde::{Deserialize, Serialize}; -use std::sync::Arc; -use wasmer_artifact::ArtifactCreate; -use wasmer_compiler::CpuFeature; -#[cfg(feature = "compiler")] -use wasmer_compiler::ModuleEnvironment; -use wasmer_engine::{Artifact, Engine as _, Tunables}; -use wasmer_types::entity::{BoxedSlice, PrimaryMap}; -use wasmer_types::{ - CompileError, DeserializeError, Features, FunctionIndex, LocalFunctionIndex, MemoryIndex, - ModuleInfo, OwnedDataInitializer, SerializeError, SignatureIndex, TableIndex, -}; -use wasmer_vm::{ - FuncDataRegistry, FunctionBodyPtr, MemoryStyle, TableStyle, VMContext, VMFunctionBody, - VMSharedSignatureIndex, VMTrampoline, -}; - -/// Serializable struct for the artifact -#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] -pub struct DummyArtifactMetadata { - pub module: Arc, - pub features: Features, - pub data_initializers: Box<[OwnedDataInitializer]>, - // Plans for that module - pub memory_styles: PrimaryMap, - pub table_styles: PrimaryMap, - pub cpu_features: u64, -} - -/// A Dummy artifact. -/// -/// This artifact will point to fake finished functions and trampolines -/// as no functions are really compiled. -pub struct DummyArtifact { - metadata: DummyArtifactMetadata, - finished_functions: BoxedSlice, - finished_function_call_trampolines: BoxedSlice, - finished_dynamic_function_trampolines: BoxedSlice, - signatures: BoxedSlice, - func_data_registry: Arc, -} - -extern "C" fn dummy_function(_context: *mut VMContext) { - panic!("Dummy engine can't generate functions") -} - -extern "C" fn dummy_trampoline( - _context: *mut VMContext, - _callee: *const VMFunctionBody, - _values: *mut u128, -) { - panic!("Dummy engine can't generate trampolines") -} - -impl DummyArtifact { - const MAGIC_HEADER: &'static [u8] = b"\0wasmer-dummy"; - - /// Check if the provided bytes look like a serialized `DummyArtifact`. - pub fn is_deserializable(bytes: &[u8]) -> bool { - bytes.starts_with(Self::MAGIC_HEADER) - } - - #[cfg(feature = "compiler")] - /// Compile a data buffer into a `DummyArtifact`, which may then be instantiated. - pub fn new( - engine: &DummyEngine, - data: &[u8], - tunables: &dyn Tunables, - ) -> Result { - let environ = ModuleEnvironment::new(); - - let translation = environ.translate(data).map_err(CompileError::Wasm)?; - - let memory_styles: PrimaryMap = translation - .module - .memories - .values() - .map(|memory_type| tunables.memory_style(memory_type)) - .collect(); - let table_styles: PrimaryMap = translation - .module - .tables - .values() - .map(|table_type| tunables.table_style(table_type)) - .collect(); - - let data_initializers = translation - .data_initializers - .iter() - .map(OwnedDataInitializer::new) - .collect::>() - .into_boxed_slice(); - - let metadata = DummyArtifactMetadata { - module: Arc::new(translation.module), - features: Features::default(), - data_initializers, - memory_styles, - table_styles, - cpu_features: engine.target().cpu_features().as_u64(), - }; - Self::from_parts(engine, metadata) - } - - #[cfg(not(feature = "compiler"))] - pub fn new(engine: &DummyEngine, data: &[u8]) -> Result { - CompileError::Generic("The compiler feature is not enabled in the DummyEngine") - } - - #[cfg(feature = "serialize")] - /// Deserialize a DummyArtifact - pub fn deserialize(engine: &DummyEngine, bytes: &[u8]) -> Result { - if !Self::is_deserializable(bytes) { - return Err(DeserializeError::Incompatible( - "The provided bytes are not of the dummy engine".to_string(), - )); - } - - let inner_bytes = &bytes[Self::MAGIC_HEADER.len()..]; - - let metadata: DummyArtifactMetadata = bincode::deserialize(inner_bytes) - .map_err(|e| DeserializeError::CorruptedBinary(format!("{:?}", e)))?; - - Self::from_parts(engine, metadata).map_err(DeserializeError::Compiler) - } - - #[cfg(not(feature = "serialize"))] - pub fn deserialize(engine: &DummyEngine, bytes: &[u8]) -> Result { - Err(DeserializeError::Generic( - "The serializer feature is not enabled in the DummyEngine", - )) - } - - /// Construct a `DummyArtifact` from component parts. - pub fn from_parts( - engine: &DummyEngine, - metadata: DummyArtifactMetadata, - ) -> Result { - let num_local_functions = - metadata.module.functions.len() - metadata.module.num_imported_functions; - // We prepare the pointers for the finished functions. - let finished_functions: PrimaryMap = (0 - ..num_local_functions) - .map(|_| FunctionBodyPtr(dummy_function as _)) - .collect::>(); - - // We prepare the pointers for the finished function call trampolines. - let finished_function_call_trampolines: PrimaryMap = (0 - ..metadata.module.signatures.len()) - .map(|_| dummy_trampoline as VMTrampoline) - .collect::>(); - - // We prepare the pointers for the finished dynamic function trampolines. - let finished_dynamic_function_trampolines: PrimaryMap = (0 - ..metadata.module.num_imported_functions) - .map(|_| FunctionBodyPtr(dummy_function as _)) - .collect::>(); - - // Compute indices into the shared signature table. - let signatures = { - metadata - .module - .signatures - .values() - .map(|sig| engine.register_signature(sig)) - .collect::>() - }; - - let finished_functions = finished_functions.into_boxed_slice(); - let finished_function_call_trampolines = - finished_function_call_trampolines.into_boxed_slice(); - let finished_dynamic_function_trampolines = - finished_dynamic_function_trampolines.into_boxed_slice(); - let signatures = signatures.into_boxed_slice(); - - Ok(Self { - metadata, - finished_functions, - finished_function_call_trampolines, - finished_dynamic_function_trampolines, - signatures, - func_data_registry: engine.func_data().clone(), - }) - } -} - -impl ArtifactCreate for DummyArtifact { - fn module(&self) -> Arc { - self.metadata.module.clone() - } - - fn module_ref(&self) -> &ModuleInfo { - &self.metadata.module - } - - fn module_mut(&mut self) -> Option<&mut ModuleInfo> { - Arc::get_mut(&mut self.metadata.module) - } - - fn features(&self) -> &Features { - &self.metadata.features - } - - fn cpu_features(&self) -> EnumSet { - EnumSet::from_u64(self.metadata.cpu_features) - } - - fn data_initializers(&self) -> &[OwnedDataInitializer] { - &*self.metadata.data_initializers - } - - fn memory_styles(&self) -> &PrimaryMap { - &self.metadata.memory_styles - } - - fn table_styles(&self) -> &PrimaryMap { - &self.metadata.table_styles - } - #[cfg(feature = "serialize")] - fn serialize(&self) -> Result, SerializeError> { - let bytes = bincode::serialize(&self.metadata) - .map_err(|e| SerializeError::Generic(format!("{:?}", e)))?; - - // Prepend the header. - let mut serialized = Self::MAGIC_HEADER.to_vec(); - serialized.extend(bytes); - Ok(serialized) - } - - #[cfg(not(feature = "serialize"))] - fn serialize(&self) -> Result, SerializeError> { - Err(SerializeError::Generic( - "The serializer feature is not enabled in the DummyEngine", - )) - } -} -impl Artifact for DummyArtifact { - fn register_frame_info(&self) { - // Do nothing, since functions are not generated for the dummy engine - } - - fn finished_functions(&self) -> &BoxedSlice { - &self.finished_functions - } - - fn finished_function_call_trampolines(&self) -> &BoxedSlice { - &self.finished_function_call_trampolines - } - - fn finished_dynamic_function_trampolines(&self) -> &BoxedSlice { - &self.finished_dynamic_function_trampolines - } - - fn signatures(&self) -> &BoxedSlice { - &self.signatures - } - - fn func_data_registry(&self) -> &FuncDataRegistry { - &self.func_data_registry - } -} diff --git a/tests/lib/engine-dummy/src/engine.rs b/tests/lib/engine-dummy/src/engine.rs deleted file mode 100644 index d954886df..000000000 --- a/tests/lib/engine-dummy/src/engine.rs +++ /dev/null @@ -1,129 +0,0 @@ -//! Dummy Engine. - -use crate::DummyArtifact; -use std::sync::Arc; -use wasmer_compiler::{Features, Target}; -use wasmer_engine::{Artifact, Engine, EngineId, Tunables}; -use wasmer_types::{CompileError, DeserializeError, FunctionType}; -use wasmer_vm::{ - FuncDataRegistry, SignatureRegistry, VMCallerCheckedAnyfunc, VMContext, VMFuncRef, - VMFunctionBody, VMSharedSignatureIndex, -}; - -#[allow(dead_code)] -extern "C" fn dummy_trampoline( - _context: *mut VMContext, - _body: *const VMFunctionBody, - _values: *mut u128, -) { - panic!("Dummy engine can't call functions, since Wasm function bodies are not really compiled") -} - -/// A WebAssembly `Dummy` Engine. -#[derive(Clone)] -#[cfg_attr(feature = "compiler", derive(Default))] -pub struct DummyEngine { - signatures: Arc, - func_data: Arc, - features: Arc, - target: Arc, - engine_id: EngineId, -} - -impl DummyEngine { - #[cfg(feature = "compiler")] - pub fn new() -> Self { - Default::default() - } - - pub fn features(&self) -> &Features { - &self.features - } - - /// Shared func metadata registry. - pub(crate) fn func_data(&self) -> &Arc { - &self.func_data - } -} - -impl Engine for DummyEngine { - /// Get the tunables - fn target(&self) -> &Target { - &self.target - } - - /// Register a signature - fn register_signature(&self, func_type: &FunctionType) -> VMSharedSignatureIndex { - self.signatures.register(func_type) - } - - fn register_function_metadata(&self, func_data: VMCallerCheckedAnyfunc) -> VMFuncRef { - self.func_data.register(func_data) - } - - /// Lookup a signature - fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option { - self.signatures.lookup(sig) - } - - #[cfg(feature = "compiler")] - /// Validates a WebAssembly module - fn validate(&self, binary: &[u8]) -> Result<(), CompileError> { - use wasmer_compiler::wasmparser::{Validator, WasmFeatures}; - - let features = self.features(); - let mut validator = Validator::new(); - let wasm_features = WasmFeatures { - bulk_memory: features.bulk_memory, - threads: features.threads, - reference_types: features.reference_types, - multi_value: features.multi_value, - simd: features.simd, - tail_call: features.tail_call, - module_linking: features.module_linking, - multi_memory: features.multi_memory, - memory64: features.memory64, - exceptions: features.exceptions, - deterministic_only: false, - extended_const: features.extended_const, - relaxed_simd: features.relaxed_simd, - mutable_global: true, - saturating_float_to_int: true, - sign_extension: true, - }; - validator.wasm_features(wasm_features); - validator - .validate_all(binary) - .map_err(|e| CompileError::Validate(format!("{}", e)))?; - Ok(()) - } - - #[cfg(not(feature = "compiler"))] - /// Validates a WebAssembly module - fn validate(&self, binary: &[u8]) -> Result<(), CompileError> { - // We mark all Wasm modules as valid - Ok(()) - } - - /// Compile a WebAssembly binary - fn compile( - &self, - binary: &[u8], - tunables: &dyn Tunables, - ) -> Result, CompileError> { - Ok(Arc::new(DummyArtifact::new(self, binary, tunables)?)) - } - - /// Deserializes a WebAssembly module (binary content of a Shared Object file) - unsafe fn deserialize(&self, bytes: &[u8]) -> Result, DeserializeError> { - Ok(Arc::new(DummyArtifact::deserialize(self, bytes)?)) - } - - fn id(&self) -> &EngineId { - &self.engine_id - } - - fn cloned(&self) -> Arc { - Arc::new(self.clone()) - } -} diff --git a/tests/lib/engine-dummy/src/lib.rs b/tests/lib/engine-dummy/src/lib.rs deleted file mode 100644 index ed7e39b95..000000000 --- a/tests/lib/engine-dummy/src/lib.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod artifact; -mod engine; - -pub use artifact::DummyArtifact; -pub use engine::DummyEngine;