diff --git a/cargo-shuttle/src/args.rs b/cargo-shuttle/src/args.rs index f43327c2a..8a8d61dcc 100644 --- a/cargo-shuttle/src/args.rs +++ b/cargo-shuttle/src/args.rs @@ -382,8 +382,14 @@ pub struct RunArgs { #[arg(long)] pub external: bool, /// Use release mode for building the project - #[arg(long, short = 'r')] + #[arg(long, short = 'r', conflicts_with = "profile")] pub release: bool, + /// Build with the specified profile + #[arg(long, conflicts_with = "release")] + pub profile: Option, + /// Space or comma separated list of features to activate + #[arg(long)] + pub features: Option, /// Don't display timestamps and log origin tags #[arg(long)] pub raw: bool, diff --git a/cargo-shuttle/src/builder.rs b/cargo-shuttle/src/builder.rs index a1cb2074b..73d313e70 100644 --- a/cargo-shuttle/src/builder.rs +++ b/cargo-shuttle/src/builder.rs @@ -20,6 +20,8 @@ pub struct BuiltService { pub async fn build_workspace( project_path: &Path, release_mode: bool, + profile: Option<&str>, + features: Option<&str>, tx: tokio::sync::mpsc::Sender, ) -> Result { let project_path = project_path.to_owned(); @@ -62,6 +64,8 @@ pub async fn build_workspace( package, target, release_mode, + profile, + features, project_path.clone(), metadata.target_directory.clone(), tx.clone(), @@ -162,6 +166,8 @@ async fn cargo_build( package: Package, target: Target, release_mode: bool, + profile: Option<&str>, + features: Option<&str>, project_path: PathBuf, target_path: impl Into, tx: tokio::sync::mpsc::Sender, @@ -182,12 +188,22 @@ async fn cargo_build( .current_dir(project_path.as_path()); if package.features.contains_key("shuttle") { - cmd.arg("--no-default-features").arg("--features=shuttle"); + cmd.arg("--no-default-features"); + if let Some(features) = features { + cmd.arg("--features").arg(format!("shuttle,{}", features)); + } else { + cmd.arg("--features=shuttle"); + } + } else if let Some(features) = features { + cmd.arg("--features").arg(features); } cmd.arg("--package").arg(package.name.as_str()); cmd.arg("--bin").arg(target.name.as_str()); - let profile = if release_mode { + let profile = if let Some(profile_name) = profile { + cmd.arg("--profile").arg(profile_name); + profile_name + } else if release_mode { cmd.arg("--release"); "release" } else { diff --git a/cargo-shuttle/src/lib.rs b/cargo-shuttle/src/lib.rs index 66bc08e7b..2978ed51d 100644 --- a/cargo-shuttle/src/lib.rs +++ b/cargo-shuttle/src/lib.rs @@ -1340,7 +1340,14 @@ impl Shuttle { project_directory.display() ); - build_workspace(project_directory, run_args.release, tx).await + build_workspace( + project_directory, + run_args.release, + run_args.profile.as_deref(), + run_args.features.as_deref(), + tx, + ) + .await } fn find_available_port(run_args: &mut RunArgs) { diff --git a/cargo-shuttle/tests/integration/builder.rs b/cargo-shuttle/tests/integration/builder.rs index 87b296bf4..2f748e66c 100644 --- a/cargo-shuttle/tests/integration/builder.rs +++ b/cargo-shuttle/tests/integration/builder.rs @@ -9,7 +9,7 @@ use cargo_shuttle::builder::{build_workspace, BuiltService}; async fn not_shuttle() { let (tx, _) = tokio::sync::mpsc::channel::(256); let project_path = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/resources/not-shuttle"); - build_workspace(Path::new(&project_path), false, tx) + build_workspace(Path::new(&project_path), false, None, None, tx) .await .unwrap(); } @@ -21,7 +21,7 @@ async fn not_shuttle() { async fn not_bin() { let (tx, _) = tokio::sync::mpsc::channel::(256); let project_path = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/resources/not-bin"); - build_workspace(Path::new(&project_path), false, tx) + build_workspace(Path::new(&project_path), false, None, None, tx) .await .unwrap(); } @@ -36,7 +36,7 @@ async fn not_full_macro() { env!("CARGO_MANIFEST_DIR"), "/tests/resources/not-full-macro" ); - build_workspace(Path::new(&project_path), false, tx) + build_workspace(Path::new(&project_path), false, None, None, tx) .await .unwrap(); } @@ -47,7 +47,7 @@ async fn is_bin() { let project_path = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/resources/is-bin"); assert_eq!( - build_workspace(Path::new(&project_path), false, tx) + build_workspace(Path::new(&project_path), false, None, None, tx) .await .unwrap(), BuiltService { @@ -64,7 +64,7 @@ async fn is_bin2() { let project_path = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/resources/is-bin2"); assert_eq!( - build_workspace(Path::new(&project_path), false, tx) + build_workspace(Path::new(&project_path), false, None, None, tx) .await .unwrap(), BuiltService { @@ -83,7 +83,7 @@ async fn not_found() { "{}/tests/resources/non-existing", env!("CARGO_MANIFEST_DIR") ); - build_workspace(Path::new(&project_path), false, tx) + build_workspace(Path::new(&project_path), false, None, None, tx) .await .unwrap(); } @@ -100,7 +100,7 @@ async fn workspace() { let project_path = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/resources/workspace"); assert_eq!( - build_workspace(Path::new(&project_path), false, tx) + build_workspace(Path::new(&project_path), false, None, None, tx) .await .unwrap(), BuiltService { diff --git a/cargo-shuttle/tests/integration/run.rs b/cargo-shuttle/tests/integration/run.rs index 6cd335fb2..3aa894477 100644 --- a/cargo-shuttle/tests/integration/run.rs +++ b/cargo-shuttle/tests/integration/run.rs @@ -46,6 +46,8 @@ async fn shuttle_run(working_directory: &str, external: bool) -> String { port, external, release: false, + profile: None, + features: None, raw: false, bacon: false, secret_args: Default::default(),