pub use wasmer_compiler::{
Artifact, BaseTunables, CompilerConfig, Engine, EngineBuilder, Tunables,
};
#[cfg(feature = "compiler")]
use wasmer_types::Features;
use wasmer_types::Target;
pub(crate) fn default_engine() -> Engine {
#[allow(unreachable_code)]
#[cfg(any(feature = "cranelift", feature = "llvm", feature = "singlepass"))]
fn get_config() -> impl wasmer_compiler::CompilerConfig + 'static {
cfg_if::cfg_if! {
if #[cfg(feature = "cranelift")] {
wasmer_compiler_cranelift::Cranelift::default()
} else if #[cfg(feature = "llvm")] {
wasmer_compiler_llvm::LLVM::default()
} else if #[cfg(feature = "singlepass")] {
wasmer_compiler_singlepass::Singlepass::default()
} else {
compile_error!("No default compiler chosen")
}
}
}
#[allow(unreachable_code, unused_mut)]
fn get_engine() -> Engine {
cfg_if::cfg_if! {
if #[cfg(feature = "compiler")] {
cfg_if::cfg_if! {
if #[cfg(any(feature = "cranelift", feature = "llvm", feature = "singlepass"))]
{
let config = get_config();
EngineBuilder::new(Box::new(config) as Box<dyn wasmer_compiler::CompilerConfig>)
.engine()
} else {
EngineBuilder::headless()
.engine()
}
}
} else {
EngineBuilder::headless().engine()
}
}
}
let mut engine = get_engine();
let tunables = BaseTunables::for_target(engine.target());
engine.set_tunables(tunables);
engine
}
pub trait NativeEngineExt {
#[cfg(feature = "compiler")]
fn new(compiler_config: Box<dyn CompilerConfig>, target: Target, features: Features) -> Self;
fn headless() -> Self;
fn target(&self) -> &Target;
fn set_tunables(&mut self, tunables: impl Tunables + Send + Sync + 'static);
fn tunables(&self) -> &dyn Tunables;
}
impl NativeEngineExt for crate::engine::Engine {
#[cfg(feature = "compiler")]
fn new(compiler_config: Box<dyn CompilerConfig>, target: Target, features: Features) -> Self {
Self(Engine::new(compiler_config, target, features))
}
fn headless() -> Self {
Self(Engine::headless())
}
fn target(&self) -> &Target {
self.0.target()
}
fn set_tunables(&mut self, tunables: impl Tunables + Send + Sync + 'static) {
self.0.set_tunables(tunables)
}
fn tunables(&self) -> &dyn Tunables {
self.0.tunables()
}
}