Skip to content

Commit 8b7f497

Browse files
committed
Move Spin CLI runtime factors to their own crate
Signed-off-by: Ryan Levick <[email protected]>
1 parent bfd3680 commit 8b7f497

File tree

20 files changed

+5402
-539
lines changed

20 files changed

+5402
-539
lines changed

Cargo.lock

Lines changed: 26 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ spin-manifest = { path = "crates/manifest" }
5757
spin-oci = { path = "crates/oci" }
5858
spin-plugins = { path = "crates/plugins" }
5959
spin-runtime-config = { path = "crates/runtime-config" }
60+
spin-runtime-factors = { path = "crates/runtime-factors" }
6061
spin-telemetry = { path = "crates/telemetry", features = [
6162
"tracing-log-compat",
6263
] }
@@ -112,9 +113,9 @@ vergen = { version = "^8.2.1", default-features = false, features = [
112113
default = ["llm"]
113114
all-tests = ["extern-dependencies-tests"]
114115
extern-dependencies-tests = []
115-
llm = ["spin-trigger-http/llm"]
116-
llm-metal = ["llm", "spin-trigger-http/llm-metal"]
117-
llm-cublas = ["llm", "spin-trigger-http/llm-cublas"]
116+
llm = ["spin-runtime-factors/llm"]
117+
llm-metal = ["llm", "spin-runtime-factors/llm-metal"]
118+
llm-cublas = ["llm", "spin-runtime-factors/llm-cublas"]
118119

119120
[workspace]
120121
members = [

crates/runtime-config/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ spin-factor-sqlite = { path = "../factor-sqlite" }
2525
spin-factor-variables = { path = "../factor-variables" }
2626
spin-factor-wasi = { path = "../factor-wasi" }
2727
spin-factors = { path = "../factors" }
28+
spin-runtime-factors = { path = "../runtime-factors" }
2829
spin-sqlite = { path = "../sqlite" }
2930
spin-trigger = { path = "../trigger" }
3031
toml = "0.8"

crates/runtime-config/src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use spin_factors::{
1919
runtime_config::toml::TomlKeyTracker, FactorRuntimeConfigSource, RuntimeConfigSourceFinalizer,
2020
};
2121
use spin_key_value_spin::{SpinKeyValueRuntimeConfig, SpinKeyValueStore};
22+
use spin_runtime_factors::TriggerFactorsRuntimeConfig;
2223
use spin_sqlite as sqlite;
2324
use spin_trigger::cli::UserProvidedPath;
2425

@@ -159,10 +160,8 @@ where
159160
}
160161
}
161162

162-
impl From<ResolvedRuntimeConfig<spin_trigger::TriggerFactorsRuntimeConfig>>
163-
for spin_trigger::TriggerFactorsRuntimeConfig
164-
{
165-
fn from(value: ResolvedRuntimeConfig<spin_trigger::TriggerFactorsRuntimeConfig>) -> Self {
163+
impl From<ResolvedRuntimeConfig<TriggerFactorsRuntimeConfig>> for TriggerFactorsRuntimeConfig {
164+
fn from(value: ResolvedRuntimeConfig<TriggerFactorsRuntimeConfig>) -> Self {
166165
value.runtime_config
167166
}
168167
}
@@ -432,7 +431,7 @@ fn sqlite_config_resolver(
432431
))
433432
}
434433

435-
impl TryFrom<TomlRuntimeConfigSource<'_, '_>> for spin_trigger::TriggerFactorsRuntimeConfig {
434+
impl TryFrom<TomlRuntimeConfigSource<'_, '_>> for TriggerFactorsRuntimeConfig {
436435
type Error = anyhow::Error;
437436

438437
fn try_from(value: TomlRuntimeConfigSource<'_, '_>) -> Result<Self, Self::Error> {

crates/runtime-factors/Cargo.toml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[package]
2+
name = "spin-runtime-factors"
3+
version.workspace = true
4+
authors.workspace = true
5+
edition.workspace = true
6+
license.workspace = true
7+
homepage.workspace = true
8+
repository.workspace = true
9+
rust-version.workspace = true
10+
11+
[features]
12+
llm = ["spin-factor-llm/llm"]
13+
llm-metal = ["spin-factor-llm/llm-metal"]
14+
llm-cublas = ["spin-factor-llm/llm-cublas"]
15+
16+
[dependencies]
17+
anyhow = "1"
18+
clap = { version = "3.1.18", features = ["derive", "env"] }
19+
spin-common = { path = "../common" }
20+
spin-factor-key-value = { path = "../factor-key-value" }
21+
spin-factor-llm = { path = "../factor-llm" }
22+
spin-factor-outbound-http = { path = "../factor-outbound-http" }
23+
spin-factor-outbound-mqtt = { path = "../factor-outbound-mqtt" }
24+
spin-factor-outbound-mysql = { path = "../factor-outbound-mysql" }
25+
spin-factor-outbound-networking = { path = "../factor-outbound-networking" }
26+
spin-factor-outbound-pg = { path = "../factor-outbound-pg" }
27+
spin-factor-outbound-redis = { path = "../factor-outbound-redis" }
28+
spin-factor-sqlite = { path = "../factor-sqlite" }
29+
spin-factor-variables = { path = "../factor-variables" }
30+
spin-factor-wasi = { path = "../factor-wasi" }
31+
spin-factors = { path = "../factors" }
32+
spin-telemetry = { path = "../telemetry" }
33+
terminal = { path = "../terminal" }
34+
tracing = { workspace = true }
35+
36+
[lints]
37+
workspace = true
File renamed without changes.

crates/trigger-http/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ edition = { workspace = true }
77
[lib]
88
doctest = false
99

10-
[features]
11-
llm = ["spin-trigger/llm"]
12-
llm-metal = ["spin-trigger/llm-metal"]
13-
llm-cublas = ["spin-trigger/llm-cublas"]
14-
1510
[dependencies]
1611
anyhow = "1.0"
1712
async-trait = "0.1"

crates/trigger/Cargo.toml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ homepage.workspace = true
88
repository.workspace = true
99
rust-version.workspace = true
1010

11-
[features]
12-
llm = ["spin-factor-llm/llm"]
13-
llm-metal = ["spin-factor-llm/llm-metal"]
14-
llm-cublas = ["spin-factor-llm/llm-cublas"]
15-
1611
[dependencies]
1712
anyhow = "1"
1813
clap = { version = "3.1.18", features = ["derive", "env"] }
@@ -27,21 +22,12 @@ spin-componentize = { path = "../componentize" }
2722
spin-compose = { path = "../compose" }
2823
spin-core = { path = "../core" }
2924
spin-factor-key-value = { path = "../factor-key-value" }
30-
spin-factor-llm = { path = "../factor-llm" }
31-
spin-factor-outbound-http = { path = "../factor-outbound-http" }
32-
spin-factor-outbound-mqtt = { path = "../factor-outbound-mqtt" }
33-
spin-factor-outbound-mysql = { path = "../factor-outbound-mysql" }
34-
spin-factor-outbound-networking = { path = "../factor-outbound-networking" }
35-
spin-factor-outbound-pg = { path = "../factor-outbound-pg" }
36-
spin-factor-outbound-redis = { path = "../factor-outbound-redis" }
3725
spin-factor-sqlite = { path = "../factor-sqlite" }
38-
spin-factor-variables = { path = "../factor-variables" }
3926
spin-factor-wasi = { path = "../factor-wasi" }
4027
spin-factors = { path = "../factors" }
4128
spin-factors-executor = { path = "../factors-executor" }
4229
spin-runtime-config = { path = "../runtime-config" }
4330
spin-telemetry = { path = "../telemetry" }
44-
terminal = { path = "../terminal" }
4531
tokio = { version = "1.23", features = ["fs", "rt"] }
4632
toml = "0.8"
4733
tracing = { workspace = true }

crates/trigger/src/cli.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
mod launch_metadata;
22
mod sqlite_statements;
3+
mod stdio;
34
mod summary;
45

56
use std::future::Future;
67
use std::path::PathBuf;
78

8-
pub use crate::stdio::StdioLoggingExecutorHooks;
99
use anyhow::{Context, Result};
1010
use clap::{Args, IntoApp, Parser};
1111
use spin_app::App;
@@ -15,12 +15,13 @@ use spin_common::url::parse_file_url;
1515
use spin_core::async_trait;
1616
use spin_factors::RuntimeFactors;
1717
use spin_factors_executor::{ComponentLoader, FactorsExecutor};
18-
pub use sqlite_statements::SqlStatementExecutorHook;
19-
pub use summary::KeyValueDefaultStoreSummaryHook;
2018

21-
use crate::stdio::FollowComponents;
2219
use crate::{Trigger, TriggerApp};
2320
pub use launch_metadata::LaunchMetadata;
21+
pub use sqlite_statements::SqlStatementExecutorHook;
22+
use stdio::FollowComponents;
23+
pub use stdio::StdioLoggingExecutorHooks;
24+
pub use summary::KeyValueDefaultStoreSummaryHook;
2425

2526
pub const APP_LOG_DIR: &str = "APP_LOG_DIR";
2627
pub const DISABLE_WASMTIME_CACHE: &str = "DISABLE_WASMTIME_CACHE";

crates/trigger/src/stdio.rs renamed to crates/trigger/src/cli/stdio.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use std::{
77
use anyhow::{Context, Result};
88
use spin_common::ui::quoted_path;
99
use spin_core::async_trait;
10+
use spin_factor_wasi::WasiFactor;
11+
use spin_factors::{HasInstanceBuilder, RuntimeFactors};
1012
use spin_factors_executor::ExecutorHooks;
1113
use tokio::io::AsyncWrite;
1214

13-
use crate::factors::TriggerFactors;
14-
1515
/// Which components should have their logs followed on stdout/stderr.
1616
#[derive(Clone, Debug, Default)]
1717
pub enum FollowComponents {
@@ -89,10 +89,10 @@ impl StdioLoggingExecutorHooks {
8989
}
9090

9191
#[async_trait]
92-
impl<U> ExecutorHooks<TriggerFactors, U> for StdioLoggingExecutorHooks {
92+
impl<F: RuntimeFactors, U> ExecutorHooks<F, U> for StdioLoggingExecutorHooks {
9393
async fn configure_app(
9494
&mut self,
95-
configured_app: &spin_factors::ConfiguredApp<TriggerFactors>,
95+
configured_app: &spin_factors::ConfiguredApp<F>,
9696
) -> anyhow::Result<()> {
9797
self.validate_follows(configured_app.app())?;
9898
if let Some(dir) = &self.log_dir {
@@ -107,10 +107,12 @@ impl<U> ExecutorHooks<TriggerFactors, U> for StdioLoggingExecutorHooks {
107107

108108
fn prepare_instance(
109109
&self,
110-
builder: &mut spin_factors_executor::FactorsInstanceBuilder<TriggerFactors, U>,
110+
builder: &mut spin_factors_executor::FactorsInstanceBuilder<F, U>,
111111
) -> anyhow::Result<()> {
112112
let component_id = builder.app_component().id().to_string();
113-
let wasi_builder = builder.factor_builders().wasi();
113+
let Some(wasi_builder) = builder.factor_builders().for_factor::<WasiFactor>() else {
114+
return Ok(());
115+
};
114116
wasi_builder.stdout_pipe(self.component_stdio_writer(
115117
&component_id,
116118
"stdout",

0 commit comments

Comments
 (0)