@@ -18,8 +18,6 @@ pub struct CommandTrigger {
18
18
#[ serde( deny_unknown_fields) ]
19
19
pub struct Component {
20
20
pub id : String ,
21
- #[ serde( default ) ]
22
- pub executor : CommandExecutorType ,
23
21
}
24
22
25
23
#[ derive( Clone , Debug , Default , Deserialize , Serialize ) ]
@@ -28,20 +26,10 @@ struct TriggerMetadata {
28
26
pub r#type : String ,
29
27
}
30
28
31
- #[ derive( Clone , Debug , Default , Deserialize , Serialize ) ]
32
- #[ serde( deny_unknown_fields, rename_all = "lowercase" , tag = "type" ) ]
33
- pub enum CommandExecutorType {
34
- #[ default]
35
- Preview2 ,
36
- Preview1 ,
37
- }
38
-
39
29
#[ derive( Clone , Debug , Default , Deserialize , Serialize ) ]
40
30
#[ serde( deny_unknown_fields) ]
41
31
pub struct CommandTriggerConfig {
42
32
pub component : String ,
43
- #[ serde( default ) ]
44
- pub executor : CommandExecutorType ,
45
33
}
46
34
47
35
pub enum CommandInstancePre {
@@ -67,7 +55,6 @@ impl TriggerExecutor for CommandTrigger {
67
55
. trigger_configs ( )
68
56
. map ( |( _, config) | Component {
69
57
id : config. component . clone ( ) ,
70
- executor : config. executor . clone ( ) ,
71
58
} )
72
59
. collect ( ) ;
73
60
Ok ( Self { engine, components } )
@@ -85,18 +72,18 @@ impl TriggerInstancePre<RuntimeData, CommandTriggerConfig> for CommandInstancePr
85
72
async fn instantiate_pre (
86
73
engine : & Engine < RuntimeData > ,
87
74
component : & AppComponent ,
88
- config : & CommandTriggerConfig ,
75
+ _config : & CommandTriggerConfig ,
89
76
) -> Result < CommandInstancePre > {
90
- if let CommandExecutorType :: Preview1 = & config. executor {
77
+ // Attempt to load as a component and fallback to loading a module
78
+ if let Ok ( comp) = component. load_component ( engine) . await {
79
+ Ok ( CommandInstancePre :: Component (
80
+ engine. instantiate_pre ( & comp) ?,
81
+ ) )
82
+ } else {
91
83
let module = component. load_module ( engine) . await ?;
92
84
Ok ( CommandInstancePre :: Module (
93
85
engine. module_instantiate_pre ( & module) ?,
94
86
) )
95
- } else {
96
- let comp = component. load_component ( engine) . await ?;
97
- Ok ( CommandInstancePre :: Component (
98
- engine. instantiate_pre ( & comp) ?,
99
- ) )
100
87
}
101
88
}
102
89
@@ -117,36 +104,35 @@ impl TriggerInstancePre<RuntimeData, CommandTriggerConfig> for CommandInstancePr
117
104
impl CommandTrigger {
118
105
pub async fn handle ( & self ) -> Result < ( ) > {
119
106
let component = & self . components [ 0 ] ;
120
- match component. executor {
121
- CommandExecutorType :: Preview2 => {
122
- let ( instance, mut store) = self . engine . prepare_instance ( & component. id ) . await ?;
123
- let CommandInstance :: Component ( instance) = instance else {
124
- unreachable ! ( )
125
- } ;
107
+ let ( instance, mut store) = self . engine . prepare_instance ( & component. id ) . await ?;
108
+ match instance {
109
+ CommandInstance :: Component ( instance) => {
126
110
let handler =
127
111
wasmtime_wasi:: preview2:: command:: Command :: new ( & mut store, & instance) ?;
128
112
let _ = handler. wasi_cli_run ( ) . call_run ( store) . await ?;
129
113
}
130
- CommandExecutorType :: Preview1 => {
114
+ CommandInstance :: Module ( _) => {
115
+ // Toss the commandInstance we have and create a new one as the
116
+ // associated store will be a preview2 store
131
117
let store_builder = self
132
118
. engine
133
119
. store_builder ( & component. id , spin_core:: WasiVersion :: Preview1 ) ?;
134
120
let ( instance, mut store) = self
135
121
. engine
136
122
. prepare_instance_with_store ( & component. id , store_builder)
137
123
. await ?;
138
-
139
- let CommandInstance :: Module ( instance) = instance else {
140
- unreachable ! ( )
141
- } ;
142
-
143
- let start = instance
144
- . get_func ( & mut store, "_start" )
145
- . context ( "Expected component to export _start function" ) ?;
146
-
147
- let _ = start. call_async ( & mut store, & [ ] , & mut [ ] ) . await ?;
124
+ if let CommandInstance :: Module ( instance) = instance {
125
+ let start = instance
126
+ . get_func ( & mut store, "_start" )
127
+ . context ( "Expected component to export _start function" ) ?;
128
+
129
+ let _ = start. call_async ( & mut store, & [ ] , & mut [ ] ) . await ?;
130
+ } else {
131
+ unreachable ! ( ) ;
132
+ }
148
133
}
149
- } ;
134
+ }
135
+
150
136
Ok ( ( ) )
151
137
}
152
138
}
0 commit comments