From ccf55b2d727c1f80bf7ab3888e30cd5c40b89809 Mon Sep 17 00:00:00 2001 From: henrylee2cn Date: Tue, 15 Mar 2022 20:02:29 +0800 Subject: [PATCH] chore(vm): add llvm feature --- Cargo.toml | 2 +- wasmy-vm/Cargo.toml | 5 ++++- wasmy-vm/src/modules.rs | 16 ++++++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) 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 {