Skip to content

Commit

Permalink
wasmer-cli: remove configuration options for engines
Browse files Browse the repository at this point in the history
Since there's now only one engine, no need to expose it to the user.
  • Loading branch information
epilys committed Jun 15, 2022
1 parent 22b2b0d commit 746229c
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 186 deletions.
12 changes: 2 additions & 10 deletions lib/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
4 changes: 1 addition & 3 deletions lib/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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/
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/src/bin/wasmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
23 changes: 4 additions & 19 deletions lib/cli/src/commands/compile.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::store::{EngineType, StoreOptions};
use crate::store::StoreOptions;
use crate::warning;
use anyhow::{Context, Result};
use std::path::PathBuf;
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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());

Expand Down
2 changes: 1 addition & 1 deletion lib/cli/src/commands/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
43 changes: 13 additions & 30 deletions lib/cli/src/commands/run.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -223,19 +223,16 @@ impl Run {

fn get_module(&self) -> Result<Module> {
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<Module> = 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())
};
Expand All @@ -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()
)
})?;
Expand All @@ -260,14 +256,13 @@ impl Run {
&self,
store: &Store,
contents: &[u8],
engine_type: &EngineType,
compiler_type: &CompilerType,
) -> Result<Module> {
// 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
Expand Down Expand Up @@ -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<FileSystemCache> {
fn get_cache(&self, compiler_type: &CompilerType) -> Result<FileSystemCache> {
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)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/src/commands/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/src/commands/wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?;
Expand Down
Loading

0 comments on commit 746229c

Please sign in to comment.