From e56c71495dea00673c7f5bd9741d7026c9a4e7d5 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Mon, 13 Jun 2022 23:59:43 +0300 Subject: [PATCH] Remove wasmer_engine_universal{,_artifact} and merge into wasmer_compiler --- Cargo.lock | 42 ++++--------------- Cargo.toml | 8 ---- examples/compiler_cranelift.rs | 2 +- examples/compiler_llvm.rs | 2 +- examples/compiler_singlepass.rs | 2 +- examples/early_exit.rs | 2 +- examples/engine_cross_compilation.rs | 2 +- examples/engine_headless.rs | 2 +- examples/engine_universal.rs | 6 +-- examples/errors.rs | 2 +- examples/exports_function.rs | 2 +- examples/exports_global.rs | 2 +- examples/exports_memory.rs | 2 +- examples/features.rs | 2 +- examples/hello_world.rs | 2 +- examples/imports_exports.rs | 2 +- examples/imports_function.rs | 2 +- examples/imports_function_env.rs | 2 +- examples/imports_global.rs | 2 +- examples/instance.rs | 2 +- examples/memory.rs | 2 +- examples/metering.rs | 2 +- examples/table.rs | 2 +- examples/tunables_limit_memory.rs | 2 +- examples/wasi.rs | 2 +- examples/wasi_pipes.rs | 2 +- fuzz/Cargo.toml | 4 +- fuzz/fuzz_targets/deterministic.rs | 2 +- fuzz/fuzz_targets/equivalence_universal.rs | 2 +- fuzz/fuzz_targets/metering.rs | 2 +- fuzz/fuzz_targets/universal_cranelift.rs | 2 +- fuzz/fuzz_targets/universal_llvm.rs | 2 +- fuzz/fuzz_targets/universal_singlepass.rs | 2 +- lib/api/Cargo.toml | 17 ++++---- lib/api/src/sys/mod.rs | 2 +- lib/api/src/sys/store.rs | 2 +- lib/c-api/Cargo.toml | 4 +- lib/c-api/src/wasm_c_api/engine.rs | 2 +- lib/cache/Cargo.toml | 2 +- lib/cache/benches/bench_filesystem_cache.rs | 2 +- lib/cli-compiler/Cargo.toml | 3 +- lib/cli-compiler/src/commands/compile.rs | 6 +-- lib/cli-compiler/src/store.rs | 2 +- lib/cli/Cargo.toml | 3 -- lib/cli/src/commands/compile.rs | 2 +- lib/cli/src/commands/run.rs | 6 +-- lib/cli/src/store.rs | 6 +-- lib/compiler/Cargo.toml | 9 ++++ lib/compiler/src/engine/mod.rs | 6 +++ .../src/engine/universal}/artifact.rs | 26 ++++++------ .../src/engine/universal}/builder.rs | 8 ++-- .../src/engine/universal}/code_memory.rs | 2 +- .../src/engine/universal}/engine.rs | 18 ++++---- .../src/engine/universal}/link.rs | 4 +- lib/compiler/src/engine/universal/mod.rs | 18 ++++++++ .../src/engine/universal}/serialize.rs | 8 ++-- .../src/engine/universal}/unwind/dummy.rs | 0 .../src/engine/universal}/unwind/mod.rs | 0 .../src/engine/universal}/unwind/systemv.rs | 0 .../engine/universal}/unwind/windows_x64.rs | 0 lib/compiler/src/lib.rs | 6 +++ .../src/universal_artifact}/artifact.rs | 25 ++++++----- .../src/universal_artifact}/engine.rs | 25 +---------- lib/compiler/src/universal_artifact/mod.rs | 11 +++++ .../src/universal_artifact}/serialize.rs | 0 .../src/universal_artifact}/trampoline.rs | 2 +- lib/engine-universal/Cargo.toml | 40 ------------------ lib/engine-universal/README.md | 25 ----------- lib/engine-universal/src/lib.rs | 40 ------------------ lib/universal-artifact/Cargo.toml | 25 ----------- lib/universal-artifact/README.md | 18 -------- lib/universal-artifact/src/lib.rs | 34 --------------- tests/compilers/config.rs | 4 +- 73 files changed, 164 insertions(+), 367 deletions(-) rename lib/{engine-universal/src => compiler/src/engine/universal}/artifact.rs (94%) rename lib/{engine-universal/src => compiler/src/engine/universal}/builder.rs (91%) rename lib/{engine-universal/src => compiler/src/engine/universal}/code_memory.rs (99%) rename lib/{engine-universal/src => compiler/src/engine/universal}/engine.rs (96%) rename lib/{engine-universal/src => compiler/src/engine/universal}/link.rs (97%) create mode 100644 lib/compiler/src/engine/universal/mod.rs rename lib/{engine-universal/src => compiler/src/engine/universal}/serialize.rs (99%) rename lib/{engine-universal/src => compiler/src/engine/universal}/unwind/dummy.rs (100%) rename lib/{engine-universal/src => compiler/src/engine/universal}/unwind/mod.rs (100%) rename lib/{engine-universal/src => compiler/src/engine/universal}/unwind/systemv.rs (100%) rename lib/{engine-universal/src => compiler/src/engine/universal}/unwind/windows_x64.rs (100%) rename lib/{universal-artifact/src => compiler/src/universal_artifact}/artifact.rs (93%) rename lib/{universal-artifact/src => compiler/src/universal_artifact}/engine.rs (57%) create mode 100644 lib/compiler/src/universal_artifact/mod.rs rename lib/{universal-artifact/src => compiler/src/universal_artifact}/serialize.rs (100%) rename lib/{universal-artifact/src => compiler/src/universal_artifact}/trampoline.rs (98%) delete mode 100644 lib/engine-universal/Cargo.toml delete mode 100644 lib/engine-universal/README.md delete mode 100644 lib/engine-universal/src/lib.rs delete mode 100644 lib/universal-artifact/Cargo.toml delete mode 100644 lib/universal-artifact/README.md delete mode 100644 lib/universal-artifact/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index e437c232c96..68eded541ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2753,7 +2753,6 @@ dependencies = [ "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-derive", - "wasmer-engine-universal", "wasmer-types", "wasmer-vm", "wasmparser 0.83.0", @@ -2769,10 +2768,10 @@ dependencies = [ "libfuzzer-sys", "wasm-smith", "wasmer", + "wasmer-compiler", "wasmer-compiler-cranelift", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", - "wasmer-engine-universal", "wasmer-middlewares", "wasmprinter", ] @@ -2798,7 +2797,6 @@ dependencies = [ "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-emscripten", - "wasmer-engine-universal", "wasmer-middlewares", "wasmer-types", "wasmer-wasi", @@ -2815,8 +2813,8 @@ dependencies = [ "tempfile", "thiserror", "wasmer", + "wasmer-compiler", "wasmer-compiler-singlepass", - "wasmer-engine-universal", ] [[package]] @@ -2841,7 +2839,6 @@ dependencies = [ "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-emscripten", - "wasmer-engine-universal", "wasmer-types", "wasmer-vfs", "wasmer-vm", @@ -2855,11 +2852,15 @@ name = "wasmer-compiler" version = "2.3.0" dependencies = [ "backtrace", + "cfg-if 1.0.0", + "enum-iterator", "enumset", "hashbrown 0.11.2", "lazy_static", + "leb128", "memmap2", "more-asserts", + "region", "rkyv", "rustc-demangle", "serde", @@ -2870,6 +2871,7 @@ dependencies = [ "wasmer-types", "wasmer-vm", "wasmparser 0.83.0", + "winapi", ] [[package]] @@ -2890,7 +2892,6 @@ dependencies = [ "wasmer-compiler", "wasmer-compiler-cranelift", "wasmer-compiler-singlepass", - "wasmer-engine-universal-artifact", "wasmer-types", ] @@ -2978,34 +2979,6 @@ dependencies = [ "wasmer", ] -[[package]] -name = "wasmer-engine-universal" -version = "2.3.0" -dependencies = [ - "cfg-if 1.0.0", - "enumset", - "leb128", - "region", - "rkyv", - "wasmer-compiler", - "wasmer-engine-universal-artifact", - "wasmer-types", - "wasmer-vm", - "winapi", -] - -[[package]] -name = "wasmer-engine-universal-artifact" -version = "2.3.0" -dependencies = [ - "enum-iterator", - "enumset", - "rkyv", - "thiserror", - "wasmer-compiler", - "wasmer-types", -] - [[package]] name = "wasmer-integration-tests-cli" version = "2.3.0" @@ -3172,7 +3145,6 @@ dependencies = [ "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-emscripten", - "wasmer-engine-universal", "wasmer-middlewares", "wasmer-types", "wasmer-wasi", diff --git a/Cargo.toml b/Cargo.toml index 6306bb9d151..22789c0a72c 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-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 } wasi-test-generator = { version = "=2.3.0", path = "tests/wasi-wast", optional = true } @@ -38,7 +37,6 @@ members = [ "lib/compiler-llvm", "lib/derive", "lib/emscripten", - "lib/engine-universal", "lib/object", "lib/vfs", "lib/vm", @@ -80,16 +78,12 @@ tracing-subscriber = { version = "0.3", default-features = false, features = ["e default = [ "wat", "wast", - "universal", "cache", "wasi", "emscripten", "middlewares", ] engine = [] -universal = [ - "wasmer-engine-universal", -] cache = ["wasmer-cache"] wast = ["wasmer-wast"] wasi = ["wasmer-wasi"] @@ -98,7 +92,6 @@ wat = ["wasmer/wat"] compiler = [ "wasmer/compiler", "wasmer-compiler/translator", - "wasmer-engine-universal/compiler", ] singlepass = [ "wasmer-compiler-singlepass", @@ -126,7 +119,6 @@ test-llvm = [ ] test-universal = [ - "universal", "test-generator/test-universal", ] diff --git a/examples/compiler_cranelift.rs b/examples/compiler_cranelift.rs index 2d7e446c8e4..372c5aa93aa 100644 --- a/examples/compiler_cranelift.rs +++ b/examples/compiler_cranelift.rs @@ -11,8 +11,8 @@ //! Ready? use wasmer::{imports, wat2wasm, Instance, Module, Store, Value}; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; fn main() -> Result<(), Box> { // Let's declare the Wasm module with the text representation. diff --git a/examples/compiler_llvm.rs b/examples/compiler_llvm.rs index f062a1c0bc6..d5c1cca8f2d 100644 --- a/examples/compiler_llvm.rs +++ b/examples/compiler_llvm.rs @@ -11,8 +11,8 @@ //! Ready? use wasmer::{imports, wat2wasm, Instance, Module, Store, Value}; +use wasmer_compiler::Universal; use wasmer_compiler_llvm::LLVM; -use wasmer_engine_universal::Universal; fn main() -> Result<(), Box> { // Let's declare the Wasm module with the text representation. diff --git a/examples/compiler_singlepass.rs b/examples/compiler_singlepass.rs index 845b9db302c..b7f53f3f575 100644 --- a/examples/compiler_singlepass.rs +++ b/examples/compiler_singlepass.rs @@ -11,8 +11,8 @@ //! Ready? use wasmer::{imports, wat2wasm, Instance, Module, Store, Value}; +use wasmer_compiler::Universal; use wasmer_compiler_singlepass::Singlepass; -use wasmer_engine_universal::Universal; fn main() -> Result<(), Box> { // Let's declare the Wasm module with the text representation. diff --git a/examples/early_exit.rs b/examples/early_exit.rs index 40ed664d7fd..b99dea687ad 100644 --- a/examples/early_exit.rs +++ b/examples/early_exit.rs @@ -17,8 +17,8 @@ use anyhow::bail; use std::fmt; use wasmer::{imports, wat2wasm, Function, Instance, Module, Store, TypedFunction}; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; // First we need to create an error type that we'll use to signal the end of execution. #[derive(Debug, Clone, Copy)] diff --git a/examples/engine_cross_compilation.rs b/examples/engine_cross_compilation.rs index 09a40fa9ce0..6af3a07440b 100644 --- a/examples/engine_cross_compilation.rs +++ b/examples/engine_cross_compilation.rs @@ -20,9 +20,9 @@ use std::str::FromStr; use wasmer::{wat2wasm, Module, RuntimeError, Store}; +use wasmer_compiler::Universal; use wasmer_compiler::{CpuFeature, Target, Triple}; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; fn main() -> Result<(), Box> { // Let's declare the Wasm module with the text representation. diff --git a/examples/engine_headless.rs b/examples/engine_headless.rs index 5e03591490a..53688731f1a 100644 --- a/examples/engine_headless.rs +++ b/examples/engine_headless.rs @@ -51,8 +51,8 @@ use wasmer::Instance; use wasmer::Module; use wasmer::Store; use wasmer::Value; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; fn main() -> Result<(), Box> { // First step, let's compile the Wasm module and serialize it. diff --git a/examples/engine_universal.rs b/examples/engine_universal.rs index 0d51244f9ec..21e27221c33 100644 --- a/examples/engine_universal.rs +++ b/examples/engine_universal.rs @@ -1,6 +1,6 @@ //! Defining an engine in Wasmer is one of the fundamental steps. //! -//! This example illustrates how to use the `wasmer_engine_universal`, +//! This example illustrates how to use the `wasmer_compiler`, //! aka the Universal engine. An engine applies roughly 2 steps: //! //! 1. It compiles the Wasm module bytes to executable code, through @@ -19,8 +19,8 @@ //! Ready? use wasmer::{imports, wat2wasm, Instance, Module, Store, Value}; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; fn main() -> Result<(), Box> { // Let's declare the Wasm module with the text representation. @@ -47,7 +47,7 @@ fn main() -> Result<(), Box> { println!("Creating Universal engine..."); // Define the engine that will drive everything. // - // In this case, the engine is `wasmer_engine_universal` which roughly + // In this case, the engine is `wasmer_compiler` which roughly // means that the executable code will live in memory. let engine = Universal::new(compiler_config).engine(); diff --git a/examples/errors.rs b/examples/errors.rs index d145fd776e1..e2718e56652 100644 --- a/examples/errors.rs +++ b/examples/errors.rs @@ -14,8 +14,8 @@ //! Ready? use wasmer::{imports, wat2wasm, Instance, Module, Store}; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; fn main() -> Result<(), Box> { // Let's declare the Wasm module with the text representation. diff --git a/examples/exports_function.rs b/examples/exports_function.rs index f720b804367..e35ab055604 100644 --- a/examples/exports_function.rs +++ b/examples/exports_function.rs @@ -18,8 +18,8 @@ //! Ready? use wasmer::{imports, wat2wasm, Instance, Module, Store, Value}; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; fn main() -> Result<(), Box> { // Let's declare the Wasm module with the text representation. diff --git a/examples/exports_global.rs b/examples/exports_global.rs index 80aad13302a..58a494006a0 100644 --- a/examples/exports_global.rs +++ b/examples/exports_global.rs @@ -16,8 +16,8 @@ //! Ready? use wasmer::{imports, wat2wasm, Instance, Module, Mutability, Store, Type, Value}; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; fn main() -> Result<(), Box> { // Let's declare the Wasm module with the text representation. diff --git a/examples/exports_memory.rs b/examples/exports_memory.rs index a3ef6c8f5bd..74b5fc649d6 100644 --- a/examples/exports_memory.rs +++ b/examples/exports_memory.rs @@ -12,8 +12,8 @@ //! Ready? use wasmer::{imports, wat2wasm, Instance, Module, Store, WasmPtr}; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; fn main() -> Result<(), Box> { // Let's declare the Wasm module with the text representation. diff --git a/examples/features.rs b/examples/features.rs index 3812bf8b3d6..13db2eab610 100644 --- a/examples/features.rs +++ b/examples/features.rs @@ -11,8 +11,8 @@ //! Ready? use wasmer::{imports, wat2wasm, Features, Instance, Module, Store, Value}; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; fn main() -> anyhow::Result<()> { // Let's declare the Wasm module with the text representation. diff --git a/examples/hello_world.rs b/examples/hello_world.rs index e0cc73e4aeb..873c4676ab2 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -7,8 +7,8 @@ //! ``` use wasmer::{imports, wat2wasm, Function, Instance, Module, Store, TypedFunction}; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; fn main() -> anyhow::Result<()> { // First we create a simple Wasm program to use with Wasmer. diff --git a/examples/imports_exports.rs b/examples/imports_exports.rs index a832ed8b8d3..fa4da15b766 100644 --- a/examples/imports_exports.rs +++ b/examples/imports_exports.rs @@ -19,8 +19,8 @@ use wasmer::{ imports, wat2wasm, Function, FunctionType, Global, Instance, Memory, Module, Store, Table, Type, Value, }; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; fn main() -> Result<(), Box> { // Let's declare the Wasm module. diff --git a/examples/imports_function.rs b/examples/imports_function.rs index 767e0bdd57c..7dc842d4888 100644 --- a/examples/imports_function.rs +++ b/examples/imports_function.rs @@ -18,8 +18,8 @@ //! Ready? use wasmer::{imports, wat2wasm, Function, FunctionType, Instance, Module, Store, Type, Value}; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; fn main() -> Result<(), Box> { // Let's declare the Wasm module with the text representation. diff --git a/examples/imports_function_env.rs b/examples/imports_function_env.rs index 0cb4b8ffec5..a59f7fe6f8e 100644 --- a/examples/imports_function_env.rs +++ b/examples/imports_function_env.rs @@ -21,8 +21,8 @@ use std::sync::{Arc, Mutex}; use wasmer::{imports, wat2wasm, Function, Instance, Module, Store, WasmerEnv}; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; fn main() -> Result<(), Box> { // Let's declare the Wasm module with the text representation. diff --git a/examples/imports_global.rs b/examples/imports_global.rs index 6da88c1d8ce..fe07a2536cb 100644 --- a/examples/imports_global.rs +++ b/examples/imports_global.rs @@ -16,8 +16,8 @@ //! Ready? use wasmer::{imports, wat2wasm, Global, Instance, Module, Store, Value}; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; fn main() -> Result<(), Box> { // Let's declare the Wasm module with the text representation. diff --git a/examples/instance.rs b/examples/instance.rs index 1d0b16f945e..4391d1fb7de 100644 --- a/examples/instance.rs +++ b/examples/instance.rs @@ -15,8 +15,8 @@ //! Ready? use wasmer::{imports, wat2wasm, Instance, Module, Store}; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; fn main() -> Result<(), Box> { // Let's declare the Wasm module. diff --git a/examples/memory.rs b/examples/memory.rs index 5598271ed59..3b16d57512f 100644 --- a/examples/memory.rs +++ b/examples/memory.rs @@ -16,8 +16,8 @@ use std::mem; use wasmer::{imports, wat2wasm, Bytes, Instance, Module, Pages, Store, TypedFunction}; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; // this example is a work in progress: // TODO: clean it up and comment it https://github.com/wasmerio/wasmer/issues/1749 diff --git a/examples/metering.rs b/examples/metering.rs index 8e715c1f7f1..d9732fea0ff 100644 --- a/examples/metering.rs +++ b/examples/metering.rs @@ -19,8 +19,8 @@ use std::sync::Arc; use wasmer::wasmparser::Operator; use wasmer::CompilerConfig; use wasmer::{imports, wat2wasm, Instance, Module, Store}; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; use wasmer_middlewares::{ metering::{get_remaining_points, set_remaining_points, MeteringPoints}, Metering, diff --git a/examples/table.rs b/examples/table.rs index c0bf78b4298..77fa31493da 100644 --- a/examples/table.rs +++ b/examples/table.rs @@ -1,8 +1,8 @@ use wasmer::{ imports, wat2wasm, Function, Instance, Module, Store, TableType, Type, TypedFunction, Value, }; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; /// A function we'll call through a table. fn host_callback(arg1: i32, arg2: i32) -> i32 { diff --git a/examples/tunables_limit_memory.rs b/examples/tunables_limit_memory.rs index 28d31450b5f..3e43cd9f7d5 100644 --- a/examples/tunables_limit_memory.rs +++ b/examples/tunables_limit_memory.rs @@ -7,8 +7,8 @@ use wasmer::{ wat2wasm, BaseTunables, Instance, Memory, MemoryType, Module, Pages, Store, TableType, Target, Tunables, }; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; /// A custom tunables that allows you to set a memory limit. /// diff --git a/examples/wasi.rs b/examples/wasi.rs index 3d24c5af60b..a14b50d42e5 100644 --- a/examples/wasi.rs +++ b/examples/wasi.rs @@ -16,8 +16,8 @@ //! Ready? use wasmer::{Instance, Module, Store}; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; use wasmer_wasi::WasiState; fn main() -> Result<(), Box> { diff --git a/examples/wasi_pipes.rs b/examples/wasi_pipes.rs index b1d44e119b4..65819882eed 100644 --- a/examples/wasi_pipes.rs +++ b/examples/wasi_pipes.rs @@ -12,8 +12,8 @@ //! Ready? use wasmer::{Instance, Module, Store}; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; use wasmer_wasi::{Pipe, WasiState}; fn main() -> Result<(), Box> { diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 8a31b18721e..7b2ce822057 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -16,7 +16,7 @@ wasmer = { path = "../lib/api" } wasmer-compiler-cranelift = { path = "../lib/compiler-cranelift", optional = true } wasmer-compiler-llvm = { path = "../lib/compiler-llvm", optional = true } wasmer-compiler-singlepass = { path = "../lib/compiler-singlepass", optional = true } -wasmer-engine-universal = { path = "../lib/engine-universal", optional = true } +wasmer-compiler = { path = "../lib/compiler", optional = true } wasmer-middlewares = { path = "../lib/middlewares" } wasmprinter = "0.2" @@ -24,7 +24,7 @@ wasmprinter = "0.2" cranelift = [ "wasmer-compiler-cranelift" ] llvm = [ "wasmer-compiler-llvm" ] singlepass = [ "wasmer-compiler-singlepass" ] -universal = [ "wasmer-engine-universal" ] +universal = [ "wasmer-compiler" ] [[bin]] name = "equivalence_universal" diff --git a/fuzz/fuzz_targets/deterministic.rs b/fuzz/fuzz_targets/deterministic.rs index 633043367b2..2e4ae2bfb07 100644 --- a/fuzz/fuzz_targets/deterministic.rs +++ b/fuzz/fuzz_targets/deterministic.rs @@ -3,10 +3,10 @@ use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target}; use wasm_smith::{Config, ConfiguredModule}; use wasmer::{CompilerConfig, Engine, Module, Store}; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; use wasmer_compiler_llvm::LLVM; use wasmer_compiler_singlepass::Singlepass; -use wasmer_engine_universal::Universal; #[derive(Arbitrary, Debug, Default, Copy, Clone)] struct NoImportsConfig; diff --git a/fuzz/fuzz_targets/equivalence_universal.rs b/fuzz/fuzz_targets/equivalence_universal.rs index bb4e4877f63..a053a757168 100644 --- a/fuzz/fuzz_targets/equivalence_universal.rs +++ b/fuzz/fuzz_targets/equivalence_universal.rs @@ -5,13 +5,13 @@ use anyhow::Result; use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target}; use wasm_smith::{Config, ConfiguredModule}; use wasmer::{imports, CompilerConfig, Instance, Module, Store, Val}; +use wasmer_compiler::Universal; #[cfg(feature = "cranelift")] use wasmer_compiler_cranelift::Cranelift; #[cfg(feature = "llvm")] use wasmer_compiler_llvm::LLVM; #[cfg(feature = "singlepass")] use wasmer_compiler_singlepass::Singlepass; -use wasmer_engine_universal::Universal; #[derive(Arbitrary, Debug, Default, Copy, Clone)] struct ExportedFunctionConfig; diff --git a/fuzz/fuzz_targets/metering.rs b/fuzz/fuzz_targets/metering.rs index 69d541967cf..4da73f0c0c9 100644 --- a/fuzz/fuzz_targets/metering.rs +++ b/fuzz/fuzz_targets/metering.rs @@ -5,8 +5,8 @@ use std::sync::Arc; use wasm_smith::{Config, ConfiguredModule}; use wasmer::wasmparser::Operator; use wasmer::{imports, CompilerConfig, Instance, Module, Store}; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; use wasmer_middlewares::Metering; #[derive(Arbitrary, Debug, Default, Copy, Clone)] diff --git a/fuzz/fuzz_targets/universal_cranelift.rs b/fuzz/fuzz_targets/universal_cranelift.rs index 05133e44289..c61c0860687 100644 --- a/fuzz/fuzz_targets/universal_cranelift.rs +++ b/fuzz/fuzz_targets/universal_cranelift.rs @@ -3,8 +3,8 @@ use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target}; use wasm_smith::{Config, ConfiguredModule}; use wasmer::{imports, CompilerConfig, Instance, Module, Store}; +use wasmer_compiler::Universal; use wasmer_compiler_cranelift::Cranelift; -use wasmer_engine_universal::Universal; #[derive(Arbitrary, Debug, Default, Copy, Clone)] struct NoImportsConfig; diff --git a/fuzz/fuzz_targets/universal_llvm.rs b/fuzz/fuzz_targets/universal_llvm.rs index 0d0044e0261..0ba36cbcd91 100644 --- a/fuzz/fuzz_targets/universal_llvm.rs +++ b/fuzz/fuzz_targets/universal_llvm.rs @@ -3,8 +3,8 @@ use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target}; use wasm_smith::{Config, ConfiguredModule}; use wasmer::{imports, CompilerConfig, Instance, Module, Store}; +use wasmer_compiler::Universal; use wasmer_compiler_llvm::LLVM; -use wasmer_engine_universal::Universal; #[derive(Arbitrary, Debug, Default, Copy, Clone)] struct NoImportsConfig; diff --git a/fuzz/fuzz_targets/universal_singlepass.rs b/fuzz/fuzz_targets/universal_singlepass.rs index b37c81b1458..2c67cedde3e 100644 --- a/fuzz/fuzz_targets/universal_singlepass.rs +++ b/fuzz/fuzz_targets/universal_singlepass.rs @@ -3,8 +3,8 @@ use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target}; use wasm_smith::{Config, ConfiguredModule}; use wasmer::{imports, Instance, Module, Store}; +use wasmer_compiler::Universal; use wasmer_compiler_singlepass::Singlepass; -use wasmer_engine_universal::Universal; #[derive(Arbitrary, Debug, Default, Copy, Clone)] struct NoImportsConfig; diff --git a/lib/api/Cargo.toml b/lib/api/Cargo.toml index ad82e777109..c88d4b5a495 100644 --- a/lib/api/Cargo.toml +++ b/lib/api/Cargo.toml @@ -41,7 +41,6 @@ target-lexicon = { version = "0.12.2", default-features = false } wasmer-compiler-singlepass = { path = "../compiler-singlepass", version = "=2.3.0", optional = true } wasmer-compiler-cranelift = { path = "../compiler-cranelift", version = "=2.3.0", optional = true } wasmer-compiler-llvm = { path = "../compiler-llvm", version = "=2.3.0", optional = true } -wasmer-engine-universal = { path = "../engine-universal", version = "=2.3.0", optional = true } # - Mandatory dependencies for `sys` on Windows. [target.'cfg(all(not(target_arch = "wasm32"), target_os = "windows"))'.dependencies] winapi = "0.3" @@ -89,7 +88,6 @@ sys-default = ["sys", "wat", "default-cranelift", "default-universal"] compiler = [ "sys", "wasmer-compiler/translator", - "wasmer-engine-universal/compiler", ] singlepass = [ "compiler", @@ -118,15 +116,14 @@ default-compiler = [] ] # - Engines. engine = ["sys"] - universal = [ - "engine", - "wasmer-engine-universal", - ] +universal = [ + "engine", +] default-engine = [] - default-universal = [ - "default-engine", - "universal", - ] +default-universal = [ + "default-engine", + "universal", +] # - Experimental / in-development features experimental-reference-types-extern-ref = [ "sys", diff --git a/lib/api/src/sys/mod.rs b/lib/api/src/sys/mod.rs index b7c8c531ea0..70c42b84f36 100644 --- a/lib/api/src/sys/mod.rs +++ b/lib/api/src/sys/mod.rs @@ -107,7 +107,7 @@ pub use wasmer_compiler_cranelift::{Cranelift, CraneliftOptLevel}; pub use wasmer_compiler_llvm::{LLVMOptLevel, LLVM}; #[cfg(feature = "universal")] -pub use wasmer_engine_universal::{Universal, UniversalArtifact, UniversalEngine}; +pub use wasmer_compiler::{Universal, UniversalArtifact, UniversalEngine}; /// Version number of this crate. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/lib/api/src/sys/store.rs b/lib/api/src/sys/store.rs index 3f2db7f1b0f..7472ef330b6 100644 --- a/lib/api/src/sys/store.rs +++ b/lib/api/src/sys/store.rs @@ -119,7 +119,7 @@ impl Default for Store { fn get_engine(mut config: impl CompilerConfig + 'static) -> impl Engine + Send + Sync { cfg_if::cfg_if! { if #[cfg(feature = "default-universal")] { - wasmer_engine_universal::Universal::new(config) + wasmer_compiler::Universal::new(config) .engine() } else { compile_error!("No default engine chosen") diff --git a/lib/c-api/Cargo.toml b/lib/c-api/Cargo.toml index e869b32b836..75c6f318114 100644 --- a/lib/c-api/Cargo.toml +++ b/lib/c-api/Cargo.toml @@ -28,7 +28,6 @@ wasmer-compiler-singlepass = { version = "=2.3.0", path = "../compiler-singlepas wasmer-compiler-llvm = { version = "=2.3.0", path = "../compiler-llvm", optional = true } wasmer-emscripten = { version = "=2.3.0", path = "../emscripten", optional = true } 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 } wasmer-types = { version = "=2.3.0", path = "../types" } @@ -60,11 +59,10 @@ middlewares = [ "wasmer-middlewares", ] universal = [ - "wasmer-engine-universal", + "compiler", ] compiler = [ "wasmer-api/compiler", - "wasmer-engine-universal/compiler", ] singlepass = [ "wasmer-compiler-singlepass", diff --git a/lib/c-api/src/wasm_c_api/engine.rs b/lib/c-api/src/wasm_c_api/engine.rs index 8bdd2f98039..b52e8201885 100644 --- a/lib/c-api/src/wasm_c_api/engine.rs +++ b/lib/c-api/src/wasm_c_api/engine.rs @@ -14,7 +14,7 @@ use cfg_if::cfg_if; use std::sync::Arc; use wasmer_api::Engine; #[cfg(feature = "universal")] -use wasmer_engine_universal::Universal; +use wasmer_compiler::Universal; /// Kind of compilers that can be used by the engines. /// diff --git a/lib/cache/Cargo.toml b/lib/cache/Cargo.toml index 86722a3b4f8..319afb3042d 100644 --- a/lib/cache/Cargo.toml +++ b/lib/cache/Cargo.toml @@ -21,7 +21,7 @@ criterion = "0.3" tempfile = "3" rand = "0.8.3" wasmer-compiler-singlepass = { path = "../compiler-singlepass", version = "=2.3.0" } -wasmer-engine-universal = { path = "../engine-universal", version = "=2.3.0" } +wasmer-compiler = { path = "../compiler", version = "=2.3.0" } [features] default = ["wasmer/js-serializable-module", "filesystem"] diff --git a/lib/cache/benches/bench_filesystem_cache.rs b/lib/cache/benches/bench_filesystem_cache.rs index b4e3ab41fe6..4f07dd4f129 100644 --- a/lib/cache/benches/bench_filesystem_cache.rs +++ b/lib/cache/benches/bench_filesystem_cache.rs @@ -5,8 +5,8 @@ use tempfile::TempDir; use wasmer::{Module, Store}; use wasmer_cache::Cache; use wasmer_cache::{FileSystemCache, Hash}; +use wasmer_compiler::Universal; use wasmer_compiler_singlepass::Singlepass; -use wasmer_engine_universal::Universal; fn random_key() -> Hash { Hash::new(rand::thread_rng().gen::<[u8; 32]>()) diff --git a/lib/cli-compiler/Cargo.toml b/lib/cli-compiler/Cargo.toml index e887ac55df8..c6e09127994 100644 --- a/lib/cli-compiler/Cargo.toml +++ b/lib/cli-compiler/Cargo.toml @@ -18,8 +18,7 @@ path = "src/bin/wasmer_compiler.rs" doc = false [dependencies] -wasmer-engine-universal-artifact = { version = "=2.3.0", path = "../universal-artifact", features = ["compiler"] } -wasmer-compiler = { version = "=2.3.0", path = "../compiler" } +wasmer-compiler = { version = "=2.3.0", path = "../compiler", features = ["universal_engine"] } wasmer-types = { version = "=2.3.0", path = "../types" } atty = "0.2" colored = "2.0" diff --git a/lib/cli-compiler/src/commands/compile.rs b/lib/cli-compiler/src/commands/compile.rs index 134c680327c..e4af3e42143 100644 --- a/lib/cli-compiler/src/commands/compile.rs +++ b/lib/cli-compiler/src/commands/compile.rs @@ -3,8 +3,8 @@ use crate::warning; use anyhow::{Context, Result}; use std::path::{Path, PathBuf}; use structopt::StructOpt; +use wasmer_compiler::{ArtifactCreate, UniversalArtifactBuild}; use wasmer_compiler::{CpuFeature, ModuleEnvironment, Target, Triple}; -use wasmer_engine_universal_artifact::{ArtifactCreate, UniversalArtifactBuild}; use wasmer_types::entity::PrimaryMap; use wasmer_types::{CompileError, MemoryIndex, MemoryStyle, TableIndex, TableStyle}; @@ -43,9 +43,7 @@ impl Compile { ) -> Result<&'static str> { Ok(match engine_type { EngineType::Universal => { - wasmer_engine_universal_artifact::UniversalArtifactBuild::get_default_extension( - target_triple, - ) + wasmer_compiler::UniversalArtifactBuild::get_default_extension(target_triple) } }) } diff --git a/lib/cli-compiler/src/store.rs b/lib/cli-compiler/src/store.rs index 16f8691ca7c..4f0c8868b4c 100644 --- a/lib/cli-compiler/src/store.rs +++ b/lib/cli-compiler/src/store.rs @@ -7,8 +7,8 @@ use std::string::ToString; #[allow(unused_imports)] use std::sync::Arc; use structopt::StructOpt; +use wasmer_compiler::UniversalEngineBuilder; use wasmer_compiler::{CompilerConfig, Features, PointerWidth, Target}; -use wasmer_engine_universal_artifact::UniversalEngineBuilder; use wasmer_types::{MemoryStyle, MemoryType, Pages, TableStyle, TableType}; /// Minimul Subset of Tunable parameters for WebAssembly compilation. diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index f4ad150b22b..b95ebfdbcb8 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-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 } wasmer-wasi-experimental-io-devices = { version = "=2.3.0", path = "../wasi-experimental-io-devices", optional = true } @@ -69,7 +68,6 @@ default = [ ] engine = [] universal = [ - "wasmer-engine-universal", "engine", ] cache = ["wasmer-cache"] @@ -80,7 +78,6 @@ emscripten = ["wasmer-emscripten"] wat = ["wasmer/wat"] compiler = [ "wasmer-compiler/translator", - "wasmer-engine-universal/compiler", ] experimental-io-devices = [ "wasmer-wasi-experimental-io-devices", diff --git a/lib/cli/src/commands/compile.rs b/lib/cli/src/commands/compile.rs index def15e91fd6..71c00eaad4f 100644 --- a/lib/cli/src/commands/compile.rs +++ b/lib/cli/src/commands/compile.rs @@ -41,7 +41,7 @@ impl Compile { Ok(match engine_type { #[cfg(feature = "universal")] EngineType::Universal => { - wasmer_engine_universal::UniversalArtifact::get_default_extension(target_triple) + wasmer_compiler::UniversalArtifact::get_default_extension(target_triple) } #[cfg(not(all(feature = "universal")))] _ => bail!("selected engine type is not compiled in"), diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index c4aad864c9e..dcad13f9927 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -225,8 +225,8 @@ impl Run { let contents = std::fs::read(self.path.clone())?; #[cfg(feature = "universal")] { - if wasmer_engine_universal::UniversalArtifact::is_deserializable(&contents) { - let engine = wasmer_engine_universal::Universal::headless().engine(); + if wasmer_compiler::UniversalArtifact::is_deserializable(&contents) { + let engine = wasmer_compiler::Universal::headless().engine(); let store = Store::new(&engine); let module = unsafe { Module::deserialize_from_file(&store, &self.path)? }; return Ok(module); @@ -309,7 +309,7 @@ impl Run { let extension = match *engine_type { #[cfg(feature = "universal")] EngineType::Universal => { - wasmer_engine_universal::UniversalArtifact::get_default_extension(&Triple::host()) + wasmer_compiler::UniversalArtifact::get_default_extension(&Triple::host()) .to_string() } // We use the compiler type as the default extension diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index d84f52561b3..fd062f74b56 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -129,7 +129,7 @@ impl CompilerOptions { let engine: Box = match engine_type { #[cfg(feature = "universal")] EngineType::Universal => Box::new( - wasmer_engine_universal::Universal::new(compiler_config) + wasmer_compiler::Universal::new(compiler_config) .features(features) .target(target) .engine(), @@ -392,9 +392,7 @@ impl StoreOptions { let engine_type = self.get_engine()?; let engine: Arc = match engine_type { #[cfg(feature = "universal")] - EngineType::Universal => { - Arc::new(wasmer_engine_universal::Universal::headless().engine()) - } + EngineType::Universal => Arc::new(wasmer_compiler::Universal::headless().engine()), #[cfg(not(all(feature = "universal")))] engine => bail!( "The `{}` engine is not included in this binary.", diff --git a/lib/compiler/Cargo.toml b/lib/compiler/Cargo.toml index 06116bfb56f..110308ae966 100644 --- a/lib/compiler/Cargo.toml +++ b/lib/compiler/Cargo.toml @@ -28,8 +28,16 @@ memmap2 = "0.5" more-asserts = "0.2" lazy_static = "1.4" +cfg-if = "1.0" +leb128 = "0.2" +enum-iterator = "0.7.0" + [target.'cfg(not(target_arch = "wasm32"))'.dependencies] wasmer-vm = { path = "../vm", version = "=2.3.0" } +region = { version = "3.0" } + +[target.'cfg(target_os = "windows")'.dependencies] +winapi = { version = "0.3", features = ["winnt", "impl-default"] } [features] default = ["std", "enable-serde" ] @@ -37,6 +45,7 @@ default = ["std", "enable-serde" ] # `CompilerConfig`, as well as the included wasmparser. # Disable this feature if you just want a headless engine. translator = ["wasmparser"] +universal_engine = [] std = ["wasmer-types/std"] core = ["hashbrown", "wasmer-types/core"] enable-serde = ["serde", "serde_bytes", "wasmer-types/enable-serde"] diff --git a/lib/compiler/src/engine/mod.rs b/lib/compiler/src/engine/mod.rs index a2c40958820..d01881fb203 100644 --- a/lib/compiler/src/engine/mod.rs +++ b/lib/compiler/src/engine/mod.rs @@ -8,6 +8,9 @@ mod resolver; mod trap; mod tunables; +#[cfg(feature = "translator")] +mod universal; + pub use self::artifact::Artifact; pub use self::error::{InstantiationError, LinkError}; pub use self::export::{Export, ExportFunction, ExportFunctionMetadata}; @@ -15,3 +18,6 @@ pub use self::inner::{Engine, EngineId}; pub use self::resolver::resolve_imports; pub use self::trap::*; pub use self::tunables::Tunables; + +#[cfg(feature = "translator")] +pub use self::universal::*; diff --git a/lib/engine-universal/src/artifact.rs b/lib/compiler/src/engine/universal/artifact.rs similarity index 94% rename from lib/engine-universal/src/artifact.rs rename to lib/compiler/src/engine/universal/artifact.rs index 11283533106..1ad5f86afc5 100644 --- a/lib/engine-universal/src/artifact.rs +++ b/lib/compiler/src/engine/universal/artifact.rs @@ -1,20 +1,18 @@ //! Define `UniversalArtifact`, based on `UniversalArtifactBuild` //! to allow compiling and instantiating to be done as separate steps. -use crate::engine::{UniversalEngine, UniversalEngineInner}; -use crate::link::link_module; -use enumset::EnumSet; -use std::sync::{Arc, Mutex}; -#[cfg(feature = "compiler")] -use wasmer_compiler::ModuleEnvironment; -use wasmer_compiler::{ +use super::engine::{UniversalEngine, UniversalEngineInner}; +use crate::engine::universal::link::link_module; +use crate::ArtifactCreate; +use crate::{ register_frame_info, Artifact, FunctionExtent, GlobalFrameInfoRegistration, MetadataHeader, }; -use wasmer_compiler::{CpuFeature, Features, Triple}; -#[cfg(feature = "compiler")] -use wasmer_compiler::{Engine, Tunables}; -use wasmer_engine_universal_artifact::ArtifactCreate; -use wasmer_engine_universal_artifact::{SerializableModule, UniversalArtifactBuild}; +use crate::{CpuFeature, Features, Triple}; +#[cfg(feature = "universal_engine")] +use crate::{Engine, ModuleEnvironment, Tunables}; +use crate::{SerializableModule, UniversalArtifactBuild}; +use enumset::EnumSet; +use std::sync::{Arc, Mutex}; use wasmer_types::entity::{BoxedSlice, PrimaryMap}; use wasmer_types::{ CompileError, DeserializeError, FunctionIndex, LocalFunctionIndex, MemoryIndex, ModuleInfo, @@ -39,7 +37,7 @@ pub struct UniversalArtifact { impl UniversalArtifact { /// Compile a data buffer into a `UniversalArtifactBuild`, which may then be instantiated. - #[cfg(feature = "compiler")] + #[cfg(feature = "universal_engine")] pub fn new( engine: &UniversalEngine, data: &[u8], @@ -72,7 +70,7 @@ impl UniversalArtifact { } /// Compile a data buffer into a `UniversalArtifactBuild`, which may then be instantiated. - #[cfg(not(feature = "compiler"))] + #[cfg(not(feature = "universal_engine"))] pub fn new(_engine: &UniversalEngine, _data: &[u8]) -> Result { Err(CompileError::Codegen( "Compilation is not enabled in the engine".to_string(), diff --git a/lib/engine-universal/src/builder.rs b/lib/compiler/src/engine/universal/builder.rs similarity index 91% rename from lib/engine-universal/src/builder.rs rename to lib/compiler/src/engine/universal/builder.rs index 0dd9fc0ef87..b5c80f64fd3 100644 --- a/lib/engine-universal/src/builder.rs +++ b/lib/compiler/src/engine/universal/builder.rs @@ -1,5 +1,5 @@ -use crate::UniversalEngine; -use wasmer_compiler::{CompilerConfig, Features, Target}; +use super::UniversalEngine; +use crate::{CompilerConfig, Features, Target}; /// The Universal builder pub struct Universal { @@ -44,7 +44,7 @@ impl Universal { } /// Build the `UniversalEngine` for this configuration - #[cfg(feature = "compiler")] + #[cfg(feature = "universal_engine")] pub fn engine(self) -> UniversalEngine { let target = self.target.unwrap_or_default(); if let Some(compiler_config) = self.compiler_config { @@ -59,7 +59,7 @@ impl Universal { } /// Build the `UniversalEngine` for this configuration - #[cfg(not(feature = "compiler"))] + #[cfg(not(feature = "universal_engine"))] pub fn engine(self) -> UniversalEngine { UniversalEngine::headless() } diff --git a/lib/engine-universal/src/code_memory.rs b/lib/compiler/src/engine/universal/code_memory.rs similarity index 99% rename from lib/engine-universal/src/code_memory.rs rename to lib/compiler/src/engine/universal/code_memory.rs index 68dfd08c74c..9c033347032 100644 --- a/lib/engine-universal/src/code_memory.rs +++ b/lib/compiler/src/engine/universal/code_memory.rs @@ -2,7 +2,7 @@ // Attributions: https://github.com/wasmerio/wasmer/blob/master/ATTRIBUTIONS.md //! Memory management for executable code. -use crate::unwind::UnwindRegistry; +use super::unwind::UnwindRegistry; use wasmer_types::{CompiledFunctionUnwindInfo, CustomSection, FunctionBody}; use wasmer_vm::{Mmap, VMFunctionBody}; diff --git a/lib/engine-universal/src/engine.rs b/lib/compiler/src/engine/universal/engine.rs similarity index 96% rename from lib/engine-universal/src/engine.rs rename to lib/compiler/src/engine/universal/engine.rs index 288959f68ab..28e4281492e 100644 --- a/lib/engine-universal/src/engine.rs +++ b/lib/compiler/src/engine/universal/engine.rs @@ -1,12 +1,12 @@ //! Universal compilation. +#[cfg(feature = "universal_engine")] +use crate::Compiler; +use crate::Target; +use crate::UniversalEngineBuilder; +use crate::{Artifact, Engine, EngineId, FunctionExtent, Tunables}; use crate::{CodeMemory, UniversalArtifact}; use std::sync::{Arc, Mutex}; -#[cfg(feature = "compiler")] -use wasmer_compiler::Compiler; -use wasmer_compiler::Target; -use wasmer_compiler::{Artifact, Engine, EngineId, FunctionExtent, Tunables}; -use wasmer_engine_universal_artifact::UniversalEngineBuilder; use wasmer_types::entity::PrimaryMap; use wasmer_types::FunctionBody; use wasmer_types::{ @@ -30,7 +30,7 @@ pub struct UniversalEngine { impl UniversalEngine { /// Create a new `UniversalEngine` with the given config - #[cfg(feature = "compiler")] + #[cfg(feature = "universal_engine")] pub fn new(compiler: Box, target: Target, features: Features) -> Self { Self { inner: Arc::new(Mutex::new(UniversalEngineInner { @@ -108,7 +108,7 @@ impl Engine for UniversalEngine { } /// Compile a WebAssembly binary - #[cfg(feature = "compiler")] + #[cfg(feature = "universal_engine")] fn compile( &self, binary: &[u8], @@ -118,7 +118,7 @@ impl Engine for UniversalEngine { } /// Compile a WebAssembly binary - #[cfg(not(feature = "compiler"))] + #[cfg(not(feature = "universal_engine"))] fn compile( &self, _binary: &[u8], @@ -162,7 +162,7 @@ pub struct UniversalEngineInner { impl UniversalEngineInner { /// Gets the compiler associated to this engine. - #[cfg(feature = "compiler")] + #[cfg(feature = "universal_engine")] pub fn compiler(&self) -> Result<&dyn Compiler, CompileError> { self.builder.compiler() } diff --git a/lib/engine-universal/src/link.rs b/lib/compiler/src/engine/universal/link.rs similarity index 97% rename from lib/engine-universal/src/link.rs rename to lib/compiler/src/engine/universal/link.rs index 86a91476e5a..713908a22fc 100644 --- a/lib/engine-universal/src/link.rs +++ b/lib/compiler/src/engine/universal/link.rs @@ -1,8 +1,8 @@ //! Linking for Universal-compiled code. +use crate::get_libcall_trampoline; +use crate::FunctionExtent; use std::ptr::{read_unaligned, write_unaligned}; -use wasmer_compiler::FunctionExtent; -use wasmer_engine_universal_artifact::get_libcall_trampoline; use wasmer_types::entity::PrimaryMap; use wasmer_types::{LocalFunctionIndex, ModuleInfo}; use wasmer_types::{Relocation, RelocationKind, RelocationTarget, Relocations, SectionIndex}; diff --git a/lib/compiler/src/engine/universal/mod.rs b/lib/compiler/src/engine/universal/mod.rs new file mode 100644 index 00000000000..d906828439d --- /dev/null +++ b/lib/compiler/src/engine/universal/mod.rs @@ -0,0 +1,18 @@ +//! Universal backend for Wasmer compilers. +//! +//! Given a compiler (such as `CraneliftCompiler` or `LLVMCompiler`) +//! it generates the compiled machine code, and publishes it into +//! memory so it can be used externally. + +mod artifact; +mod builder; +mod code_memory; +mod engine; +mod link; +mod unwind; + +pub use self::artifact::UniversalArtifact; +pub use self::builder::Universal; +pub use self::code_memory::CodeMemory; +pub use self::engine::UniversalEngine; +pub use self::link::link_module; diff --git a/lib/engine-universal/src/serialize.rs b/lib/compiler/src/engine/universal/serialize.rs similarity index 99% rename from lib/engine-universal/src/serialize.rs rename to lib/compiler/src/engine/universal/serialize.rs index 96847ae4896..e5c86b393e9 100644 --- a/lib/engine-universal/src/serialize.rs +++ b/lib/compiler/src/engine/universal/serialize.rs @@ -1,12 +1,12 @@ +use crate::{ + CompileModuleInfo, CompiledFunctionFrameInfo, CustomSection, Dwarf, FunctionBody, Relocation, + SectionIndex, +}; use rkyv::{ archived_value, de::deserializers::SharedDeserializeMap, ser::serializers::AllocSerializer, ser::Serializer as RkyvSerializer, Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize, }; -use wasmer_compiler::{ - CompileModuleInfo, CompiledFunctionFrameInfo, CustomSection, Dwarf, FunctionBody, Relocation, - SectionIndex, -}; use wasmer_engine::{DeserializeError, SerializeError}; use wasmer_types::entity::PrimaryMap; use wasmer_types::{FunctionIndex, LocalFunctionIndex, OwnedDataInitializer, SignatureIndex}; diff --git a/lib/engine-universal/src/unwind/dummy.rs b/lib/compiler/src/engine/universal/unwind/dummy.rs similarity index 100% rename from lib/engine-universal/src/unwind/dummy.rs rename to lib/compiler/src/engine/universal/unwind/dummy.rs diff --git a/lib/engine-universal/src/unwind/mod.rs b/lib/compiler/src/engine/universal/unwind/mod.rs similarity index 100% rename from lib/engine-universal/src/unwind/mod.rs rename to lib/compiler/src/engine/universal/unwind/mod.rs diff --git a/lib/engine-universal/src/unwind/systemv.rs b/lib/compiler/src/engine/universal/unwind/systemv.rs similarity index 100% rename from lib/engine-universal/src/unwind/systemv.rs rename to lib/compiler/src/engine/universal/unwind/systemv.rs diff --git a/lib/engine-universal/src/unwind/windows_x64.rs b/lib/compiler/src/engine/universal/unwind/windows_x64.rs similarity index 100% rename from lib/engine-universal/src/unwind/windows_x64.rs rename to lib/compiler/src/engine/universal/unwind/windows_x64.rs diff --git a/lib/compiler/src/lib.rs b/lib/compiler/src/lib.rs index a63d271f9c3..d018fcf8257 100644 --- a/lib/compiler/src/lib.rs +++ b/lib/compiler/src/lib.rs @@ -59,6 +59,12 @@ pub use crate::artifact::*; #[cfg(not(target_arch = "wasm32"))] pub use crate::engine::*; +#[cfg(feature = "translator")] +mod universal_artifact; + +#[cfg(feature = "translator")] +pub use self::universal_artifact::*; + #[cfg(feature = "translator")] mod compiler; mod target; diff --git a/lib/universal-artifact/src/artifact.rs b/lib/compiler/src/universal_artifact/artifact.rs similarity index 93% rename from lib/universal-artifact/src/artifact.rs rename to lib/compiler/src/universal_artifact/artifact.rs index 92047ec35bc..08ebe14c121 100644 --- a/lib/universal-artifact/src/artifact.rs +++ b/lib/compiler/src/universal_artifact/artifact.rs @@ -1,26 +1,29 @@ //! Define `UniversalArtifactBuild` to allow compiling and instantiating to be //! done as separate steps. -use crate::serialize::SerializableCompilation; -use crate::serialize::SerializableModule; -#[cfg(feature = "compiler")] -use crate::trampoline::{libcall_trampoline_len, make_libcall_trampolines}; +#[cfg(feature = "universal_engine")] +use super::serialize::SerializableCompilation; +use super::serialize::SerializableModule; +#[cfg(feature = "universal_engine")] +use super::trampoline::{libcall_trampoline_len, make_libcall_trampolines}; +use crate::MetadataHeader; use crate::{ArtifactCreate, UniversalEngineBuilder}; +use crate::{CpuFeature, Features, Triple}; +#[cfg(feature = "universal_engine")] +use crate::{ModuleEnvironment, ModuleMiddlewareChain, Target}; use enumset::EnumSet; use std::mem; use std::sync::Arc; -use wasmer_compiler::MetadataHeader; -use wasmer_compiler::{ - CpuFeature, Features, ModuleEnvironment, ModuleMiddlewareChain, Target, Triple, -}; use wasmer_types::entity::PrimaryMap; +#[cfg(feature = "universal_engine")] +use wasmer_types::CompileModuleInfo; use wasmer_types::SerializeError; use wasmer_types::{ CompileError, CustomSection, Dwarf, FunctionIndex, LocalFunctionIndex, MemoryIndex, MemoryStyle, ModuleInfo, OwnedDataInitializer, Relocation, SectionIndex, SignatureIndex, TableIndex, TableStyle, }; -use wasmer_types::{CompileModuleInfo, CompiledFunctionFrameInfo, FunctionBody}; +use wasmer_types::{CompiledFunctionFrameInfo, FunctionBody}; /// A compiled wasm module, ready to be instantiated. pub struct UniversalArtifactBuild { @@ -37,7 +40,7 @@ impl UniversalArtifactBuild { } /// Compile a data buffer into a `UniversalArtifactBuild`, which may then be instantiated. - #[cfg(feature = "compiler")] + #[cfg(feature = "universal_engine")] pub fn new( inner_engine: &mut UniversalEngineBuilder, data: &[u8], @@ -116,7 +119,7 @@ impl UniversalArtifactBuild { } /// Compile a data buffer into a `UniversalArtifactBuild`, which may then be instantiated. - #[cfg(not(feature = "compiler"))] + #[cfg(not(feature = "universal_engine"))] pub fn new(_engine: &UniversalEngineBuilder, _data: &[u8]) -> Result { Err(CompileError::Codegen( "Compilation is not enabled in the engine".to_string(), diff --git a/lib/universal-artifact/src/engine.rs b/lib/compiler/src/universal_artifact/engine.rs similarity index 57% rename from lib/universal-artifact/src/engine.rs rename to lib/compiler/src/universal_artifact/engine.rs index 0810b742085..6153dea1807 100644 --- a/lib/universal-artifact/src/engine.rs +++ b/lib/compiler/src/universal_artifact/engine.rs @@ -1,13 +1,11 @@ //! Universal compilation. -#[cfg(feature = "compiler")] -use wasmer_compiler::Compiler; +use crate::Compiler; use wasmer_types::{CompileError, Features}; /// The Builder contents of `UniversalEngine` pub struct UniversalEngineBuilder { /// The compiler - #[cfg(feature = "compiler")] compiler: Option>, /// The features to compile the Wasm module with features: Features, @@ -15,13 +13,11 @@ pub struct UniversalEngineBuilder { impl UniversalEngineBuilder { /// Create a new builder with pre-made components - #[cfg(feature = "compiler")] pub fn new(compiler: Option>, features: Features) -> Self { Self { compiler, features } } /// Gets the compiler associated to this engine. - #[cfg(feature = "compiler")] pub fn compiler(&self) -> Result<&dyn Compiler, CompileError> { if self.compiler.is_none() { return Err(CompileError::Codegen( @@ -30,30 +26,11 @@ impl UniversalEngineBuilder { } Ok(&**self.compiler.as_ref().unwrap()) } - - /// Gets the compiler associated to this engine. - #[cfg(not(feature = "compiler"))] - pub fn compiler(&self) -> Result<&dyn Compiler, CompileError> { - return Err(CompileError::Codegen( - "The UniversalEngine is not compiled in.".to_string(), - )); - } - /// Validate the module - #[cfg(feature = "compiler")] pub fn validate(&self, data: &[u8]) -> Result<(), CompileError> { self.compiler()?.validate_module(self.features(), data) } - /// Validate the module - #[cfg(not(feature = "compiler"))] - pub fn validate<'data>(&self, _data: &'data [u8]) -> Result<(), CompileError> { - Err(CompileError::Validate( - "The UniversalEngine is not compiled with compiler support, which is required for validating" - .to_string(), - )) - } - /// The Wasm features pub fn features(&self) -> &Features { &self.features diff --git a/lib/compiler/src/universal_artifact/mod.rs b/lib/compiler/src/universal_artifact/mod.rs new file mode 100644 index 00000000000..3a081e84467 --- /dev/null +++ b/lib/compiler/src/universal_artifact/mod.rs @@ -0,0 +1,11 @@ +//! Generic Artifact abstraction for Wasmer Engines. + +mod artifact; +mod engine; +mod serialize; +mod trampoline; + +pub use self::artifact::UniversalArtifactBuild; +pub use self::engine::UniversalEngineBuilder; +pub use self::serialize::SerializableModule; +pub use self::trampoline::*; diff --git a/lib/universal-artifact/src/serialize.rs b/lib/compiler/src/universal_artifact/serialize.rs similarity index 100% rename from lib/universal-artifact/src/serialize.rs rename to lib/compiler/src/universal_artifact/serialize.rs diff --git a/lib/universal-artifact/src/trampoline.rs b/lib/compiler/src/universal_artifact/trampoline.rs similarity index 98% rename from lib/universal-artifact/src/trampoline.rs rename to lib/compiler/src/universal_artifact/trampoline.rs index 77b9ded3a9f..135827072b0 100644 --- a/lib/universal-artifact/src/trampoline.rs +++ b/lib/compiler/src/universal_artifact/trampoline.rs @@ -3,8 +3,8 @@ //! This is needed because the target of libcall relocations are not reachable //! through normal branch instructions. +use crate::{Architecture, Target}; use enum_iterator::IntoEnumIterator; -use wasmer_compiler::{Architecture, Target}; use wasmer_types::{ CustomSection, CustomSectionProtection, LibCall, Relocation, RelocationKind, RelocationTarget, SectionBody, diff --git a/lib/engine-universal/Cargo.toml b/lib/engine-universal/Cargo.toml deleted file mode 100644 index a9c4c0c6458..00000000000 --- a/lib/engine-universal/Cargo.toml +++ /dev/null @@ -1,40 +0,0 @@ -[package] -name = "wasmer-engine-universal" -version = "2.3.0" -description = "Wasmer Universal Engine" -categories = ["wasm"] -keywords = ["wasm", "webassembly", "engine", "universal"] -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-engine-universal-artifact = { path = "../universal-artifact", version = "=2.3.0", features = [ - "compiler", -] } -wasmer-types = { path = "../types", version = "=2.3.0" } -wasmer-compiler = { path = "../compiler", version = "=2.3.0", features = [ - "translator", -] } -wasmer-vm = { path = "../vm", version = "=2.3.0" } -# flexbuffers = { path = "../../../flatbuffers/rust/flexbuffers", version = "0.1.0" } -cfg-if = "1.0" -leb128 = "0.2" -rkyv = { version = "0.7.38", features = ["indexmap"] } -enumset = "1.0" - -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] -region = { version = "3.0" } - -[target.'cfg(target_os = "windows")'.dependencies] -winapi = { version = "0.3", features = ["winnt", "impl-default"] } - -[features] -# Enable the `compiler` feature if you want the engine to compile -# and not be only on headless mode. -compiler = ["wasmer-compiler/translator"] - -[badges] -maintenance = { status = "actively-developed" } diff --git a/lib/engine-universal/README.md b/lib/engine-universal/README.md deleted file mode 100644 index 93d9ac321f5..00000000000 --- a/lib/engine-universal/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# `wasmer-engine-universal` [![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) - -The Wasmer Universal engine is usable with any compiler implementation based -on [`wasmer-compiler`]. After the compiler process the result, the Universal -pushes it into memory and links its contents so it can be usable by -the [`wasmer`] API. - -*Note: you can find a [full working example using the Universal engine -here][example].* - -### Acknowledgments - -This project borrowed some of the code of the code memory and unwind -tables from the [`wasmtime-jit`], the code since then has evolved -significantly. - -Please check [Wasmer `ATTRIBUTIONS`] to further see licenses and other -attributions of the project. - - -[`wasmer-compiler`]: https://github.com/wasmerio/wasmer/tree/master/lib/compiler -[`wasmer`]: https://github.com/wasmerio/wasmer/tree/master/lib/api -[example]: https://github.com/wasmerio/wasmer/blob/master/examples/engine_universal.rs -[`wasmtime-jit`]: https://crates.io/crates/wasmtime-jit -[Wasmer `ATTRIBUTIONS`]: https://github.com/wasmerio/wasmer/blob/master/ATTRIBUTIONS.md diff --git a/lib/engine-universal/src/lib.rs b/lib/engine-universal/src/lib.rs deleted file mode 100644 index 68afde89054..00000000000 --- a/lib/engine-universal/src/lib.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! Universal backend for Wasmer compilers. -//! -//! Given a compiler (such as `CraneliftCompiler` or `LLVMCompiler`) -//! it generates the compiled machine code, and publishes it into -//! memory so it can be used externally. - -#![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 builder; -mod code_memory; -mod engine; -mod link; -mod unwind; - -pub use crate::artifact::UniversalArtifact; -pub use crate::builder::Universal; -pub use crate::code_memory::CodeMemory; -pub use crate::engine::UniversalEngine; -pub use crate::link::link_module; - -/// 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 deleted file mode 100644 index 819d4e89de7..00000000000 --- a/lib/universal-artifact/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "wasmer-engine-universal-artifact" -version = "2.3.0" -description = "Wasmer Engine Universal 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", features = ["translator", ] } -thiserror = "1.0" -enumset = "1.0" -rkyv = "0.7.20" -enum-iterator = "0.7.0" - -[features] -compiler = [] - -[badges] -maintenance = { status = "actively-developed" } diff --git a/lib/universal-artifact/README.md b/lib/universal-artifact/README.md deleted file mode 100644 index 8bb8b76024e..00000000000 --- a/lib/universal-artifact/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# `wasmer-engine-universal-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 generating 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/universal-artifact/src/lib.rs b/lib/universal-artifact/src/lib.rs deleted file mode 100644 index 85cf7c6769c..00000000000 --- a/lib/universal-artifact/src/lib.rs +++ /dev/null @@ -1,34 +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 engine; -mod serialize; -mod trampoline; - -pub use crate::artifact::UniversalArtifactBuild; -pub use crate::engine::UniversalEngineBuilder; -pub use crate::serialize::SerializableModule; -pub use crate::trampoline::*; -pub use wasmer_compiler::{ArtifactCreate, MetadataHeader, Upcastable}; - -/// Version number of this crate. -pub const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/tests/compilers/config.rs b/tests/compilers/config.rs index 6b2146446cb..adff7b87bb1 100644 --- a/tests/compilers/config.rs +++ b/tests/compilers/config.rs @@ -60,7 +60,7 @@ impl Config { match &self.engine { #[cfg(feature = "universal")] Engine::Universal => { - let mut engine = wasmer_engine_universal::Universal::new(compiler_config); + let mut engine = wasmer_compiler::Universal::new(compiler_config); if let Some(ref features) = self.features { engine = engine.features(features.clone()) } @@ -77,7 +77,7 @@ impl Config { pub fn engine_headless(&self) -> Box { match &self.engine { #[cfg(feature = "universal")] - Engine::Universal => Box::new(wasmer_engine_universal::Universal::headless().engine()), + Engine::Universal => Box::new(wasmer_compiler::Universal::headless().engine()), #[allow(unreachable_patterns)] engine => panic!( "The {:?} Engine is not enabled. Please enable it using the features",