From 4a1e40d14971a28e80d99ee2a6f94fd02de6b673 Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:36:10 +0100 Subject: [PATCH 1/9] feat: initial commit of codegen rewrite --- cargo-shuttle/src/lib.rs | 46 +------------- codegen/src/shuttle_main/mod.rs | 109 ++++++++++++++++++++------------ proto/src/lib.rs | 10 ++- service/src/lib.rs | 3 +- service/src/loader.rs | 4 +- 5 files changed, 79 insertions(+), 93 deletions(-) diff --git a/cargo-shuttle/src/lib.rs b/cargo-shuttle/src/lib.rs index 5fcc02eab..c11021a50 100644 --- a/cargo-shuttle/src/lib.rs +++ b/cargo-shuttle/src/lib.rs @@ -404,7 +404,7 @@ impl Shuttle { let service_name = self.ctx.project_name().to_string(); - let (is_wasm, so_path) = match runtime { + let (is_wasm, bin_path) = match runtime { Runtime::Next(path) => (true, path), Runtime::Legacy(path) => (false, path), }; @@ -415,52 +415,12 @@ impl Shuttle { run_args.port + 1, )); - let get_runtime_executable = || { - let runtime_path = home::cargo_home() - .expect("failed to find cargo home dir") - .join("bin/shuttle-runtime"); - - if cfg!(debug_assertions) { - // Canonicalized path to shuttle-runtime for dev to work on windows - let path = std::fs::canonicalize(format!("{MANIFEST_DIR}/../runtime")) - .expect("path to shuttle-runtime does not exist or is invalid"); - - std::process::Command::new("cargo") - .arg("install") - .arg("shuttle-runtime") - .arg("--path") - .arg(path) - .output() - .expect("failed to install the shuttle runtime"); - } else { - // If the version of cargo-shuttle is different from shuttle-runtime, - // or it isn't installed, try to install shuttle-runtime from the production - // branch. - if let Err(err) = check_version(&runtime_path) { - trace!("{}", err); - - trace!("installing shuttle-runtime"); - std::process::Command::new("cargo") - .arg("install") - .arg("shuttle-runtime") - .arg("--git") - .arg("https://github.com/shuttle-hq/shuttle") - .arg("--branch") - .arg("production") - .output() - .expect("failed to install the shuttle runtime"); - }; - }; - - runtime_path - }; - let (mut runtime, mut runtime_client) = runtime::start( is_wasm, runtime::StorageManagerType::WorkingDir(working_directory.to_path_buf()), &format!("http://localhost:{}", run_args.port + 1), run_args.port + 2, - get_runtime_executable, + bin_path.clone(), ) .await .map_err(|err| { @@ -470,7 +430,7 @@ impl Shuttle { })?; let load_request = tonic::Request::new(LoadRequest { - path: so_path + path: bin_path .into_os_string() .into_string() .expect("to convert path to string"), diff --git a/codegen/src/shuttle_main/mod.rs b/codegen/src/shuttle_main/mod.rs index c8a03d1da..d523b1c3d 100644 --- a/codegen/src/shuttle_main/mod.rs +++ b/codegen/src/shuttle_main/mod.rs @@ -4,7 +4,7 @@ use quote::{quote, ToTokens}; use syn::{ parenthesized, parse::Parse, parse2, parse_macro_input, parse_quote, punctuated::Punctuated, spanned::Spanned, token::Paren, Attribute, Expr, FnArg, Ident, ItemFn, Pat, PatIdent, Path, - ReturnType, Signature, Stmt, Token, Type, + ReturnType, Signature, Stmt, Token, Type, TypePath, }; pub(crate) fn r#impl(_attr: TokenStream, item: TokenStream) -> TokenStream { @@ -12,34 +12,51 @@ pub(crate) fn r#impl(_attr: TokenStream, item: TokenStream) -> TokenStream { let wrapper = Wrapper::from_item_fn(&mut fn_decl); - let expanded = quote! { - #wrapper + let return_type = wrapper.fn_return.clone(); - fn __binder( - service: Box, - addr: std::net::SocketAddr, - runtime: &shuttle_service::Runtime, - ) -> shuttle_service::ServeHandle { - use shuttle_service::Context; - runtime.spawn(async move { service.bind(addr).await.context("failed to bind service").map_err(Into::into) }) - } + let fn_ident = &wrapper.fn_ident; + let mut fn_inputs: Vec<_> = Vec::with_capacity(wrapper.fn_inputs.len()); + let mut fn_inputs_builder: Vec<_> = Vec::with_capacity(wrapper.fn_inputs.len()); + let mut fn_inputs_builder_options: Vec<_> = Vec::with_capacity(wrapper.fn_inputs.len()); - #fn_decl + for input in wrapper.fn_inputs.iter() { + fn_inputs.push(&input.ident); + fn_inputs_builder.push(&input.builder.path); + fn_inputs_builder_options.push(&input.builder.options); + } + + let factory_ident: Ident = if wrapper.fn_inputs.is_empty() { + parse_quote!(_factory) + } else { + parse_quote!(factory) + }; - #[no_mangle] - pub extern "C" fn _create_service() -> *mut shuttle_service::Bootstrapper { - let builder: shuttle_service::StateBuilder> = - |factory, runtime, logger| Box::pin(__shuttle_wrapper(factory, runtime, logger)); + let extra_imports: Option = if wrapper.fn_inputs.is_empty() { + None + } else { + Some(parse_quote!( + use shuttle_service::ResourceBuilder; + )) + }; - let bootstrapper = shuttle_service::Bootstrapper::new( - builder, - __binder, - shuttle_service::Runtime::new().unwrap(), - ); + let expanded = quote! { + #[tokio::main] + async fn main() { + shuttle_runtime::start(loader).await; + } + + async fn loader( + mut factory: shuttle_runtime::ProvisionerFactory, + ) -> #return_type { + use shuttle_service::Context; + #extra_imports - let boxed = Box::new(bootstrapper); - Box::into_raw(boxed) + #(let #fn_inputs = #fn_inputs_builder::new()#fn_inputs_builder_options.build(&mut #factory_ident).await.context(format!("failed to provision {}", stringify!(#fn_inputs_builder)))?;)* + + #fn_ident(#(#fn_inputs),*).await } + + #fn_decl }; expanded.into() @@ -48,6 +65,7 @@ pub(crate) fn r#impl(_attr: TokenStream, item: TokenStream) -> TokenStream { struct Wrapper { fn_ident: Ident, fn_inputs: Vec, + fn_return: TypePath, } #[derive(Debug, PartialEq)] @@ -145,31 +163,38 @@ impl Wrapper { }) .collect(); - check_return_type(&item_fn.sig); + let type_path = check_return_type(item_fn.sig.clone()); Self { fn_ident: item_fn.sig.ident.clone(), fn_inputs: inputs, + fn_return: type_path.unwrap(), } } } -fn check_return_type(signature: &Signature) { - match &signature.output { - ReturnType::Default => emit_error!( - signature, - "shuttle_service::main functions need to return a service"; - hint = "See the docs for services with first class support"; - doc = "https://docs.rs/shuttle-service/latest/shuttle_service/attr.main.html#shuttle-supported-services" - ), - ReturnType::Type(_, r#type) => match r#type.as_ref() { - Type::Path(_) => {} - _ => emit_error!( - r#type, - "shuttle_service::main functions need to return a first class service or 'Result"; +fn check_return_type(signature: Signature) -> Option { + match signature.output { + ReturnType::Default => { + emit_error!( + signature, + "shuttle_service::main functions need to return a service"; hint = "See the docs for services with first class support"; doc = "https://docs.rs/shuttle-service/latest/shuttle_service/attr.main.html#shuttle-supported-services" - ), + ); + None + } + ReturnType::Type(_, r#type) => match *r#type { + Type::Path(path) => Some(path), + _ => { + emit_error!( + r#type, + "shuttle_service::main functions need to return a first class service or 'Result"; + hint = "See the docs for services with first class support"; + doc = "https://docs.rs/shuttle-service/latest/shuttle_service/attr.main.html#shuttle-supported-services" + ); + None + } }, } } @@ -196,6 +221,7 @@ fn attribute_to_builder(pat_ident: &PatIdent, attrs: Vec) -> syn::Res Ok(builder) } +/* impl ToTokens for Wrapper { fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { let fn_ident = &self.fn_ident; @@ -228,7 +254,7 @@ impl ToTokens for Wrapper { #factory_ident: &mut dyn shuttle_service::Factory, runtime: &shuttle_service::Runtime, logger: shuttle_service::Logger, - ) -> Result, shuttle_service::Error> { + ) { use shuttle_service::Context; use shuttle_service::tracing_subscriber::prelude::*; #extra_imports @@ -286,7 +312,7 @@ impl ToTokens for Wrapper { wrapper.to_tokens(tokens); } } - +*/ #[cfg(test)] mod tests { use pretty_assertions::assert_eq; @@ -313,6 +339,7 @@ mod tests { let input = Wrapper { fn_ident: parse_quote!(simple), fn_inputs: Vec::new(), + fn_return: parse_quote!(ShuttleSimple), }; let actual = quote!(#input); @@ -426,6 +453,7 @@ mod tests { }, }, ], + fn_return: parse_quote!(ShuttleComplex), }; let actual = quote!(#input); @@ -577,6 +605,7 @@ mod tests { options: Default::default(), }, }], + fn_return: parse_quote!(ShuttleComplex), }; input.fn_inputs[0] diff --git a/proto/src/lib.rs b/proto/src/lib.rs index a4d51a522..c66dba0c5 100644 --- a/proto/src/lib.rs +++ b/proto/src/lib.rs @@ -245,20 +245,18 @@ pub mod runtime { storage_manager_type: StorageManagerType, provisioner_address: &str, port: u16, - get_runtime_executable: impl FnOnce() -> PathBuf, + runtime_executable_path: PathBuf, ) -> anyhow::Result<(process::Child, runtime_client::RuntimeClient)> { - let runtime_flag = if wasm { "--axum" } else { "--legacy" }; + let _runtime_flag = if wasm { "--axum" } else { "--legacy" }; let (storage_manager_type, storage_manager_path) = match storage_manager_type { StorageManagerType::Artifacts(path) => ("artifacts", path), StorageManagerType::WorkingDir(path) => ("working-dir", path), }; - let runtime_executable = get_runtime_executable(); - - let runtime = process::Command::new(runtime_executable) + let runtime = process::Command::new(runtime_executable_path) .args([ - runtime_flag, + // runtime_flag, "--port", &port.to_string(), "--provisioner-address", diff --git a/service/src/lib.rs b/service/src/lib.rs index 7b1b55597..81a5db79f 100644 --- a/service/src/lib.rs +++ b/service/src/lib.rs @@ -231,6 +231,7 @@ mod logger; pub use logger::Logger; pub use shuttle_common::database; +pub use shuttle_common::storage_manager::StorageManager; #[cfg(feature = "codegen")] extern crate shuttle_codegen; @@ -399,7 +400,7 @@ pub type ServeHandle = JoinHandle>; // TODO: our current state machine in the api crate stores this service and can move it across // threads (handlers) causing `Service` to need `Sync`. We should remove this restriction #[async_trait] -pub trait Service: Send + Sync { +pub trait Service: Send { /// This function is run exactly once on each instance of a deployment. /// /// The deployer expects this instance of [Service][Service] to bind to the passed [SocketAddr][SocketAddr]. diff --git a/service/src/loader.rs b/service/src/loader.rs index 9f130716c..008334ea4 100644 --- a/service/src/loader.rs +++ b/service/src/loader.rs @@ -141,8 +141,6 @@ pub async fn build_crate( let mut ws = Workspace::new(&manifest_path, &config)?; let current = ws.current_mut().map_err(|_| anyhow!("A Shuttle project cannot have a virtual manifest file - please ensure your Cargo.toml file specifies it as a library."))?; - let manifest = current.manifest_mut(); - ensure_cdylib(manifest)?; let summary = current.manifest_mut().summary_mut(); make_name_unique(summary, deployment_id); @@ -156,7 +154,7 @@ pub async fn build_crate( let opts = get_compile_options(&config, release_mode, is_next)?; let compilation = compile(&ws, &opts); - let path = compilation?.cdylibs[0].path.clone(); + let path = compilation?.binaries[0].path.clone(); Ok(if is_next { Runtime::Next(path) } else { From e2fedb9920aca1ec993dde99cd79ff7bd3b84cb0 Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:52:49 +0100 Subject: [PATCH 2/9] refactor: wrapper to loader --- codegen/src/shuttle_main/mod.rs | 113 +++++--------------------------- 1 file changed, 16 insertions(+), 97 deletions(-) diff --git a/codegen/src/shuttle_main/mod.rs b/codegen/src/shuttle_main/mod.rs index d523b1c3d..69dd00e42 100644 --- a/codegen/src/shuttle_main/mod.rs +++ b/codegen/src/shuttle_main/mod.rs @@ -10,34 +10,7 @@ use syn::{ pub(crate) fn r#impl(_attr: TokenStream, item: TokenStream) -> TokenStream { let mut fn_decl = parse_macro_input!(item as ItemFn); - let wrapper = Wrapper::from_item_fn(&mut fn_decl); - - let return_type = wrapper.fn_return.clone(); - - let fn_ident = &wrapper.fn_ident; - let mut fn_inputs: Vec<_> = Vec::with_capacity(wrapper.fn_inputs.len()); - let mut fn_inputs_builder: Vec<_> = Vec::with_capacity(wrapper.fn_inputs.len()); - let mut fn_inputs_builder_options: Vec<_> = Vec::with_capacity(wrapper.fn_inputs.len()); - - for input in wrapper.fn_inputs.iter() { - fn_inputs.push(&input.ident); - fn_inputs_builder.push(&input.builder.path); - fn_inputs_builder_options.push(&input.builder.options); - } - - let factory_ident: Ident = if wrapper.fn_inputs.is_empty() { - parse_quote!(_factory) - } else { - parse_quote!(factory) - }; - - let extra_imports: Option = if wrapper.fn_inputs.is_empty() { - None - } else { - Some(parse_quote!( - use shuttle_service::ResourceBuilder; - )) - }; + let loader = Loader::from_item_fn(&mut fn_decl); let expanded = quote! { #[tokio::main] @@ -45,16 +18,7 @@ pub(crate) fn r#impl(_attr: TokenStream, item: TokenStream) -> TokenStream { shuttle_runtime::start(loader).await; } - async fn loader( - mut factory: shuttle_runtime::ProvisionerFactory, - ) -> #return_type { - use shuttle_service::Context; - #extra_imports - - #(let #fn_inputs = #fn_inputs_builder::new()#fn_inputs_builder_options.build(&mut #factory_ident).await.context(format!("failed to provision {}", stringify!(#fn_inputs_builder)))?;)* - - #fn_ident(#(#fn_inputs),*).await - } + #loader #fn_decl }; @@ -62,7 +26,7 @@ pub(crate) fn r#impl(_attr: TokenStream, item: TokenStream) -> TokenStream { expanded.into() } -struct Wrapper { +struct Loader { fn_ident: Ident, fn_inputs: Vec, fn_return: TypePath, @@ -135,7 +99,7 @@ impl Parse for BuilderOption { } } -impl Wrapper { +impl Loader { pub(crate) fn from_item_fn(item_fn: &mut ItemFn) -> Self { let inputs: Vec<_> = item_fn .sig @@ -221,10 +185,12 @@ fn attribute_to_builder(pat_ident: &PatIdent, attrs: Vec) -> syn::Res Ok(builder) } -/* -impl ToTokens for Wrapper { +impl ToTokens for Loader { fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { let fn_ident = &self.fn_ident; + + let return_type = &self.fn_return; + let mut fn_inputs: Vec<_> = Vec::with_capacity(self.fn_inputs.len()); let mut fn_inputs_builder: Vec<_> = Vec::with_capacity(self.fn_inputs.len()); let mut fn_inputs_builder_options: Vec<_> = Vec::with_capacity(self.fn_inputs.len()); @@ -249,70 +215,23 @@ impl ToTokens for Wrapper { )) }; - let wrapper = quote! { - async fn __shuttle_wrapper( - #factory_ident: &mut dyn shuttle_service::Factory, - runtime: &shuttle_service::Runtime, - logger: shuttle_service::Logger, - ) { + let loader = quote! { + async fn loader( + mut #factory_ident: shuttle_runtime::ProvisionerFactory, + ) -> #return_type { use shuttle_service::Context; - use shuttle_service::tracing_subscriber::prelude::*; #extra_imports - runtime.spawn_blocking(move || { - let filter_layer = - shuttle_service::tracing_subscriber::EnvFilter::try_from_default_env() - .or_else(|_| shuttle_service::tracing_subscriber::EnvFilter::try_new("INFO")) - .unwrap(); + #(let #fn_inputs = #fn_inputs_builder::new()#fn_inputs_builder_options.build(&mut #factory_ident).await.context(format!("failed to provision {}", stringify!(#fn_inputs_builder)))?;)* - shuttle_service::tracing_subscriber::registry() - .with(filter_layer) - .with(logger) - .init(); // this sets the subscriber as the global default and also adds a compatibility layer for capturing `log::Record`s - }) - .await - .map_err(|e| { - if e.is_panic() { - let mes = e - .into_panic() - .downcast_ref::<&str>() - .map(|x| x.to_string()) - .unwrap_or_else(|| "panicked setting logger".to_string()); - - shuttle_service::Error::BuildPanic(mes) - } else { - shuttle_service::Error::Custom(shuttle_service::error::CustomError::new(e).context("failed to set logger")) - } - })?; - - #(let #fn_inputs = #fn_inputs_builder::new()#fn_inputs_builder_options.build(#factory_ident, runtime).await.context(format!("failed to provision {}", stringify!(#fn_inputs_builder)))?;)* - - runtime.spawn(async { - #fn_ident(#(#fn_inputs),*) - .await - .map(|ok| Box::new(ok) as Box) - }) - .await - .map_err(|e| { - if e.is_panic() { - let mes = e - .into_panic() - .downcast_ref::<&str>() - .map(|x| x.to_string()) - .unwrap_or_else(|| "panicked calling main".to_string()); - - shuttle_service::Error::BuildPanic(mes) - } else { - shuttle_service::Error::Custom(shuttle_service::error::CustomError::new(e).context("failed to call main")) - } - })? + #fn_ident(#(#fn_inputs),*).await } }; - wrapper.to_tokens(tokens); + loader.to_tokens(tokens); } } -*/ + #[cfg(test)] mod tests { use pretty_assertions::assert_eq; From 4735530af0508d5f9afe9d488b8dca039dd9d87a Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Mon, 6 Mar 2023 15:04:01 +0100 Subject: [PATCH 3/9] tests: update the unit tests --- codegen/src/shuttle_main/mod.rs | 189 ++++---------------------------- 1 file changed, 24 insertions(+), 165 deletions(-) diff --git a/codegen/src/shuttle_main/mod.rs b/codegen/src/shuttle_main/mod.rs index 69dd00e42..083410397 100644 --- a/codegen/src/shuttle_main/mod.rs +++ b/codegen/src/shuttle_main/mod.rs @@ -238,7 +238,7 @@ mod tests { use quote::quote; use syn::{parse_quote, Ident}; - use super::{Builder, BuilderOptions, Input, Wrapper}; + use super::{Builder, BuilderOptions, Input, Loader}; #[test] fn from_with_return() { @@ -246,7 +246,7 @@ mod tests { async fn simple() -> ShuttleAxum {} ); - let actual = Wrapper::from_item_fn(&mut input); + let actual = Loader::from_item_fn(&mut input); let expected_ident: Ident = parse_quote!(simple); assert_eq!(actual.fn_ident, expected_ident); @@ -255,7 +255,7 @@ mod tests { #[test] fn output_with_return() { - let input = Wrapper { + let input = Loader { fn_ident: parse_quote!(simple), fn_inputs: Vec::new(), fn_return: parse_quote!(ShuttleSimple), @@ -263,58 +263,11 @@ mod tests { let actual = quote!(#input); let expected = quote! { - async fn __shuttle_wrapper( - _factory: &mut dyn shuttle_service::Factory, - runtime: &shuttle_service::Runtime, - logger: shuttle_service::Logger, - ) -> Result, shuttle_service::Error> { + async fn loader( + mut _factory: shuttle_runtime::ProvisionerFactory, + ) -> ShuttleSimple { use shuttle_service::Context; - use shuttle_service::tracing_subscriber::prelude::*; - runtime.spawn_blocking(move || { - let filter_layer = - shuttle_service::tracing_subscriber::EnvFilter::try_from_default_env() - .or_else(|_| shuttle_service::tracing_subscriber::EnvFilter::try_new("INFO")) - .unwrap(); - - shuttle_service::tracing_subscriber::registry() - .with(filter_layer) - .with(logger) - .init(); - }) - .await - .map_err(|e| { - if e.is_panic() { - let mes = e - .into_panic() - .downcast_ref::<&str>() - .map(|x| x.to_string()) - .unwrap_or_else(|| "panicked setting logger".to_string()); - - shuttle_service::Error::BuildPanic(mes) - } else { - shuttle_service::Error::Custom(shuttle_service::error::CustomError::new(e).context("failed to set logger")) - } - })?; - - runtime.spawn(async { - simple() - .await - .map(|ok| Box::new(ok) as Box) - }) - .await - .map_err(|e| { - if e.is_panic() { - let mes = e - .into_panic() - .downcast_ref::<&str>() - .map(|x| x.to_string()) - .unwrap_or_else(|| "panicked calling main".to_string()); - - shuttle_service::Error::BuildPanic(mes) - } else { - shuttle_service::Error::Custom(shuttle_service::error::CustomError::new(e).context("failed to call main")) - } - })? + simple().await } }; @@ -327,7 +280,7 @@ mod tests { async fn complex(#[shuttle_shared_db::Postgres] pool: PgPool) -> ShuttleTide {} ); - let actual = Wrapper::from_item_fn(&mut input); + let actual = Loader::from_item_fn(&mut input); let expected_ident: Ident = parse_quote!(complex); let expected_inputs: Vec = vec![Input { ident: parse_quote!(pool), @@ -354,7 +307,7 @@ mod tests { #[test] fn output_with_inputs() { - let input = Wrapper { + let input = Loader { fn_ident: parse_quote!(complex), fn_inputs: vec![ Input { @@ -377,63 +330,16 @@ mod tests { let actual = quote!(#input); let expected = quote! { - async fn __shuttle_wrapper( - factory: &mut dyn shuttle_service::Factory, - runtime: &shuttle_service::Runtime, - logger: shuttle_service::Logger, - ) -> Result, shuttle_service::Error> { + async fn loader( + mut factory: shuttle_runtime::ProvisionerFactory, + ) -> ShuttleComplex { use shuttle_service::Context; - use shuttle_service::tracing_subscriber::prelude::*; use shuttle_service::ResourceBuilder; - runtime.spawn_blocking(move || { - let filter_layer = - shuttle_service::tracing_subscriber::EnvFilter::try_from_default_env() - .or_else(|_| shuttle_service::tracing_subscriber::EnvFilter::try_new("INFO")) - .unwrap(); - - shuttle_service::tracing_subscriber::registry() - .with(filter_layer) - .with(logger) - .init(); - }) - .await - .map_err(|e| { - if e.is_panic() { - let mes = e - .into_panic() - .downcast_ref::<&str>() - .map(|x| x.to_string()) - .unwrap_or_else(|| "panicked setting logger".to_string()); - - shuttle_service::Error::BuildPanic(mes) - } else { - shuttle_service::Error::Custom(shuttle_service::error::CustomError::new(e).context("failed to set logger")) - } - })?; - - let pool = shuttle_shared_db::Postgres::new().build(factory, runtime).await.context(format!("failed to provision {}", stringify!(shuttle_shared_db::Postgres)))?; - let redis = shuttle_shared_db::Redis::new().build(factory, runtime).await.context(format!("failed to provision {}", stringify!(shuttle_shared_db::Redis)))?; - - runtime.spawn(async { - complex(pool, redis) - .await - .map(|ok| Box::new(ok) as Box) - }) - .await - .map_err(|e| { - if e.is_panic() { - let mes = e - .into_panic() - .downcast_ref::<&str>() - .map(|x| x.to_string()) - .unwrap_or_else(|| "panicked calling main".to_string()); - - shuttle_service::Error::BuildPanic(mes) - } else { - shuttle_service::Error::Custom(shuttle_service::error::CustomError::new(e).context("failed to call main")) - } - })? + let pool = shuttle_shared_db::Postgres::new().build(&mut factory).await.context(format!("failed to provision {}", stringify!(shuttle_shared_db::Postgres)))?; + let redis = shuttle_shared_db::Redis::new().build(&mut factory).await.context(format!("failed to provision {}", stringify!(shuttle_shared_db::Redis)))?; + + complex(pool, redis).await } }; @@ -488,7 +394,7 @@ mod tests { } ); - let actual = Wrapper::from_item_fn(&mut input); + let actual = Loader::from_item_fn(&mut input); let expected_ident: Ident = parse_quote!(complex); let mut expected_inputs: Vec = vec![Input { ident: parse_quote!(pool), @@ -515,7 +421,7 @@ mod tests { #[test] fn output_with_input_options() { - let mut input = Wrapper { + let mut input = Loader { fn_ident: parse_quote!(complex), fn_inputs: vec![Input { ident: parse_quote!(pool), @@ -540,62 +446,15 @@ mod tests { let actual = quote!(#input); let expected = quote! { - async fn __shuttle_wrapper( - factory: &mut dyn shuttle_service::Factory, - runtime: &shuttle_service::Runtime, - logger: shuttle_service::Logger, - ) -> Result, shuttle_service::Error> { + async fn loader( + mut factory: shuttle_runtime::ProvisionerFactory, + ) -> ShuttleComplex { use shuttle_service::Context; - use shuttle_service::tracing_subscriber::prelude::*; use shuttle_service::ResourceBuilder; - runtime.spawn_blocking(move || { - let filter_layer = - shuttle_service::tracing_subscriber::EnvFilter::try_from_default_env() - .or_else(|_| shuttle_service::tracing_subscriber::EnvFilter::try_new("INFO")) - .unwrap(); - - shuttle_service::tracing_subscriber::registry() - .with(filter_layer) - .with(logger) - .init(); - }) - .await - .map_err(|e| { - if e.is_panic() { - let mes = e - .into_panic() - .downcast_ref::<&str>() - .map(|x| x.to_string()) - .unwrap_or_else(|| "panicked setting logger".to_string()); - - shuttle_service::Error::BuildPanic(mes) - } else { - shuttle_service::Error::Custom(shuttle_service::error::CustomError::new(e).context("failed to set logger")) - } - })?; - - let pool = shuttle_shared_db::Postgres::new().size("10Gb").public(false).build(factory, runtime).await.context(format!("failed to provision {}", stringify!(shuttle_shared_db::Postgres)))?; - - runtime.spawn(async { - complex(pool) - .await - .map(|ok| Box::new(ok) as Box) - }) - .await - .map_err(|e| { - if e.is_panic() { - let mes = e - .into_panic() - .downcast_ref::<&str>() - .map(|x| x.to_string()) - .unwrap_or_else(|| "panicked calling main".to_string()); - - shuttle_service::Error::BuildPanic(mes) - } else { - shuttle_service::Error::Custom(shuttle_service::error::CustomError::new(e).context("failed to call main")) - } - })? + let pool = shuttle_shared_db::Postgres::new().size("10Gb").public(false).build(&mut factory).await.context(format!("failed to provision {}", stringify!(shuttle_shared_db::Postgres)))?; + + complex(pool).await } }; From 3344b4f2a90ce9f5c3b9c52e991801bd53c3c477 Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Mon, 6 Mar 2023 16:50:54 +0100 Subject: [PATCH 4/9] fix: don't unwrap return type --- codegen/src/shuttle_main/mod.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/codegen/src/shuttle_main/mod.rs b/codegen/src/shuttle_main/mod.rs index 083410397..701888730 100644 --- a/codegen/src/shuttle_main/mod.rs +++ b/codegen/src/shuttle_main/mod.rs @@ -100,7 +100,7 @@ impl Parse for BuilderOption { } impl Loader { - pub(crate) fn from_item_fn(item_fn: &mut ItemFn) -> Self { + pub(crate) fn from_item_fn(item_fn: &mut ItemFn) -> Option { let inputs: Vec<_> = item_fn .sig .inputs @@ -127,12 +127,14 @@ impl Loader { }) .collect(); - let type_path = check_return_type(item_fn.sig.clone()); - - Self { - fn_ident: item_fn.sig.ident.clone(), - fn_inputs: inputs, - fn_return: type_path.unwrap(), + if let Some(type_path) = check_return_type(item_fn.sig.clone()) { + Some(Self { + fn_ident: item_fn.sig.ident.clone(), + fn_inputs: inputs, + fn_return: type_path, + }) + } else { + None } } } @@ -246,7 +248,7 @@ mod tests { async fn simple() -> ShuttleAxum {} ); - let actual = Loader::from_item_fn(&mut input); + let actual = Loader::from_item_fn(&mut input).unwrap(); let expected_ident: Ident = parse_quote!(simple); assert_eq!(actual.fn_ident, expected_ident); @@ -280,7 +282,7 @@ mod tests { async fn complex(#[shuttle_shared_db::Postgres] pool: PgPool) -> ShuttleTide {} ); - let actual = Loader::from_item_fn(&mut input); + let actual = Loader::from_item_fn(&mut input).unwrap(); let expected_ident: Ident = parse_quote!(complex); let expected_inputs: Vec = vec![Input { ident: parse_quote!(pool), @@ -394,7 +396,7 @@ mod tests { } ); - let actual = Loader::from_item_fn(&mut input); + let actual = Loader::from_item_fn(&mut input).unwrap(); let expected_ident: Ident = parse_quote!(complex); let mut expected_inputs: Vec = vec![Input { ident: parse_quote!(pool), From d232512ffc74f58d7b04d0928f1bc171f012afe8 Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Mon, 6 Mar 2023 18:18:01 +0100 Subject: [PATCH 5/9] feat: setup tracing in loader codegen --- codegen/src/shuttle_main/mod.rs | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/codegen/src/shuttle_main/mod.rs b/codegen/src/shuttle_main/mod.rs index 701888730..b50d80eff 100644 --- a/codegen/src/shuttle_main/mod.rs +++ b/codegen/src/shuttle_main/mod.rs @@ -222,8 +222,19 @@ impl ToTokens for Loader { mut #factory_ident: shuttle_runtime::ProvisionerFactory, ) -> #return_type { use shuttle_service::Context; + use shuttle_service::tracing_subscriber::prelude::*; #extra_imports + let filter_layer = + shuttle_service::tracing_subscriber::EnvFilter::try_from_default_env() + .or_else(|_| shuttle_service::tracing_subscriber::EnvFilter::try_new("INFO")) + .unwrap(); + + shuttle_service::tracing_subscriber::registry() + .with(filter_layer) + .with(logger) + .init(); + #(let #fn_inputs = #fn_inputs_builder::new()#fn_inputs_builder_options.build(&mut #factory_ident).await.context(format!("failed to provision {}", stringify!(#fn_inputs_builder)))?;)* #fn_ident(#(#fn_inputs),*).await @@ -269,6 +280,18 @@ mod tests { mut _factory: shuttle_runtime::ProvisionerFactory, ) -> ShuttleSimple { use shuttle_service::Context; + use shuttle_service::tracing_subscriber::prelude::*; + + let filter_layer = + shuttle_service::tracing_subscriber::EnvFilter::try_from_default_env() + .or_else(|_| shuttle_service::tracing_subscriber::EnvFilter::try_new("INFO")) + .unwrap(); + + shuttle_service::tracing_subscriber::registry() + .with(filter_layer) + .with(logger) + .init(); + simple().await } }; @@ -336,8 +359,19 @@ mod tests { mut factory: shuttle_runtime::ProvisionerFactory, ) -> ShuttleComplex { use shuttle_service::Context; + use shuttle_service::tracing_subscriber::prelude::*; use shuttle_service::ResourceBuilder; + let filter_layer = + shuttle_service::tracing_subscriber::EnvFilter::try_from_default_env() + .or_else(|_| shuttle_service::tracing_subscriber::EnvFilter::try_new("INFO")) + .unwrap(); + + shuttle_service::tracing_subscriber::registry() + .with(filter_layer) + .with(logger) + .init(); + let pool = shuttle_shared_db::Postgres::new().build(&mut factory).await.context(format!("failed to provision {}", stringify!(shuttle_shared_db::Postgres)))?; let redis = shuttle_shared_db::Redis::new().build(&mut factory).await.context(format!("failed to provision {}", stringify!(shuttle_shared_db::Redis)))?; @@ -452,8 +486,19 @@ mod tests { mut factory: shuttle_runtime::ProvisionerFactory, ) -> ShuttleComplex { use shuttle_service::Context; + use shuttle_service::tracing_subscriber::prelude::*; use shuttle_service::ResourceBuilder; + let filter_layer = + shuttle_service::tracing_subscriber::EnvFilter::try_from_default_env() + .or_else(|_| shuttle_service::tracing_subscriber::EnvFilter::try_new("INFO")) + .unwrap(); + + shuttle_service::tracing_subscriber::registry() + .with(filter_layer) + .with(logger) + .init(); + let pool = shuttle_shared_db::Postgres::new().size("10Gb").public(false).build(&mut factory).await.context(format!("failed to provision {}", stringify!(shuttle_shared_db::Postgres)))?; complex(pool).await From a19915a047106d0178b3bc45a01ffa656e86c1b9 Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Mon, 6 Mar 2023 18:56:59 +0100 Subject: [PATCH 6/9] fix: pass inn logger to loader --- codegen/src/shuttle_main/mod.rs | 4 ++++ runtime/src/bin/rocket.rs | 1 + runtime/src/legacy/mod.rs | 21 ++++++++++++++++----- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/codegen/src/shuttle_main/mod.rs b/codegen/src/shuttle_main/mod.rs index b50d80eff..2a21ecca4 100644 --- a/codegen/src/shuttle_main/mod.rs +++ b/codegen/src/shuttle_main/mod.rs @@ -220,6 +220,7 @@ impl ToTokens for Loader { let loader = quote! { async fn loader( mut #factory_ident: shuttle_runtime::ProvisionerFactory, + logger: shuttle_service::Logger, ) -> #return_type { use shuttle_service::Context; use shuttle_service::tracing_subscriber::prelude::*; @@ -278,6 +279,7 @@ mod tests { let expected = quote! { async fn loader( mut _factory: shuttle_runtime::ProvisionerFactory, + logger: shuttle_service::Logger, ) -> ShuttleSimple { use shuttle_service::Context; use shuttle_service::tracing_subscriber::prelude::*; @@ -357,6 +359,7 @@ mod tests { let expected = quote! { async fn loader( mut factory: shuttle_runtime::ProvisionerFactory, + logger: shuttle_service::Logger, ) -> ShuttleComplex { use shuttle_service::Context; use shuttle_service::tracing_subscriber::prelude::*; @@ -484,6 +487,7 @@ mod tests { let expected = quote! { async fn loader( mut factory: shuttle_runtime::ProvisionerFactory, + logger: shuttle_service::Logger, ) -> ShuttleComplex { use shuttle_service::Context; use shuttle_service::tracing_subscriber::prelude::*; diff --git a/runtime/src/bin/rocket.rs b/runtime/src/bin/rocket.rs index 8da00a54f..622984b2d 100644 --- a/runtime/src/bin/rocket.rs +++ b/runtime/src/bin/rocket.rs @@ -6,6 +6,7 @@ async fn main() { async fn loader( mut factory: shuttle_runtime::ProvisionerFactory, + logger: shuttle_service::Logger, ) -> shuttle_service::ShuttleRocket { use shuttle_service::ResourceBuilder; diff --git a/runtime/src/legacy/mod.rs b/runtime/src/legacy/mod.rs index ea042a856..c57463f08 100644 --- a/runtime/src/legacy/mod.rs +++ b/runtime/src/legacy/mod.rs @@ -100,21 +100,29 @@ where { type Service: Service; - async fn load(self, factory: Fac) -> Result; + async fn load( + self, + factory: Fac, + logger: shuttle_service::Logger, + ) -> Result; } #[async_trait] impl Loader for F where - F: FnOnce(Fac) -> O + Send, + F: FnOnce(Fac, shuttle_service::Logger) -> O + Send, O: Future> + Send, Fac: Factory + 'static, S: Service, { type Service = S; - async fn load(self, factory: Fac) -> Result { - (self)(factory).await + async fn load( + self, + factory: Fac, + logger: shuttle_service::Logger, + ) -> Result { + (self)(factory, logger).await } } @@ -154,9 +162,12 @@ where ); trace!("got factory"); + let logs_tx = self.logs_tx.clone(); + let logger = shuttle_service::Logger::new(logs_tx, deployment_id); + let loader = self.loader.lock().unwrap().deref_mut().take().unwrap(); - let service = loader.load(factory).await.unwrap(); + let service = loader.load(factory, logger).await.unwrap(); *self.service.lock().unwrap() = Some(service); From d85817f157d7e6994b5f253b1ab62dce6f0a6fb1 Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Mon, 6 Mar 2023 21:25:42 +0100 Subject: [PATCH 7/9] feat: mvp of shuttle-next local run --- cargo-shuttle/src/lib.rs | 53 +++++++++++++++++++- proto/src/lib.rs | 25 +++++---- runtime/Cargo.toml | 2 +- runtime/src/bin/{next.rs => shuttle-next.rs} | 0 service/src/builder.rs | 7 ++- 5 files changed, 72 insertions(+), 15 deletions(-) rename runtime/src/bin/{next.rs => shuttle-next.rs} (100%) diff --git a/cargo-shuttle/src/lib.rs b/cargo-shuttle/src/lib.rs index 5861aaf0a..2c2466269 100644 --- a/cargo-shuttle/src/lib.rs +++ b/cargo-shuttle/src/lib.rs @@ -383,6 +383,7 @@ impl Shuttle { "Building".bold().green(), working_directory.display() ); + let runtime = build_crate(working_directory, false, tx).await?; trace!("loading secrets"); @@ -414,12 +415,62 @@ impl Shuttle { run_args.port + 1, )); + let runtime_path = || { + if is_wasm { + let runtime_path = home::cargo_home() + .expect("failed to find cargo home dir") + .join("bin/shuttle-next"); + + if cfg!(debug_assertions) { + // Canonicalized path to shuttle-runtime for dev to work on windows + let path = std::fs::canonicalize(format!("{MANIFEST_DIR}/../runtime")) + .expect("path to shuttle-runtime does not exist or is invalid"); + + // TODO: Add --features next here when https://github.com/shuttle-hq/shuttle/pull/688 is merged + std::process::Command::new("cargo") + .arg("install") + .arg("shuttle-runtime") + .arg("--path") + .arg(path) + .arg("--bin") + .arg("shuttle-next") + .output() + .expect("failed to install the shuttle runtime"); + } else { + // If the version of cargo-shuttle is different from shuttle-runtime, + // or it isn't installed, try to install shuttle-runtime from the production + // branch. + if let Err(err) = check_version(&runtime_path) { + trace!("{}", err); + + trace!("installing shuttle-runtime"); + // TODO: Add --features next here when https://github.com/shuttle-hq/shuttle/pull/688 is merged + std::process::Command::new("cargo") + .arg("install") + .arg("shuttle-runtime") + .arg("--bin") + .arg("shuttle-next") + .arg("--git") + .arg("https://github.com/shuttle-hq/shuttle") + .arg("--branch") + .arg("production") + .output() + .expect("failed to install the shuttle runtime"); + }; + }; + + runtime_path + } else { + bin_path.clone() + } + }; + let (mut runtime, mut runtime_client) = runtime::start( is_wasm, runtime::StorageManagerType::WorkingDir(working_directory.to_path_buf()), &format!("http://localhost:{}", run_args.port + 1), run_args.port + 2, - bin_path.clone(), + runtime_path, ) .await .map_err(|err| { diff --git a/proto/src/lib.rs b/proto/src/lib.rs index c66dba0c5..f27281d13 100644 --- a/proto/src/lib.rs +++ b/proto/src/lib.rs @@ -245,27 +245,34 @@ pub mod runtime { storage_manager_type: StorageManagerType, provisioner_address: &str, port: u16, - runtime_executable_path: PathBuf, + get_runtime_executable: impl FnOnce() -> PathBuf, ) -> anyhow::Result<(process::Child, runtime_client::RuntimeClient)> { - let _runtime_flag = if wasm { "--axum" } else { "--legacy" }; - let (storage_manager_type, storage_manager_path) = match storage_manager_type { StorageManagerType::Artifacts(path) => ("artifacts", path), StorageManagerType::WorkingDir(path) => ("working-dir", path), }; - let runtime = process::Command::new(runtime_executable_path) - .args([ - // runtime_flag, + let port = &port.to_string(); + let storage_manager_path = &storage_manager_path.display().to_string(); + let runtime_executable_path = get_runtime_executable(); + + let args = if wasm { + vec!["--port", port] + } else { + vec![ "--port", - &port.to_string(), + port, "--provisioner-address", provisioner_address, "--storage-manager-type", storage_manager_type, "--storage-manager-path", - &storage_manager_path.display().to_string(), - ]) + storage_manager_path, + ] + }; + + let runtime = process::Command::new(runtime_executable_path) + .args(&args) .spawn() .context("spawning runtime process")?; diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 897f97d8b..f807be186 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -10,7 +10,7 @@ publish = false name = "rocket" [[bin]] -name = "next" +name = "shuttle-next" [dependencies] anyhow = { workspace = true } diff --git a/runtime/src/bin/next.rs b/runtime/src/bin/shuttle-next.rs similarity index 100% rename from runtime/src/bin/next.rs rename to runtime/src/bin/shuttle-next.rs diff --git a/service/src/builder.rs b/service/src/builder.rs index 870284206..3fcd8c67f 100644 --- a/service/src/builder.rs +++ b/service/src/builder.rs @@ -62,13 +62,12 @@ pub async fn build_crate( check_no_panic(&ws)?; let opts = get_compile_options(&config, release_mode, is_next)?; - let compilation = compile(&ws, &opts); + let compilation = compile(&ws, &opts)?; - let path = compilation?.binaries[0].path.clone(); Ok(if is_next { - Runtime::Next(path) + Runtime::Next(compilation.cdylibs[0].path.clone()) } else { - Runtime::Legacy(path) + Runtime::Legacy(compilation.binaries[0].path.clone()) }) } From 2368bba5536fa11cd4b764c704b7695eac15322e Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Tue, 7 Mar 2023 10:26:39 +0100 Subject: [PATCH 8/9] refactor: move logger to runtime --- Cargo.lock | 3 ++- codegen/src/shuttle_main/mod.rs | 8 ++++---- runtime/Cargo.toml | 2 ++ runtime/src/bin/rocket.rs | 2 +- runtime/src/legacy/mod.rs | 10 +++++----- runtime/src/lib.rs | 2 ++ {service => runtime}/src/logger.rs | 0 service/Cargo.toml | 1 - service/src/lib.rs | 3 --- 9 files changed, 16 insertions(+), 15 deletions(-) rename {service => runtime}/src/logger.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index ce6076eab..c47655c27 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6401,11 +6401,13 @@ dependencies = [ "anyhow", "async-trait", "cap-std", + "chrono", "clap 4.0.27", "futures", "hyper", "rmp-serde", "rocket", + "serde_json", "shuttle-common", "shuttle-proto", "shuttle-secrets", @@ -6442,7 +6444,6 @@ dependencies = [ "bincode", "cargo", "cargo_metadata", - "chrono", "crossbeam-channel", "futures", "hyper", diff --git a/codegen/src/shuttle_main/mod.rs b/codegen/src/shuttle_main/mod.rs index 2a21ecca4..7db82e423 100644 --- a/codegen/src/shuttle_main/mod.rs +++ b/codegen/src/shuttle_main/mod.rs @@ -220,7 +220,7 @@ impl ToTokens for Loader { let loader = quote! { async fn loader( mut #factory_ident: shuttle_runtime::ProvisionerFactory, - logger: shuttle_service::Logger, + logger: shuttle_runtime::Logger, ) -> #return_type { use shuttle_service::Context; use shuttle_service::tracing_subscriber::prelude::*; @@ -279,7 +279,7 @@ mod tests { let expected = quote! { async fn loader( mut _factory: shuttle_runtime::ProvisionerFactory, - logger: shuttle_service::Logger, + logger: shuttle_runtime::Logger, ) -> ShuttleSimple { use shuttle_service::Context; use shuttle_service::tracing_subscriber::prelude::*; @@ -359,7 +359,7 @@ mod tests { let expected = quote! { async fn loader( mut factory: shuttle_runtime::ProvisionerFactory, - logger: shuttle_service::Logger, + logger: shuttle_runtime::Logger, ) -> ShuttleComplex { use shuttle_service::Context; use shuttle_service::tracing_subscriber::prelude::*; @@ -487,7 +487,7 @@ mod tests { let expected = quote! { async fn loader( mut factory: shuttle_runtime::ProvisionerFactory, - logger: shuttle_service::Logger, + logger: shuttle_runtime::Logger, ) -> ShuttleComplex { use shuttle_service::Context; use shuttle_service::tracing_subscriber::prelude::*; diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 3a147171d..b8ce5c235 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -16,7 +16,9 @@ required-features = ["next"] [dependencies] anyhow = { workspace = true } async-trait = { workspace = true } +chrono = { workspace = true } clap ={ version = "4.0.18", features = ["derive"] } +serde_json = { workspace = true } thiserror = { workspace = true } tokio = { version = "1.22.0", features = ["full"] } tokio-stream = "0.1.11" diff --git a/runtime/src/bin/rocket.rs b/runtime/src/bin/rocket.rs index 622984b2d..9222f709d 100644 --- a/runtime/src/bin/rocket.rs +++ b/runtime/src/bin/rocket.rs @@ -6,7 +6,7 @@ async fn main() { async fn loader( mut factory: shuttle_runtime::ProvisionerFactory, - logger: shuttle_service::Logger, + logger: shuttle_runtime::Logger, ) -> shuttle_service::ShuttleRocket { use shuttle_service::ResourceBuilder; diff --git a/runtime/src/legacy/mod.rs b/runtime/src/legacy/mod.rs index e8b496bc7..9cc3fa4b3 100644 --- a/runtime/src/legacy/mod.rs +++ b/runtime/src/legacy/mod.rs @@ -36,7 +36,7 @@ use tonic::{ use tracing::{error, instrument, trace}; use uuid::Uuid; -use crate::provisioner_factory::ProvisionerFactory; +use crate::{provisioner_factory::ProvisionerFactory, Logger}; use self::args::Args; @@ -103,14 +103,14 @@ where async fn load( self, factory: Fac, - logger: shuttle_service::Logger, + logger: Logger, ) -> Result; } #[async_trait] impl Loader for F where - F: FnOnce(Fac, shuttle_service::Logger) -> O + Send, + F: FnOnce(Fac, Logger) -> O + Send, O: Future> + Send, Fac: Factory + 'static, S: Service, @@ -120,7 +120,7 @@ where async fn load( self, factory: Fac, - logger: shuttle_service::Logger, + logger: Logger, ) -> Result { (self)(factory, logger).await } @@ -163,7 +163,7 @@ where trace!("got factory"); let logs_tx = self.logs_tx.clone(); - let logger = shuttle_service::Logger::new(logs_tx, deployment_id); + let logger = Logger::new(logs_tx, deployment_id); let loader = self.loader.lock().unwrap().deref_mut().take().unwrap(); diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 33babf1c7..6090dca6d 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1,9 +1,11 @@ mod legacy; +mod logger; #[cfg(feature = "next")] mod next; mod provisioner_factory; pub use legacy::{start, Legacy}; +pub use logger::Logger; #[cfg(feature = "next")] pub use next::{AxumWasm, NextArgs}; pub use provisioner_factory::ProvisionerFactory; diff --git a/service/src/logger.rs b/runtime/src/logger.rs similarity index 100% rename from service/src/logger.rs rename to runtime/src/logger.rs diff --git a/service/Cargo.toml b/service/Cargo.toml index ae3a29eb8..f9943a4d2 100644 --- a/service/Cargo.toml +++ b/service/Cargo.toml @@ -18,7 +18,6 @@ bincode = { version = "1.3.3", optional = true } # TODO: debug the libgit2-sys conflict with cargo-edit when upgrading cargo to 0.66 cargo = { version = "0.65.0", optional = true } cargo_metadata = "0.15.2" -chrono = { workspace = true } crossbeam-channel = "0.5.6" futures = { version = "0.3.25", features = ["std"] } hyper = { version = "0.14.23", features = ["server", "tcp", "http1"], optional = true } diff --git a/service/src/lib.rs b/service/src/lib.rs index 48886e0be..f29cc902a 100644 --- a/service/src/lib.rs +++ b/service/src/lib.rs @@ -223,9 +223,6 @@ pub use tracing_subscriber; pub mod error; pub use error::Error; -mod logger; -pub use logger::Logger; - pub use shuttle_common::database; pub use shuttle_common::storage_manager::StorageManager; From b0150c3b793f12465b9d73548c4a1c6b52a4601d Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Tue, 7 Mar 2023 10:31:50 +0100 Subject: [PATCH 9/9] refactor: move storagemanager export to runtime --- codegen/src/shuttle_main/mod.rs | 8 ++++---- runtime/src/lib.rs | 1 + service/src/lib.rs | 1 - 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/codegen/src/shuttle_main/mod.rs b/codegen/src/shuttle_main/mod.rs index 7db82e423..3b73f82a5 100644 --- a/codegen/src/shuttle_main/mod.rs +++ b/codegen/src/shuttle_main/mod.rs @@ -218,7 +218,7 @@ impl ToTokens for Loader { }; let loader = quote! { - async fn loader( + async fn loader( mut #factory_ident: shuttle_runtime::ProvisionerFactory, logger: shuttle_runtime::Logger, ) -> #return_type { @@ -277,7 +277,7 @@ mod tests { let actual = quote!(#input); let expected = quote! { - async fn loader( + async fn loader( mut _factory: shuttle_runtime::ProvisionerFactory, logger: shuttle_runtime::Logger, ) -> ShuttleSimple { @@ -357,7 +357,7 @@ mod tests { let actual = quote!(#input); let expected = quote! { - async fn loader( + async fn loader( mut factory: shuttle_runtime::ProvisionerFactory, logger: shuttle_runtime::Logger, ) -> ShuttleComplex { @@ -485,7 +485,7 @@ mod tests { let actual = quote!(#input); let expected = quote! { - async fn loader( + async fn loader( mut factory: shuttle_runtime::ProvisionerFactory, logger: shuttle_runtime::Logger, ) -> ShuttleComplex { diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 6090dca6d..6e51ff0f4 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -9,3 +9,4 @@ pub use logger::Logger; #[cfg(feature = "next")] pub use next::{AxumWasm, NextArgs}; pub use provisioner_factory::ProvisionerFactory; +pub use shuttle_common::storage_manager::StorageManager; diff --git a/service/src/lib.rs b/service/src/lib.rs index f29cc902a..de58ad046 100644 --- a/service/src/lib.rs +++ b/service/src/lib.rs @@ -224,7 +224,6 @@ pub mod error; pub use error::Error; pub use shuttle_common::database; -pub use shuttle_common::storage_manager::StorageManager; #[cfg(feature = "codegen")] extern crate shuttle_codegen;