wasmer_engine_universal/
builder.rsuse crate::UniversalEngine;
use wasmer_compiler::{CompilerConfig, Features, Target};
pub struct Universal {
#[allow(dead_code)]
compiler_config: Option<Box<dyn CompilerConfig>>,
target: Option<Target>,
features: Option<Features>,
}
impl Universal {
pub fn new<T>(compiler_config: T) -> Self
where
T: Into<Box<dyn CompilerConfig>>,
{
Self {
compiler_config: Some(compiler_config.into()),
target: None,
features: None,
}
}
pub fn headless() -> Self {
Self {
compiler_config: None,
target: None,
features: None,
}
}
pub fn target(mut self, target: Target) -> Self {
self.target = Some(target);
self
}
pub fn features(mut self, features: Features) -> Self {
self.features = Some(features);
self
}
#[cfg(feature = "compiler")]
pub fn engine(self) -> UniversalEngine {
let target = self.target.unwrap_or_default();
if let Some(compiler_config) = self.compiler_config {
let features = self
.features
.unwrap_or_else(|| compiler_config.default_features_for_target(&target));
let compiler = compiler_config.compiler();
UniversalEngine::new(compiler, target, features)
} else {
UniversalEngine::headless()
}
}
#[cfg(not(feature = "compiler"))]
pub fn engine(self) -> UniversalEngine {
UniversalEngine::headless()
}
}