Skip to content

Commit

Permalink
Merge pull request #2839 from fermyon/configurable-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
rylev authored Sep 17, 2024
2 parents 3ef8673 + 98b63ee commit 485b040
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
21 changes: 15 additions & 6 deletions crates/trigger/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ use spin_common::sloth;
use spin_common::ui::quoted_path;
use spin_common::url::parse_file_url;
use spin_factors::RuntimeFactors;
use spin_factors_executor::FactorsExecutor;
use spin_factors_executor::{ComponentLoader, FactorsExecutor};

use crate::loader::ComponentLoader;
use crate::{Trigger, TriggerApp};
use crate::{loader::ComponentLoader as ComponentLoaderImpl, Trigger, TriggerApp};
pub use initial_kv_setter::InitialKvSetterHook;
pub use launch_metadata::LaunchMetadata;
pub use sqlite_statements::SqlStatementExecutorHook;
Expand Down Expand Up @@ -220,7 +219,15 @@ impl<T: Trigger<B::Factors>, B: RuntimeFactorsBuilder> FactorsTriggerCommand<T,
follow_components,
log_dir,
};
let run_fut = builder.run(app, common_options, self.builder_args).await?;

let run_fut = builder
.run(
app,
common_options,
self.builder_args,
&ComponentLoaderImpl::new(),
)
.await?;

let (abortable, abort_handle) = futures::future::abortable(run_fut);
ctrlc::set_handler(move || abort_handle.abort())?;
Expand Down Expand Up @@ -302,6 +309,7 @@ impl<T: Trigger<B::Factors>, B: RuntimeFactorsBuilder> TriggerAppBuilder<T, B> {
app: App,
common_options: FactorsConfig,
options: B::CliArgs,
loader: &impl ComponentLoader,
) -> anyhow::Result<TriggerApp<T, B::Factors>> {
let mut core_engine_builder = {
self.trigger.update_core_config(&mut self.engine_config)?;
Expand All @@ -319,7 +327,7 @@ impl<T: Trigger<B::Factors>, B: RuntimeFactorsBuilder> TriggerAppBuilder<T, B> {
let configured_app = {
let _sloth_guard = warn_if_wasm_build_slothful();
executor
.load_app(app, runtime_config.into(), &ComponentLoader::default())
.load_app(app, runtime_config.into(), loader)
.await?
};

Expand All @@ -332,8 +340,9 @@ impl<T: Trigger<B::Factors>, B: RuntimeFactorsBuilder> TriggerAppBuilder<T, B> {
app: App,
common_options: FactorsConfig,
options: B::CliArgs,
loader: &impl ComponentLoader,
) -> anyhow::Result<impl Future<Output = anyhow::Result<()>>> {
let configured_app = self.build(app, common_options, options).await?;
let configured_app = self.build(app, common_options, options, loader).await?;
Ok(self.trigger.run(configured_app))
}
}
Expand Down
6 changes: 6 additions & 0 deletions crates/trigger/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ use spin_factors::AppComponent;

#[derive(Default)]
pub struct ComponentLoader {
_private: (),
#[cfg(feature = "unsafe-aot-compilation")]
aot_compilation_enabled: bool,
}

impl ComponentLoader {
/// Create a new `ComponentLoader`
pub fn new() -> Self {
Self::default()
}

/// Updates the TriggerLoader to load AOT precompiled components
///
/// **Warning: This feature may bypass important security guarantees of the
Expand Down
3 changes: 2 additions & 1 deletion tests/testing-framework/src/runtimes/in_process_spin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::Arc;

use anyhow::Context as _;
use spin_runtime_factors::{FactorsBuilder, TriggerAppArgs, TriggerFactors};
use spin_trigger::cli::TriggerAppBuilder;
use spin_trigger::{cli::TriggerAppBuilder, loader::ComponentLoader};
use spin_trigger_http::{HttpServer, HttpTrigger};
use test_environment::{
http::{Request, Response},
Expand Down Expand Up @@ -111,6 +111,7 @@ async fn initialize_trigger(
app,
spin_trigger::cli::FactorsConfig::default(),
TriggerAppArgs::default(),
&ComponentLoader::new(),
)
.await?;
let server = builder.trigger.into_server(trigger_app)?;
Expand Down

0 comments on commit 485b040

Please sign in to comment.