diff --git a/Cargo.toml b/Cargo.toml index 3606f41..f3d96a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ readme = "./README.md" [target.'cfg(not(target_family="wasm"))'.dev-dependencies] -wasmy-vm = "0.5.5" +wasmy-vm = { version ="0.5.5", features = [] } structopt = { version = "0.3", features = ["color"] } tokio = { version = "1.17.0", features = ["macros", "rt", "rt-multi-thread"] } [[example]] diff --git a/wasmy-vm/Cargo.toml b/wasmy-vm/Cargo.toml index b96bee0..6c49245 100644 --- a/wasmy-vm/Cargo.toml +++ b/wasmy-vm/Cargo.toml @@ -20,10 +20,13 @@ inventory = "0.2.2" wasmer = "2.0.0" wasmer-engine-universal = "2.0.0" wasmer-wasi = "2.0.0" -wasmer-compiler-cranelift = { version = "2.0.0" } +wasmer-compiler-cranelift = { version = "2.0.0", optional = true } +wasmer-compiler-llvm = { version = "2.0.0", optional = true } serde = { version = "1.0", features = ["derive"] } anyhow = "1" protobuf = { version = "2", features = ["with-bytes"] } lazy_static = "1.4.0" [features] +default = ["wasmer-compiler-cranelift"] +llvm = ["wasmer-compiler-llvm"] diff --git a/wasmy-vm/src/modules.rs b/wasmy-vm/src/modules.rs index b067b2a..1db0437 100644 --- a/wasmy-vm/src/modules.rs +++ b/wasmy-vm/src/modules.rs @@ -2,7 +2,6 @@ use std::{collections::HashMap, sync::RwLock}; use lazy_static; use wasmer::{ImportObject, Store, Type}; -use wasmer_compiler_cranelift::Cranelift; use wasmer_engine_universal::Universal; use wasmer_wasi::{WasiState, WasiStateBuilder}; use wasmy_abi::{CodeMsg, Result, CODE_EXPORTS}; @@ -42,7 +41,20 @@ where #[cfg(debug_assertions)] println!("compiling module, wasm_uri={}...", wasm_uri); - let store: Store = Store::new(&Universal::new(Cranelift::default()).engine()); + + let compiler_config; + + #[cfg(not(feature = "llvm"))] + { + compiler_config = wasmer_compiler_cranelift::Cranelift::default(); + } + + #[cfg(feature = "llvm")] + { + compiler_config = wasmer_compiler_llvm::LLVM::default(); + } + + let store: Store = Store::new(&Universal::new(compiler_config).engine()); let mut module = wasmer::Module::new(&store, bytes)?; module.set_name(wasm_uri.as_str()); if let Some(cf) = check_module {