Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass loader into TriggerAppBuilder #2839

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/componentize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ mod tests {
let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
let mut cmd = process::Command::new("cargo");
cmd.arg("build")
.current_dir(&format!("tests/{name}"))
.current_dir(format!("tests/{name}"))
.arg("--release")
.arg("--target=wasm32-wasi")
.env("CARGO_TARGET_DIR", out_dir);
Expand Down
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
Loading