Skip to content

Commit 286d5a7

Browse files
committed
Expose engine and component from executor app
Signed-off-by: Ryan Levick <[email protected]>
1 parent 0772633 commit 286d5a7

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/factors-executor/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,16 @@ impl<'a, T: RuntimeFactors, U> FactorsInstanceBuilder<'a, T, U> {
211211
pub fn factor_builder<F: Factor>(&mut self) -> Option<&mut F::InstanceBuilder> {
212212
self.factor_builders().for_factor::<F>()
213213
}
214+
215+
/// Returns the underlying wasmtime engine for the instance.
216+
pub fn engine(&self) -> &spin_core::wasmtime::Engine {
217+
self.instance_pre.engine()
218+
}
219+
220+
/// Returns the compiled component for the instance.
221+
pub fn component(&self) -> &Component {
222+
self.instance_pre.component()
223+
}
214224
}
215225

216226
impl<'a, T: RuntimeFactors, U: Send> FactorsInstanceBuilder<'a, T, U> {

crates/http/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ anyhow = { workspace = true }
99
http = { workspace = true }
1010
http-body-util = { workspace = true }
1111
hyper = { workspace = true }
12-
indexmap = "1"
12+
indexmap = "2"
1313
percent-encoding = "2"
1414
routefinder = "0.5.4"
1515
serde = { workspace = true }

crates/http/src/trigger.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ pub const WASI_HTTP_EXPORT_2023_11_10: &str = "wasi:http/[email protected]
3131
pub const WASI_HTTP_EXPORT_0_2_0: &str = "wasi:http/[email protected]";
3232
/// The `incoming-handler` export for `wasi:http` version 0.2.1
3333
pub const WASI_HTTP_EXPORT_0_2_1: &str = "wasi:http/[email protected]";
34+
/// The `inbound-http` export for `fermyon:spin`
35+
pub const SPIN_HTTP_EXPORT: &str = "fermyon:spin/inbound-http";
3436

3537
impl HandlerType {
36-
/// Determine the handler type from the exports of a component
38+
/// Determine the handler type from the exports of a component.
3739
pub fn from_component(
38-
engine: impl AsRef<wasmtime::Engine>,
40+
engine: &wasmtime::Engine,
3941
component: &Component,
4042
) -> anyhow::Result<HandlerType> {
4143
let mut handler_ty = None;
@@ -52,12 +54,12 @@ impl HandlerType {
5254
}
5355
};
5456
let ty = component.component_type();
55-
for (name, _) in ty.exports(engine.as_ref()) {
57+
for (name, _) in ty.exports(engine) {
5658
match name {
5759
WASI_HTTP_EXPORT_2023_10_18 => set(HandlerType::Wasi2023_10_18)?,
5860
WASI_HTTP_EXPORT_2023_11_10 => set(HandlerType::Wasi2023_11_10)?,
5961
WASI_HTTP_EXPORT_0_2_0 | WASI_HTTP_EXPORT_0_2_1 => set(HandlerType::Wasi0_2)?,
60-
"fermyon:spin/inbound-http" => set(HandlerType::Spin)?,
62+
SPIN_HTTP_EXPORT => set(HandlerType::Spin)?,
6163
_ => {}
6264
}
6365
}
@@ -69,7 +71,7 @@ impl HandlerType {
6971
`{WASI_HTTP_EXPORT_2023_11_10}`, \
7072
`{WASI_HTTP_EXPORT_0_2_0}`, \
7173
`{WASI_HTTP_EXPORT_0_2_1}`, \
72-
or `fermyon:spin/inbound-http` but it exported none of those"
74+
or `{SPIN_HTTP_EXPORT}` but it exported none of those"
7375
)
7476
})
7577
}

crates/trigger-http/src/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<F: RuntimeFactors> HttpServer<F> {
104104
let handler_type = match &trigger_config.executor {
105105
None | Some(HttpExecutorType::Http) => {
106106
let component = trigger_app.get_component(component_id)?;
107-
HandlerType::from_component(trigger_app.engine(), component)?
107+
HandlerType::from_component(trigger_app.engine().as_ref(), component)?
108108
}
109109
Some(HttpExecutorType::Wagi(wagi_config)) => {
110110
anyhow::ensure!(

0 commit comments

Comments
 (0)