1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::JITEngine;
use wasmer_compiler::{CompilerConfig, Features, Target};
pub struct JIT {
#[allow(dead_code)]
compiler_config: Option<Box<dyn CompilerConfig>>,
target: Option<Target>,
features: Option<Features>,
}
impl JIT {
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) -> JITEngine {
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();
JITEngine::new(compiler, target, features)
} else {
JITEngine::headless()
}
}
#[cfg(not(feature = "compiler"))]
pub fn engine(self) -> JITEngine {
JITEngine::headless()
}
}