diff --git a/Cargo.lock b/Cargo.lock index 21ef461c7..1017ca4ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5433,6 +5433,7 @@ dependencies = [ "rmp-serde", "serde", "serde_json", + "shuttle-codegen", "shuttle-common", "shuttle-proto", "shuttle-service", @@ -5459,7 +5460,6 @@ dependencies = [ "crossbeam-channel", "os_pipe", "serde", - "shuttle-codegen", "shuttle-common", "strfmt", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index a8e6d6cdc..37a96f9ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,6 +73,7 @@ rmp-serde = "1.1.1" serde = { version = "1.0.148", default-features = false } serde_json = "1.0.89" sqlx = "0.6.3" +strfmt = "0.2.2" strum = { version = "0.24.1", features = ["derive"] } tempfile = "3.4.0" thiserror = "1.0.37" diff --git a/resources/aws-rds/Cargo.toml b/resources/aws-rds/Cargo.toml index aa17cfa4f..878493dfb 100644 --- a/resources/aws-rds/Cargo.toml +++ b/resources/aws-rds/Cargo.toml @@ -10,7 +10,7 @@ keywords = ["shuttle-service", "rds"] async-trait = "0.1.56" paste = "1.0.7" serde = { version = "1.0.148", features = ["derive"] } -shuttle-service = { path = "../../service", version = "0.19.0", default-features = false } +shuttle-service = { path = "../../service", version = "0.19.0" } sqlx = { version = "0.6.2", features = ["runtime-tokio-native-tls"] } [features] diff --git a/resources/persist/Cargo.toml b/resources/persist/Cargo.toml index 819cf9535..846d44e28 100644 --- a/resources/persist/Cargo.toml +++ b/resources/persist/Cargo.toml @@ -10,6 +10,5 @@ keywords = ["shuttle-service", "persistence"] async-trait = "0.1.56" bincode = "1.2.1" serde = { version = "1.0.0", features = ["derive"] } -shuttle-common = { path = "../../common", version = "0.19.0", default-features = false } -shuttle-service = { path = "../../service", version = "0.19.0", default-features = false } +shuttle-service = { path = "../../service", version = "0.19.0" } thiserror = "1.0.32" diff --git a/resources/persist/src/lib.rs b/resources/persist/src/lib.rs index d7a71097b..e93b44088 100644 --- a/resources/persist/src/lib.rs +++ b/resources/persist/src/lib.rs @@ -2,9 +2,7 @@ use async_trait::async_trait; use bincode::{deserialize_from, serialize_into, Error as BincodeError}; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; -use shuttle_common::project::ProjectName; -use shuttle_service::Type; -use shuttle_service::{Factory, ResourceBuilder}; +use shuttle_service::{Factory, ResourceBuilder, ServiceName, Type}; use std::fs; use std::fs::File; use std::io::BufReader; @@ -29,7 +27,7 @@ pub struct Persist; #[derive(Deserialize, Serialize, Clone)] pub struct PersistInstance { - service_name: ProjectName, + service_name: ServiceName, } impl PersistInstance { @@ -100,13 +98,12 @@ impl ResourceBuilder for Persist { #[cfg(test)] mod tests { use super::*; - use shuttle_common::project::ProjectName; use std::str::FromStr; #[test] fn test_save_and_load() { let persist = PersistInstance { - service_name: ProjectName::from_str("test").unwrap(), + service_name: ServiceName::from_str("test").unwrap(), }; persist.save("test", "test").unwrap(); @@ -117,7 +114,7 @@ mod tests { #[test] fn test_load_error() { let persist = PersistInstance { - service_name: ProjectName::from_str("test").unwrap(), + service_name: ServiceName::from_str("test").unwrap(), }; // unwrapp error diff --git a/resources/secrets/Cargo.toml b/resources/secrets/Cargo.toml index d3e9acc02..65fd4e793 100644 --- a/resources/secrets/Cargo.toml +++ b/resources/secrets/Cargo.toml @@ -9,4 +9,4 @@ keywords = ["shuttle-service", "secrets"] [dependencies] async-trait = "0.1.56" serde = { version = "1.0.148", features = ["derive"] } -shuttle-service = { path = "../../service", version = "0.19.0", default-features = false } +shuttle-service = { path = "../../service", version = "0.19.0" } diff --git a/resources/shared-db/Cargo.toml b/resources/shared-db/Cargo.toml index 0d744e01b..5d1460391 100644 --- a/resources/shared-db/Cargo.toml +++ b/resources/shared-db/Cargo.toml @@ -10,7 +10,7 @@ keywords = ["shuttle-service", "database"] async-trait = "0.1.56" mongodb = { version = "2.3.0", optional = true } serde = { version = "1.0.148", features = ["derive"] } -shuttle-service = { path = "../../service", version = "0.19.0", default-features = false } +shuttle-service = { path = "../../service", version = "0.19.0" } sqlx = { version = "0.6.2", optional = true } [features] diff --git a/resources/static-folder/Cargo.toml b/resources/static-folder/Cargo.toml index 0e76af80d..d17c131b9 100644 --- a/resources/static-folder/Cargo.toml +++ b/resources/static-folder/Cargo.toml @@ -11,7 +11,7 @@ async-trait = "0.1.56" dunce = "1.0.3" fs_extra = "1.3.0" serde = { version = "1.0.148", features = ["derive"] } -shuttle-service = { path = "../../service", version = "0.19.0", default-features = false } +shuttle-service = { path = "../../service", version = "0.19.0" } tracing = "0.1.37" [dev-dependencies] diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index ecd051c08..74f9bdd41 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -19,7 +19,7 @@ chrono = { workspace = true } prost-types = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } -strfmt = "0.2.2" +strfmt = { workspace = true } thiserror = { workspace = true } tokio = { workspace = true, features = ["full"] } tokio-stream = "0.1.11" @@ -39,6 +39,10 @@ wasi-common = { version = "7.0.0", optional = true } wasmtime = { version = "7.0.0", optional = true } wasmtime-wasi = { version = "7.0.0", optional = true } +[dependencies.shuttle-codegen] +workspace = true +features = ["frameworks"] + [dependencies.shuttle-common] workspace = true features = ["claims", "backend"] diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 7972ed9dd..2af364b5f 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -20,7 +20,7 @@ //! //! Now that shuttle is installed, you can initialize a project with Axum boilerplate: //! ```bash -//! $ cargo shuttle init --axum my-axum-app +//! $ cargo shuttle init --template axum my-axum-app //! ``` //! //! By looking at the `Cargo.toml` file of the generated `my-axum-app` project you will see it has been made to @@ -106,7 +106,7 @@ //! //! Initialize a project with Rocket boilerplate: //! ```bash -//! $ cargo shuttle init --rocket my-rocket-app +//! $ cargo shuttle init --template rocket my-rocket-app //! ``` //! //! Add `shuttle-shared-db` as a dependency with the `postgres` feature, and add `sqlx` as a dependency with the @@ -214,6 +214,59 @@ //! //! You can also [open an issue or a discussion on GitHub](https://github.com/shuttle-hq/shuttle). //! + +/// Helper macro that generates the entrypoint required by any service - likely the only macro you need in this crate. +/// +/// # Without shuttle managed resources +/// The simplest usage is when your service does not require any shuttle managed resources, so you only need to return a shuttle supported service: +/// +/// ```rust,no_run +/// use shuttle_rocket::ShuttleRocket; +/// +/// #[shuttle_rocket::main] +/// async fn rocket() -> ShuttleRocket { +/// let rocket = rocket::build(); +/// +/// Ok(rocket.into()) +/// } +/// ``` +/// +/// ## shuttle supported services +/// The following types can be returned from a `#[shuttle_service::main]` function and enjoy first class service support in shuttle. +/// +/// | Return type | Crate | Service | Version | Example | +/// | ------------------------------------- |-------------------------------------------------------------- | ------------------------------------------- | ---------- | ----------------------------------------------------------------------------------- | +/// | `ShuttleActixWeb` |[shuttle-actix-web](https://crates.io/crates/shuttle-actix-web)| [actix-web](https://docs.rs/actix-web/4.3) | 4.3 | [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/actix-web/hello-world) | +/// | `ShuttleAxum` |[shuttle-axum](https://crates.io/crates/shuttle-axum) | [axum](https://docs.rs/axum/0.6) | 0.5 | [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/axum/hello-world) | +/// | `ShuttlePoem` |[shuttle-poem](https://crates.io/crates/shuttle-poem) | [poem](https://docs.rs/poem/1.3) | 1.3 | [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/poem/hello-world) | +/// | `ShuttlePoise` |[shuttle-poise](https://crates.io/crates/shuttle-poise) | [poise](https://docs.rs/poise/0.5) | 0.5 | [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/poise/hello-world) | +/// | `ShuttleRocket` |[shuttle-rocket](https://crates.io/crates/shuttle-rocket) | [rocket](https://docs.rs/rocket/0.5.0-rc.2) | 0.5.0-rc.2 | [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/rocket/hello-world) | +/// | `ShuttleSalvo` |[shuttle-salvo](https://crates.io/crates/shuttle-salvo) | [salvo](https://docs.rs/salvo/0.37) | 0.37 | [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/salvo/hello-world) | +/// | `ShuttleSerenity` |[shuttle-serenity](https://crates.io/crates/shuttle-serenity | [serenity](https://docs.rs/serenity/0.11) | 0.11 | [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/serenity/hello-world) | +/// | `ShuttleThruster` |[shuttle-thruster](https://crates.io/crates/shuttle-thruster) | [thruster](https://docs.rs/thruster/1.3) | 1.3 | [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/thruster/hello-world) | +/// | `ShuttleTower` |[shuttle-tower](https://crates.io/crates/shuttle-tower) | [tower](https://docs.rs/tower/0.4) | 0.4 | [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/tower/hello-world) | +/// | `ShuttleTide` |[shuttle-tide](https://crates.io/crates/shuttle-tide) | [tide](https://docs.rs/tide/0.16) | 0.16 | [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/tide/hello-world) | +/// +/// # Getting shuttle managed resources +/// Shuttle is able to manage resource dependencies for you. These resources are passed in as inputs to your `#[shuttle_runtime::main]` function and are configured using attributes: +/// ```rust,no_run +/// use sqlx::PgPool; +/// use shuttle_rocket::ShuttleRocket; +/// +/// struct MyState(PgPool); +/// +/// #[shuttle_runtime::main] +/// async fn rocket(#[shuttle_shared_db::Postgres] pool: PgPool) -> ShuttleRocket { +/// let state = MyState(pool); +/// let rocket = rocket::build().manage(state); +/// +/// Ok(rocket.into()) +/// } +/// ``` +/// +/// More [shuttle managed resources can be found here](https://github.com/shuttle-hq/shuttle/tree/main/resources) +pub use shuttle_codegen::main; + mod alpha; mod args; mod logger; @@ -223,14 +276,15 @@ mod provisioner_factory; mod resource_tracker; pub use alpha::{start, Alpha}; -pub use async_trait::async_trait; pub use logger::Logger; #[cfg(feature = "next")] pub use next::{AxumWasm, NextArgs}; pub use provisioner_factory::ProvisionerFactory; pub use resource_tracker::{get_resource, ResourceTracker}; pub use shuttle_common::storage_manager::StorageManager; -pub use shuttle_service::{main, CustomError, Error, Factory, ResourceBuilder, Service}; +pub use shuttle_service::{CustomError, Error, Factory, ResourceBuilder, Service}; + +pub use async_trait::async_trait; // Dependencies required by the codegen pub use anyhow::Context; diff --git a/service/Cargo.toml b/service/Cargo.toml index 34a6e2c55..e05106fe7 100644 --- a/service/Cargo.toml +++ b/service/Cargo.toml @@ -17,16 +17,12 @@ cargo_metadata = { workspace = true, optional = true } crossbeam-channel = { workspace = true, optional = true } os_pipe = { version = "1.1.4", optional = true } serde = { workspace = true, features = ["derive"] } -strfmt = "0.2.2" +strfmt = { workspace = true } thiserror = { workspace = true } -tokio = { workspace = true, features = ["sync", "process"], optional = true } +tokio = { workspace = true, features = ["process"], optional = true } toml = { workspace = true, optional = true } tracing = { workspace = true, optional = true } -[dependencies.shuttle-codegen] -workspace = true -optional = true - [dependencies.shuttle-common] workspace = true features = ["service"] @@ -35,7 +31,6 @@ features = ["service"] tokio = { workspace = true, features = ["macros", "rt"] } [features] -default = ["codegen"] +default = [] -codegen = ["shuttle-codegen/frameworks"] builder = ["cargo_metadata", "crossbeam-channel", "os_pipe", "tokio", "toml", "tracing"] diff --git a/service/src/lib.rs b/service/src/lib.rs index 53ac2322f..fa9b7885b 100644 --- a/service/src/lib.rs +++ b/service/src/lib.rs @@ -3,74 +3,20 @@ use std::net::SocketAddr; use std::path::PathBuf; use async_trait::async_trait; - -pub mod error; -pub use error::{CustomError, Error}; - use serde::{de::DeserializeOwned, Serialize}; pub use shuttle_common::{ - database, resource::Type, DatabaseReadyInfo, DbInput, DbOutput, SecretStore, + database, deployment::Environment, project::ProjectName as ServiceName, resource::Type, + DatabaseReadyInfo, DbInput, DbOutput, SecretStore, }; -#[cfg(feature = "codegen")] -extern crate shuttle_codegen; -#[cfg(feature = "codegen")] -/// Helper macro that generates the entrypoint required by any service - likely the only macro you need in this crate. -/// -/// # Without shuttle managed resources -/// The simplest usage is when your service does not require any shuttle managed resources, so you only need to return a shuttle supported service: -/// -/// ```rust,no_run -/// use shuttle_rocket::ShuttleRocket; -/// -/// #[shuttle_rocket::main] -/// async fn rocket() -> ShuttleRocket { -/// let rocket = rocket::build(); -/// -/// Ok(rocket.into()) -/// } -/// ``` -/// -/// ## shuttle supported services -/// The following types can be returned from a `#[shuttle_service::main]` function and enjoy first class service support in shuttle. -/// -/// | Return type | Crate | Service | Version | Example | -/// | ------------------------------------- |-------------------------------------------------------------- | ------------------------------------------- | ---------- | ----------------------------------------------------------------------------------- | -/// | `ShuttleActixWeb` |[shuttle-actix-web](https://crates.io/crates/shuttle-actix-web)| [actix-web](https://docs.rs/actix-web/4.3) | 4.3 | [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/actix-web/hello-world) | -/// | `ShuttleAxum` |[shuttle-axum](https://crates.io/crates/shuttle-axum) | [axum](https://docs.rs/axum/0.6) | 0.5 | [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/axum/hello-world) | -/// | `ShuttlePoem` |[shuttle-poem](https://crates.io/crates/shuttle-poem) | [poem](https://docs.rs/poem/1.3) | 1.3 | [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/poem/hello-world) | -/// | `ShuttlePoise` |[shuttle-poise](https://crates.io/crates/shuttle-poise) | [poise](https://docs.rs/poise/0.5) | 0.5 | [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/poise/hello-world) | -/// | `ShuttleRocket` |[shuttle-rocket](https://crates.io/crates/shuttle-rocket) | [rocket](https://docs.rs/rocket/0.5.0-rc.2) | 0.5.0-rc.2 | [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/rocket/hello-world) | -/// | `ShuttleSalvo` |[shuttle-salvo](https://crates.io/crates/shuttle-salvo) | [salvo](https://docs.rs/salvo/0.37) | 0.37 | [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/salvo/hello-world) | -/// | `ShuttleSerenity` |[shuttle-serenity](https://crates.io/crates/shuttle-serenity | [serenity](https://docs.rs/serenity/0.11) | 0.11 | [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/serenity/hello-world) | -/// | `ShuttleThruster` |[shuttle-thruster](https://crates.io/crates/shuttle-thruster) | [thruster](https://docs.rs/thruster/1.3) | 1.3 | [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/thruster/hello-world) | -/// | `ShuttleTower` |[shuttle-tower](https://crates.io/crates/shuttle-tower) | [tower](https://docs.rs/tower/0.4) | 0.4 | [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/tower/hello-world) | -/// | `ShuttleTide` |[shuttle-tide](https://crates.io/crates/shuttle-tide) | [tide](https://docs.rs/tide/0.16) | 0.16 | [GitHub](https://github.com/shuttle-hq/shuttle-examples/tree/main/tide/hello-world) | -/// -/// # Getting shuttle managed resources -/// Shuttle is able to manage resource dependencies for you. These resources are passed in as inputs to your `#[shuttle_runtime::main]` function and are configured using attributes: -/// ```rust,no_run -/// use sqlx::PgPool; -/// use shuttle_rocket::ShuttleRocket; -/// -/// struct MyState(PgPool); -/// -/// #[shuttle_runtime::main] -/// async fn rocket(#[shuttle_shared_db::Postgres] pool: PgPool) -> ShuttleRocket { -/// let state = MyState(pool); -/// let rocket = rocket::build().manage(state); -/// -/// Ok(rocket.into()) -/// } -/// ``` -/// -/// More [shuttle managed resources can be found here](https://github.com/shuttle-hq/shuttle/tree/main/resources) -pub use shuttle_codegen::main; +pub mod error; +pub use error::{CustomError, Error}; #[cfg(feature = "builder")] pub mod builder; -pub use shuttle_common::{deployment::Environment, project::ProjectName as ServiceName}; +pub const NEXT_NAME: &str = "shuttle-next"; +pub const RUNTIME_NAME: &str = "shuttle-runtime"; /// Factories can be used to request the provisioning of additional resources (like databases). /// @@ -216,6 +162,3 @@ pub trait Service: Send { /// The deployer expects this instance of [Service][Service] to bind to the passed [SocketAddr][SocketAddr]. async fn bind(mut self, addr: SocketAddr) -> Result<(), error::Error>; } - -pub const NEXT_NAME: &str = "shuttle-next"; -pub const RUNTIME_NAME: &str = "shuttle-runtime";