diff --git a/src/commands/serve.rs b/src/commands/serve.rs index d56e3fea6a2b..0c7598d84cb6 100644 --- a/src/commands/serve.rs +++ b/src/commands/serve.rs @@ -73,6 +73,30 @@ pub struct ServeCommand { impl ServeCommand { /// Start a server to run the given wasi-http proxy component pub fn execute(self) -> Result<()> { + // We force cli errors before starting to listen for connections so tha we don't + // accidentally delay them to the first request. + if self.run.common.wasi.nn == Some(true) { + #[cfg(not(feature = "wasi-nn"))] + { + bail!("Cannot enable wasi-nn when the binary is not compiled with this feature."); + } + } + + if let Some(Profile::Guest { .. }) = &self.run.profile { + bail!("Cannot use the guest profiler with components"); + } + + if self.run.common.wasi.nn == Some(true) { + #[cfg(not(feature = "wasi-nn"))] + { + bail!("Cannot enable wasi-nn when the binary is not compiled with this feature."); + } + } + + if self.run.common.wasi.threads == Some(true) { + bail!("wasi-threads does not support components yet") + } + let runtime = tokio::runtime::Builder::new_multi_thread() .enable_time() .enable_io() @@ -110,10 +134,6 @@ impl ServeCommand { }; if self.run.common.wasi.nn == Some(true) { - #[cfg(not(feature = "wasi-nn"))] - { - bail!("Cannot enable wasi-nn when the binary is not compiled with this feature."); - } #[cfg(feature = "wasi-nn")] { let graphs = self @@ -131,10 +151,6 @@ impl ServeCommand { let mut store = Store::new(engine, host); - if let Some(Profile::Guest { .. }) = &self.run.profile { - bail!("Cannot use the guest profiler with components"); - } - if self.run.common.wasm.timeout.is_some() { store.set_epoch_deadline(1); } @@ -142,6 +158,12 @@ impl ServeCommand { store.data_mut().limits = self.run.store_limits(); store.limiter(|t| &mut t.limits); + // If fuel has been configured, we want to add the configured + // fuel amount to this store. + if let Some(fuel) = self.run.common.wasm.fuel { + store.add_fuel(fuel)?; + } + Ok(store) } @@ -153,20 +175,12 @@ impl ServeCommand { wasmtime_wasi_http::proxy::add_to_linker(linker)?; if self.run.common.wasi.nn == Some(true) { - #[cfg(not(feature = "wasi-nn"))] - { - bail!("Cannot enable wasi-nn when the binary is not compiled with this feature."); - } #[cfg(feature = "wasi-nn")] { wasmtime_wasi_nn::wit::ML::add_to_linker(linker, |host| host.nn.as_mut().unwrap())?; } } - if self.run.common.wasi.threads == Some(true) { - bail!("wasi-threads does not support components yet") - } - Ok(()) } @@ -187,9 +201,10 @@ impl ServeCommand { Some(Profile::Native(s)) => { config.profiler(s); } - Some(Profile::Guest { .. }) => { - bail!("guest profiling not yet available with components"); - } + + // We bail early in `execute` if the guest profiler is configured. + Some(Profile::Guest { .. }) => unreachable!(), + None => {} }