Skip to content

Commit 3f2882f

Browse files
committed
Skip load_instance_pre for components not referenced by the trigger
This allows the manifest to contain components which exist only to be used in composition and do not necessarily comply with the Spin world - albeit more important for future middleware-style projects than for current import-style dependencies. Signed-off-by: itowlson <[email protected]>
1 parent 22322aa commit 3f2882f

File tree

9 files changed

+775
-5
lines changed

9 files changed

+775
-5
lines changed

crates/factors-executor/src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl<T: RuntimeFactors, U: Send + 'static> FactorsExecutor<T, U> {
5353
app: App,
5454
runtime_config: T::RuntimeConfig,
5555
component_loader: &impl ComponentLoader<T, U>,
56+
trigger_type: Option<&str>,
5657
) -> anyhow::Result<FactorsExecutorApp<T, U>> {
5758
let configured_app = self
5859
.factors
@@ -63,7 +64,14 @@ impl<T: RuntimeFactors, U: Send + 'static> FactorsExecutor<T, U> {
6364
hooks.configure_app(&configured_app).await?;
6465
}
6566

66-
let components = configured_app.app().components();
67+
let components = match trigger_type {
68+
Some(trigger_type) => configured_app
69+
.app()
70+
.triggers_with_type(trigger_type)
71+
.filter_map(|t| t.component().ok())
72+
.collect::<Vec<_>>(),
73+
None => configured_app.app().components().collect(),
74+
};
6775
let mut component_instance_pres = HashMap::with_capacity(components.len());
6876

6977
for component in components {
@@ -334,7 +342,7 @@ mod tests {
334342
let executor = Arc::new(FactorsExecutor::new(engine_builder, env.factors)?);
335343

336344
let factors_app = executor
337-
.load_app(app, Default::default(), &DummyComponentLoader)
345+
.load_app(app, Default::default(), &DummyComponentLoader, None)
338346
.await?;
339347

340348
let mut instance_builder = factors_app.prepare("empty")?;

crates/trigger/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl<T: Trigger<B::Factors>, B: RuntimeFactorsBuilder> TriggerAppBuilder<T, B> {
341341
let configured_app = {
342342
let _sloth_guard = warn_if_wasm_build_slothful();
343343
executor
344-
.load_app(app, runtime_config.into(), loader)
344+
.load_app(app, runtime_config.into(), loader, Some(T::TYPE))
345345
.await?
346346
};
347347

examples/spin-timer/Cargo.lock

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

tests/integration.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,29 @@ route = "/..."
15331533
Ok(())
15341534
}
15351535

1536+
#[test]
1537+
fn test_does_not_load_triggerless_component() -> anyhow::Result<()> {
1538+
run_test(
1539+
"unsupported-import-unused",
1540+
SpinConfig {
1541+
binary_path: spin_binary(),
1542+
spin_up_args: Vec::new(),
1543+
app_type: SpinAppType::Http,
1544+
},
1545+
ServicesConfig::none(),
1546+
move |env| {
1547+
let spin = env.runtime_mut();
1548+
assert_spin_request(
1549+
spin,
1550+
Request::full(Method::Get, "/", &[], Some("")),
1551+
Response::new_with_body(200, "Hello World!\n"),
1552+
)?;
1553+
Ok(())
1554+
},
1555+
)?;
1556+
Ok(())
1557+
}
1558+
15361559
#[test]
15371560
fn test_outbound_post() -> anyhow::Result<()> {
15381561
run_test(

0 commit comments

Comments
 (0)