mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-27 23:51:33 +00:00
Make cranelift optional for middleware
This commit is contained in:
@ -10,12 +10,12 @@ publish = false
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
wasmer-runtime-core = { path = "../runtime-core", version = "0.12.0" }
|
wasmer-runtime-core = { path = "../runtime-core", version = "0.12.0" }
|
||||||
wasmer-middleware-common = { path = "../middleware-common", version = "0.12.0" }
|
wasmer-middleware-common = { path = "../middleware-common", version = "0.12.0" }
|
||||||
wasmer-clif-backend = { path = "../clif-backend", version = "0.12.0" }
|
wasmer-clif-backend = { path = "../clif-backend", version = "0.12.0", optional = true }
|
||||||
wasmer-llvm-backend = { path = "../llvm-backend", version = "0.12.0", features = ["test"], optional = true }
|
wasmer-llvm-backend = { path = "../llvm-backend", version = "0.12.0", features = ["test"], optional = true }
|
||||||
wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.12.0", optional = true }
|
wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.12.0", optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
clif = []
|
clif = ["wasmer-clif-backend"]
|
||||||
llvm = ["wasmer-llvm-backend"]
|
llvm = ["wasmer-llvm-backend"]
|
||||||
singlepass = ["wasmer-singlepass-backend"]
|
singlepass = ["wasmer-singlepass-backend"]
|
||||||
|
|
||||||
|
@ -3,27 +3,23 @@ mod tests {
|
|||||||
use wabt::wat2wasm;
|
use wabt::wat2wasm;
|
||||||
|
|
||||||
use wasmer_middleware_common::metering::*;
|
use wasmer_middleware_common::metering::*;
|
||||||
use wasmer_runtime_core::backend::RunnableModule;
|
|
||||||
use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler};
|
use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler};
|
||||||
|
use wasmer_runtime_core::codegen::ModuleCodeGenerator;
|
||||||
use wasmer_runtime_core::fault::{pop_code_version, push_code_version};
|
use wasmer_runtime_core::fault::{pop_code_version, push_code_version};
|
||||||
use wasmer_runtime_core::state::CodeVersion;
|
use wasmer_runtime_core::state::CodeVersion;
|
||||||
use wasmer_runtime_core::{backend::Compiler, compile_with, imports, Func};
|
use wasmer_runtime_core::{backend::Compiler, compile_with, imports, Func};
|
||||||
|
|
||||||
#[cfg(feature = "llvm")]
|
#[cfg(feature = "llvm")]
|
||||||
fn get_compiler(limit: u64) -> impl Compiler {
|
use wasmer_llvm_backend::ModuleCodeGenerator as MCG;
|
||||||
use wasmer_llvm_backend::ModuleCodeGenerator as LLVMMCG;
|
|
||||||
let c: StreamingCompiler<LLVMMCG, _, _, _, _> = StreamingCompiler::new(move || {
|
|
||||||
let mut chain = MiddlewareChain::new();
|
|
||||||
chain.push(Metering::new(limit));
|
|
||||||
chain
|
|
||||||
});
|
|
||||||
c
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "singlepass")]
|
#[cfg(feature = "singlepass")]
|
||||||
|
use wasmer_singlepass_backend::ModuleCodeGenerator as MCG;
|
||||||
|
|
||||||
|
#[cfg(feature = "clif")]
|
||||||
|
compile_error!("cranelift does not implement metering yet");
|
||||||
|
|
||||||
fn get_compiler(limit: u64) -> impl Compiler {
|
fn get_compiler(limit: u64) -> impl Compiler {
|
||||||
use wasmer_singlepass_backend::ModuleCodeGenerator as SinglePassMCG;
|
let c: StreamingCompiler<MCG, _, _, _, _> = StreamingCompiler::new(move || {
|
||||||
let c: StreamingCompiler<SinglePassMCG, _, _, _, _> = StreamingCompiler::new(move || {
|
|
||||||
let mut chain = MiddlewareChain::new();
|
let mut chain = MiddlewareChain::new();
|
||||||
chain.push(Metering::new(limit));
|
chain.push(Metering::new(limit));
|
||||||
chain
|
chain
|
||||||
@ -34,13 +30,6 @@ mod tests {
|
|||||||
#[cfg(not(any(feature = "llvm", feature = "clif", feature = "singlepass")))]
|
#[cfg(not(any(feature = "llvm", feature = "clif", feature = "singlepass")))]
|
||||||
compile_error!("compiler not specified, activate a compiler via features");
|
compile_error!("compiler not specified, activate a compiler via features");
|
||||||
|
|
||||||
#[cfg(feature = "clif")]
|
|
||||||
fn get_compiler(_limit: u64) -> impl Compiler {
|
|
||||||
compile_error!("cranelift does not implement metering");
|
|
||||||
use wasmer_clif_backend::CraneliftCompiler;
|
|
||||||
CraneliftCompiler::new()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assemblyscript
|
// Assemblyscript
|
||||||
// export function add_to(x: i32, y: i32): i32 {
|
// export function add_to(x: i32, y: i32): i32 {
|
||||||
// for(var i = 0; i < x; i++){
|
// for(var i = 0; i < x; i++){
|
||||||
@ -106,7 +95,7 @@ mod tests {
|
|||||||
|
|
||||||
let limit = 100u64;
|
let limit = 100u64;
|
||||||
|
|
||||||
let (compiler, backend_id) = get_compiler(limit);
|
let compiler = get_compiler(limit);
|
||||||
let module = compile_with(&wasm_binary, &compiler).unwrap();
|
let module = compile_with(&wasm_binary, &compiler).unwrap();
|
||||||
|
|
||||||
let import_object = imports! {};
|
let import_object = imports! {};
|
||||||
@ -121,8 +110,8 @@ mod tests {
|
|||||||
baseline: true,
|
baseline: true,
|
||||||
msm: msm,
|
msm: msm,
|
||||||
base: instance.module.runnable_module.get_code().unwrap().as_ptr() as usize,
|
base: instance.module.runnable_module.get_code().unwrap().as_ptr() as usize,
|
||||||
|
backend: MCG::backend_id(),
|
||||||
runnable_module: instance.module.runnable_module.clone(),
|
runnable_module: instance.module.runnable_module.clone(),
|
||||||
backend: backend_id,
|
|
||||||
});
|
});
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
@ -148,7 +137,7 @@ mod tests {
|
|||||||
|
|
||||||
let limit = 100u64;
|
let limit = 100u64;
|
||||||
|
|
||||||
let (compiler, backend_id) = get_compiler(limit);
|
let compiler = get_compiler(limit);
|
||||||
let module = compile_with(&wasm_binary, &compiler).unwrap();
|
let module = compile_with(&wasm_binary, &compiler).unwrap();
|
||||||
|
|
||||||
let import_object = imports! {};
|
let import_object = imports! {};
|
||||||
@ -168,7 +157,7 @@ mod tests {
|
|||||||
baseline: true,
|
baseline: true,
|
||||||
msm: msm,
|
msm: msm,
|
||||||
base: instance.module.runnable_module.get_code().unwrap().as_ptr() as usize,
|
base: instance.module.runnable_module.get_code().unwrap().as_ptr() as usize,
|
||||||
backend: backend_id,
|
backend: MCG::backend_id(),
|
||||||
runnable_module: instance.module.runnable_module.clone(),
|
runnable_module: instance.module.runnable_module.clone(),
|
||||||
});
|
});
|
||||||
true
|
true
|
||||||
|
Reference in New Issue
Block a user