wasmer_compiler/engine/
builder.rs1use super::Engine;
2#[cfg(feature = "compiler")]
3use crate::CompilerConfig;
4use wasmer_types::{Features, target::Target};
5
6pub struct EngineBuilder {
8 #[cfg(feature = "compiler")]
10 compiler_config: Option<Box<dyn CompilerConfig>>,
11 target: Option<Target>,
13 features: Option<Features>,
15}
16
17impl EngineBuilder {
18 #[cfg(feature = "compiler")]
20 pub fn new<T>(compiler_config: T) -> Self
21 where
22 T: Into<Box<dyn CompilerConfig>>,
23 {
24 Self {
25 compiler_config: Some(compiler_config.into()),
26 target: None,
27 features: None,
28 }
29 }
30
31 pub fn headless() -> Self {
33 Self {
34 #[cfg(feature = "compiler")]
35 compiler_config: None,
36 target: None,
37 features: None,
38 }
39 }
40
41 pub fn set_target(mut self, target: Option<Target>) -> Self {
43 self.target = target;
44 self
45 }
46
47 pub fn set_features(mut self, features: Option<Features>) -> Self {
49 self.features = features;
50 self
51 }
52
53 #[cfg(feature = "compiler")]
55 pub fn engine(self) -> Engine {
56 let target = self.target.unwrap_or_default();
57 if let Some(compiler_config) = self.compiler_config {
58 let features = self
59 .features
60 .unwrap_or_else(|| compiler_config.default_features_for_target(&target));
61 Engine::new(compiler_config, target, features)
62 } else {
63 Engine::headless()
64 }
65 }
66
67 #[cfg(not(feature = "compiler"))]
69 pub fn engine(self) -> Engine {
70 Engine::headless()
71 }
72
73 pub fn features(&self) -> Option<&Features> {
75 self.features.as_ref()
76 }
77
78 pub fn target(&self) -> Option<&Target> {
80 self.target.as_ref()
81 }
82}