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

chore: move codegen::main from service to runtime #1013

Merged
merged 1 commit into from
Jun 23, 2023
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion resources/aws-rds/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions resources/persist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
11 changes: 4 additions & 7 deletions resources/persist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,7 +27,7 @@ pub struct Persist;

#[derive(Deserialize, Serialize, Clone)]
pub struct PersistInstance {
service_name: ProjectName,
service_name: ServiceName,
}

impl PersistInstance {
Expand Down Expand Up @@ -100,13 +98,12 @@ impl ResourceBuilder<PersistInstance> 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();
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion resources/secrets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
2 changes: 1 addition & 1 deletion resources/shared-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion resources/static-folder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 5 additions & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"]
Expand Down
62 changes: 58 additions & 4 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
11 changes: 3 additions & 8 deletions service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"]
69 changes: 6 additions & 63 deletions service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
///
Expand Down Expand Up @@ -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";