From 746229c96da9e7c73cee2b50b117d098e85b0f10 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Wed, 15 Jun 2022 13:21:55 +0300 Subject: [PATCH] wasmer-cli: remove configuration options for engines Since there's now only one engine, no need to expose it to the user. --- lib/cli/Cargo.toml | 12 +-- lib/cli/README.md | 4 +- lib/cli/src/bin/wasmer.rs | 2 +- lib/cli/src/commands/compile.rs | 23 +---- lib/cli/src/commands/inspect.rs | 2 +- lib/cli/src/commands/run.rs | 43 +++------ lib/cli/src/commands/validate.rs | 2 +- lib/cli/src/commands/wast.rs | 2 +- lib/cli/src/store.rs | 150 +++++++------------------------ 9 files changed, 54 insertions(+), 186 deletions(-) diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index b95ebfdbcb8..1a9ef08e683 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -26,7 +26,7 @@ required-features = ["headless"] [dependencies] wasmer = { version = "=2.3.0", path = "../api", default-features = false } -wasmer-compiler = { version = "=2.3.0", path = "../compiler" } +wasmer-compiler = { version = "=2.3.0", path = "../compiler", features = ["universal_engine", ] } wasmer-compiler-cranelift = { version = "=2.3.0", path = "../compiler-cranelift", optional = true } wasmer-compiler-singlepass = { version = "=2.3.0", path = "../compiler-singlepass", optional = true } wasmer-compiler-llvm = { version = "=2.3.0", path = "../compiler-llvm", optional = true } @@ -61,15 +61,10 @@ unix_mode = "0.1.3" default = [ "wat", "wast", - "universal", "cache", "wasi", "emscripten", ] -engine = [] -universal = [ - "engine", -] cache = ["wasmer-cache"] cache-blake3-pure = ["wasmer-cache/blake3-pure"] wast = ["wasmer-wast"] @@ -98,7 +93,4 @@ llvm = [ debug = ["fern", "log", "wasmer-wasi/logging"] disable-all-logging = ["wasmer-wasi/disable-all-logging"] headless = [] -headless-minimal = ["headless", "disable-all-logging", "wasi", "universal"] - -# Deprecated features. -jit = ["universal"] +headless-minimal = ["headless", "disable-all-logging", "wasi"] diff --git a/lib/cli/README.md b/lib/cli/README.md index acb99b7345b..e6332d4998c 100644 --- a/lib/cli/README.md +++ b/lib/cli/README.md @@ -25,7 +25,6 @@ cargo build --release --features "singlepass,cranelift" The Wasmer supports the following features: * `wat` (default): support for executing WebAssembly text files. * `wast`(default): support for running wast test files. -* `universal` (default): support for the [Universal engine]. * `cache` (default): support or automatically caching compiled artifacts. * `wasi` (default): support for [WASI]. * `experimental-io-devices`: support for experimental IO devices in WASI. @@ -34,7 +33,6 @@ The Wasmer supports the following features: * `cranelift`: support for the [Cranelift compiler]. * `llvm`: support for the [LLVM compiler]. -[Universal engine]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-universal/ [WASI]: https://github.com/wasmerio/wasmer/tree/master/lib/wasi/ [Emscripten]: https://github.com/wasmerio/wasmer/tree/master/lib/emscripten/ [Singlepass compiler]: https://github.com/wasmerio/wasmer/tree/master/lib/compiler-singlepass/ @@ -60,7 +58,7 @@ wasmer run myfile.wasm Compile a WebAssembly file: ```bash -wasmer compile myfile.wasm -o myfile.wasmu --universal +wasmer compile myfile.wasm -o myfile.wasmu ``` Run a compiled WebAssembly file (fastest): diff --git a/lib/cli/src/bin/wasmer.rs b/lib/cli/src/bin/wasmer.rs index 8f781e1f8cd..102672d8236 100644 --- a/lib/cli/src/bin/wasmer.rs +++ b/lib/cli/src/bin/wasmer.rs @@ -2,7 +2,7 @@ use wasmer_cli::cli::wasmer_main; #[cfg(not(any(feature = "cranelift", feature = "singlepass", feature = "llvm")))] compile_error!( - "Either enable at least one compiler, or compile the wasmer-headless binary instead" + "Either enable at least one compiler, or compile the wasmer-headless binary instead.\nWith cargo, you can provide a compiler option with the --features flag.\n\nExample values:\n\n\t\t--features compiler,cranelift\n\t\t--features compiler,cranelift,singlepass\n\n\n" ); fn main() { diff --git a/lib/cli/src/commands/compile.rs b/lib/cli/src/commands/compile.rs index 71c00eaad4f..f3bc3b9fafb 100644 --- a/lib/cli/src/commands/compile.rs +++ b/lib/cli/src/commands/compile.rs @@ -1,4 +1,4 @@ -use crate::store::{EngineType, StoreOptions}; +use crate::store::StoreOptions; use crate::warning; use anyhow::{Context, Result}; use std::path::PathBuf; @@ -34,20 +34,6 @@ impl Compile { .context(format!("failed to compile `{}`", self.path.display())) } - pub(crate) fn get_recommend_extension( - engine_type: &EngineType, - target_triple: &Triple, - ) -> Result<&'static str> { - Ok(match engine_type { - #[cfg(feature = "universal")] - EngineType::Universal => { - wasmer_compiler::UniversalArtifact::get_default_extension(target_triple) - } - #[cfg(not(all(feature = "universal")))] - _ => bail!("selected engine type is not compiled in"), - }) - } - fn inner_execute(&self) -> Result<()> { let target = self .target_triple @@ -64,14 +50,14 @@ impl Compile { Target::new(target_triple.clone(), features) }) .unwrap_or_default(); - let (store, engine_type, compiler_type) = - self.store.get_store_for_target(target.clone())?; + let (store, compiler_type) = self.store.get_store_for_target(target.clone())?; let output_filename = self .output .file_stem() .map(|osstr| osstr.to_string_lossy().to_string()) .unwrap_or_default(); - let recommended_extension = Self::get_recommend_extension(&engine_type, target.triple())?; + let recommended_extension = + wasmer_compiler::UniversalArtifact::get_default_extension(target.triple()); match self.output.extension() { Some(ext) => { if ext != recommended_extension { @@ -82,7 +68,6 @@ impl Compile { warning!("the output file has no extension. We recommend using `{}.{}` for the chosen target", &output_filename, &recommended_extension) } } - println!("Engine: {}", engine_type.to_string()); println!("Compiler: {}", compiler_type.to_string()); println!("Target: {}", target.triple()); diff --git a/lib/cli/src/commands/inspect.rs b/lib/cli/src/commands/inspect.rs index 4858c749ac8..e1a99e618bd 100644 --- a/lib/cli/src/commands/inspect.rs +++ b/lib/cli/src/commands/inspect.rs @@ -23,7 +23,7 @@ impl Inspect { .context(format!("failed to inspect `{}`", self.path.display())) } fn inner_execute(&self) -> Result<()> { - let (store, _engine_type, _compiler_type) = self.store.get_store()?; + let (store, _compiler_type) = self.store.get_store()?; let module_contents = std::fs::read(&self.path)?; let module = Module::new(&store, &module_contents)?; println!( diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index dcad13f9927..23cb6f77fd6 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -1,7 +1,7 @@ use crate::common::get_cache_dir; #[cfg(feature = "debug")] use crate::logging; -use crate::store::{CompilerType, EngineType, StoreOptions}; +use crate::store::{CompilerType, StoreOptions}; use crate::suggestions::suggest_function_exports; use crate::warning; use anyhow::{anyhow, Context, Result}; @@ -223,19 +223,16 @@ impl Run { fn get_module(&self) -> Result { let contents = std::fs::read(self.path.clone())?; - #[cfg(feature = "universal")] - { - 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); - } + 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); } - let (store, engine_type, compiler_type) = self.store.get_store()?; + let (store, compiler_type) = self.store.get_store()?; #[cfg(feature = "cache")] let module_result: Result = if !self.disable_cache && contents.len() > 0x1000 { - self.get_module_from_cache(&store, &contents, &engine_type, &compiler_type) + self.get_module_from_cache(&store, &contents, &compiler_type) } else { Module::new(&store, &contents).map_err(|e| e.into()) }; @@ -244,8 +241,7 @@ impl Run { let mut module = module_result.with_context(|| { format!( - "module instantiation failed (engine: {}, compiler: {})", - engine_type.to_string(), + "module instantiation failed (compiler: {})", compiler_type.to_string() ) })?; @@ -260,14 +256,13 @@ impl Run { &self, store: &Store, contents: &[u8], - engine_type: &EngineType, compiler_type: &CompilerType, ) -> Result { // We try to get it from cache, in case caching is enabled // and the file length is greater than 4KB. // For files smaller than 4KB caching is not worth, // as it takes space and the speedup is minimal. - let mut cache = self.get_cache(engine_type, compiler_type)?; + let mut cache = self.get_cache(compiler_type)?; // Try to get the hash from the provided `--cache-key`, otherwise // generate one from the provided file `.wasm` contents. let hash = self @@ -296,25 +291,13 @@ impl Run { #[cfg(feature = "cache")] /// Get the Compiler Filesystem cache - fn get_cache( - &self, - engine_type: &EngineType, - compiler_type: &CompilerType, - ) -> Result { + fn get_cache(&self, compiler_type: &CompilerType) -> Result { let mut cache_dir_root = get_cache_dir(); cache_dir_root.push(compiler_type.to_string()); let mut cache = FileSystemCache::new(cache_dir_root)?; - #[allow(unreachable_patterns)] - let extension = match *engine_type { - #[cfg(feature = "universal")] - EngineType::Universal => { - wasmer_compiler::UniversalArtifact::get_default_extension(&Triple::host()) - .to_string() - } - // We use the compiler type as the default extension - _ => compiler_type.to_string(), - }; + let extension = + wasmer_compiler::UniversalArtifact::get_default_extension(&Triple::host()).to_string(); cache.set_cache_extension(Some(extension)); Ok(cache) } diff --git a/lib/cli/src/commands/validate.rs b/lib/cli/src/commands/validate.rs index fb9554d684e..f429c8ab6b5 100644 --- a/lib/cli/src/commands/validate.rs +++ b/lib/cli/src/commands/validate.rs @@ -22,7 +22,7 @@ impl Validate { .context(format!("failed to validate `{}`", self.path.display())) } fn inner_execute(&self) -> Result<()> { - let (store, _engine_type, _compiler_type) = self.store.get_store()?; + let (store, _compiler_type) = self.store.get_store()?; let module_contents = std::fs::read(&self.path)?; if !is_wasm(&module_contents) { bail!("`wasmer validate` only validates WebAssembly files"); diff --git a/lib/cli/src/commands/wast.rs b/lib/cli/src/commands/wast.rs index 2837069f21f..580bdb205e1 100644 --- a/lib/cli/src/commands/wast.rs +++ b/lib/cli/src/commands/wast.rs @@ -27,7 +27,7 @@ impl Wast { .context(format!("failed to test the wast `{}`", self.path.display())) } fn inner_execute(&self) -> Result<()> { - let (store, _engine_name, _compiler_name) = self.store.get_store()?; + let (store, _compiler_name) = self.store.get_store()?; let mut wast = WastSpectest::new_with_spectest(store); wast.fail_fast = self.fail_fast; wast.run_file(&self.path).with_context(|| "tests failed")?; diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index fd062f74b56..287729d2500 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -16,19 +16,11 @@ use wasmer::*; use wasmer_compiler::CompilerConfig; #[derive(Debug, Clone, StructOpt, Default)] -/// The compiler and engine options +/// The compiler options pub struct StoreOptions { #[cfg(feature = "compiler")] #[structopt(flatten)] compiler: CompilerOptions, - - /// Use the Universal Engine. - #[structopt(long, conflicts_with_all = &["jit"])] - universal: bool, - - /// Use the JIT (Universal) Engine. - #[structopt(long, hidden = true, conflicts_with_all = &["universal"])] - jit: bool, } #[cfg(feature = "compiler")] @@ -49,6 +41,7 @@ pub struct CompilerOptions { /// Enable compiler internal verification. #[structopt(long)] + #[cfg(any(feature = "singlepass", feature = "cranelift", feature = "llvm"))] enable_verifier: bool, /// LLVM debug directory, where IR and object files will be written to. @@ -107,39 +100,26 @@ impl CompilerOptions { Ok(features) } - /// Gets the Store for a given target and engine. - pub fn get_store_for_target_and_engine( - &self, - target: Target, - engine_type: EngineType, - ) -> Result<(Store, CompilerType)> { + /// Gets the Store for a given target. + pub fn get_store_for_target(&self, target: Target) -> Result<(Store, CompilerType)> { let (compiler_config, compiler_type) = self.get_compiler_config()?; - let engine = self.get_engine_by_type(target, compiler_config, engine_type)?; + let engine = self.get_engine(target, compiler_config)?; let store = Store::new(&*engine); Ok((store, compiler_type)) } - fn get_engine_by_type( + fn get_engine( &self, target: Target, compiler_config: Box, - engine_type: EngineType, ) -> Result> { let features = self.get_features(compiler_config.default_features_for_target(&target))?; - let engine: Box = match engine_type { - #[cfg(feature = "universal")] - EngineType::Universal => Box::new( - wasmer_compiler::Universal::new(compiler_config) - .features(features) - .target(target) - .engine(), - ), - #[cfg(not(all(feature = "universal")))] - engine => bail!( - "The `{}` engine is not included in this binary.", - engine.to_string() - ), - }; + let engine: Box = Box::new( + wasmer_compiler::Universal::new(compiler_config) + .features(features) + .target(target) + .engine(), + ); Ok(engine) } @@ -321,116 +301,46 @@ impl ToString for CompilerType { } } -/// The engine used for the store -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum EngineType { - /// Universal Engine - Universal, -} - -impl ToString for EngineType { - fn to_string(&self) -> String { - match self { - Self::Universal => "universal".to_string(), - } - } -} - -#[cfg(all(feature = "compiler", feature = "engine"))] +#[cfg(all(feature = "compiler"))] impl StoreOptions { - /// Gets the store for the host target, with the engine name and compiler name selected - pub fn get_store(&self) -> Result<(Store, EngineType, CompilerType)> { + /// Gets the store for the host target, with the compiler name selected + pub fn get_store(&self) -> Result<(Store, CompilerType)> { let target = Target::default(); self.get_store_for_target(target) } - /// Gets the store for a given target, with the engine name and compiler name selected, as - pub fn get_store_for_target( - &self, - target: Target, - ) -> Result<(Store, EngineType, CompilerType)> { + /// Gets the store for a given target, with the compiler name selected. + pub fn get_store_for_target(&self, target: Target) -> Result<(Store, CompilerType)> { let (compiler_config, compiler_type) = self.compiler.get_compiler_config()?; - let (engine, engine_type) = self.get_engine_with_compiler(target, compiler_config)?; + let engine = self.get_engine_with_compiler(target, compiler_config)?; let store = Store::new(&*engine); - Ok((store, engine_type, compiler_type)) + Ok((store, compiler_type)) } fn get_engine_with_compiler( &self, target: Target, compiler_config: Box, - ) -> Result<(Box, EngineType)> { - let engine_type = self.get_engine()?; - let engine = self - .compiler - .get_engine_by_type(target, compiler_config, engine_type)?; - - Ok((engine, engine_type)) - } -} + ) -> Result> { + let engine = self.compiler.get_engine(target, compiler_config)?; -#[cfg(feature = "engine")] -impl StoreOptions { - fn get_engine(&self) -> Result { - if self.universal || self.jit { - Ok(EngineType::Universal) - } else { - // Auto mode, we choose the best engine for that platform - if cfg!(feature = "universal") { - Ok(EngineType::Universal) - } else { - bail!("There are no available engines for your architecture") - } - } + Ok(engine) } } // If we don't have a compiler, but we have an engine -#[cfg(all(not(feature = "compiler"), feature = "engine"))] +#[cfg(not(feature = "compiler"))] impl StoreOptions { - fn get_engine_headless(&self) -> Result<(Arc, EngineType)> { - let engine_type = self.get_engine()?; - let engine: Arc = match engine_type { - #[cfg(feature = "universal")] - EngineType::Universal => Arc::new(wasmer_compiler::Universal::headless().engine()), - #[cfg(not(all(feature = "universal")))] - engine => bail!( - "The `{}` engine is not included in this binary.", - engine.to_string() - ), - }; - Ok((engine, engine_type)) + fn get_engine_headless(&self) -> Result> { + let engine: Arc = + Arc::new(wasmer_compiler::Universal::headless().engine()); + Ok(engine) } /// Get the store (headless engine) - pub fn get_store(&self) -> Result<(Store, EngineType, CompilerType)> { - let (engine, engine_type) = self.get_engine_headless()?; + pub fn get_store(&self) -> Result<(Store, CompilerType)> { + let engine = self.get_engine_headless()?; let store = Store::new(&*engine); - Ok((store, engine_type, CompilerType::Headless)) - } - - /// Gets the store for provided host target - pub fn get_store_for_target( - &self, - _target: Target, - ) -> Result<(Store, EngineType, CompilerType)> { - bail!("You need compilers to retrieve a store for a specific target"); - } -} - -// If we don't have any engine enabled -#[cfg(not(feature = "engine"))] -impl StoreOptions { - /// Get the store (headless engine) - pub fn get_store(&self) -> Result<(Store, EngineType, CompilerType)> { - bail!("No engines are enabled"); - } - - /// Gets the store for the host target - pub fn get_store_for_target( - &self, - _target: Target, - ) -> Result<(Store, EngineType, CompilerType)> { - bail!("No engines are enabled"); + Ok((store, CompilerType::Headless)) } }