Skip to content

Commit 91d2762

Browse files
feat: add support for --profile and --features flags
Add support for custom build profiles and features in cargo-shuttle run command: - Add --profile flag to specify custom build profiles (e.g., --profile production) - Add --features flag to specify cargo features (e.g., --features "feature1 feature2") - Ensure --profile conflicts with --release to avoid confusion - Properly combine custom features with existing "shuttle" feature when present This allows users to have more control over the build process, matching the flexibility of standard cargo commands.
1 parent d4ea7eb commit 91d2762

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

cargo-shuttle/src/args.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,14 @@ pub struct RunArgs {
382382
#[arg(long)]
383383
pub external: bool,
384384
/// Use release mode for building the project
385-
#[arg(long, short = 'r')]
385+
#[arg(long, short = 'r', conflicts_with = "profile")]
386386
pub release: bool,
387+
/// Build with the specified profile
388+
#[arg(long, conflicts_with = "release")]
389+
pub profile: Option<String>,
390+
/// Space or comma separated list of features to activate
391+
#[arg(long)]
392+
pub features: Option<String>,
387393
/// Don't display timestamps and log origin tags
388394
#[arg(long)]
389395
pub raw: bool,

cargo-shuttle/src/builder.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub struct BuiltService {
2020
pub async fn build_workspace(
2121
project_path: &Path,
2222
release_mode: bool,
23+
profile: Option<&str>,
24+
features: Option<&str>,
2325
tx: tokio::sync::mpsc::Sender<String>,
2426
) -> Result<BuiltService> {
2527
let project_path = project_path.to_owned();
@@ -62,6 +64,8 @@ pub async fn build_workspace(
6264
package,
6365
target,
6466
release_mode,
67+
profile,
68+
features,
6569
project_path.clone(),
6670
metadata.target_directory.clone(),
6771
tx.clone(),
@@ -162,6 +166,8 @@ async fn cargo_build(
162166
package: Package,
163167
target: Target,
164168
release_mode: bool,
169+
profile: Option<&str>,
170+
features: Option<&str>,
165171
project_path: PathBuf,
166172
target_path: impl Into<PathBuf>,
167173
tx: tokio::sync::mpsc::Sender<String>,
@@ -182,12 +188,22 @@ async fn cargo_build(
182188
.current_dir(project_path.as_path());
183189

184190
if package.features.contains_key("shuttle") {
185-
cmd.arg("--no-default-features").arg("--features=shuttle");
191+
cmd.arg("--no-default-features");
192+
if let Some(features) = features {
193+
cmd.arg("--features").arg(format!("shuttle,{}", features));
194+
} else {
195+
cmd.arg("--features=shuttle");
196+
}
197+
} else if let Some(features) = features {
198+
cmd.arg("--features").arg(features);
186199
}
187200
cmd.arg("--package").arg(package.name.as_str());
188201
cmd.arg("--bin").arg(target.name.as_str());
189202

190-
let profile = if release_mode {
203+
let profile = if let Some(profile_name) = profile {
204+
cmd.arg("--profile").arg(profile_name);
205+
profile_name
206+
} else if release_mode {
191207
cmd.arg("--release");
192208
"release"
193209
} else {

cargo-shuttle/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ impl Shuttle {
13401340
project_directory.display()
13411341
);
13421342

1343-
build_workspace(project_directory, run_args.release, tx).await
1343+
build_workspace(project_directory, run_args.release, run_args.profile.as_deref(), run_args.features.as_deref(), tx).await
13441344
}
13451345

13461346
fn find_available_port(run_args: &mut RunArgs) {

cargo-shuttle/tests/integration/builder.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use cargo_shuttle::builder::{build_workspace, BuiltService};
99
async fn not_shuttle() {
1010
let (tx, _) = tokio::sync::mpsc::channel::<String>(256);
1111
let project_path = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/resources/not-shuttle");
12-
build_workspace(Path::new(&project_path), false, tx)
12+
build_workspace(Path::new(&project_path), false, None, None, tx)
1313
.await
1414
.unwrap();
1515
}
@@ -21,7 +21,7 @@ async fn not_shuttle() {
2121
async fn not_bin() {
2222
let (tx, _) = tokio::sync::mpsc::channel::<String>(256);
2323
let project_path = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/resources/not-bin");
24-
build_workspace(Path::new(&project_path), false, tx)
24+
build_workspace(Path::new(&project_path), false, None, None, tx)
2525
.await
2626
.unwrap();
2727
}
@@ -36,7 +36,7 @@ async fn not_full_macro() {
3636
env!("CARGO_MANIFEST_DIR"),
3737
"/tests/resources/not-full-macro"
3838
);
39-
build_workspace(Path::new(&project_path), false, tx)
39+
build_workspace(Path::new(&project_path), false, None, None, tx)
4040
.await
4141
.unwrap();
4242
}
@@ -47,7 +47,7 @@ async fn is_bin() {
4747
let project_path = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/resources/is-bin");
4848

4949
assert_eq!(
50-
build_workspace(Path::new(&project_path), false, tx)
50+
build_workspace(Path::new(&project_path), false, None, None, tx)
5151
.await
5252
.unwrap(),
5353
BuiltService {
@@ -64,7 +64,7 @@ async fn is_bin2() {
6464
let project_path = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/resources/is-bin2");
6565

6666
assert_eq!(
67-
build_workspace(Path::new(&project_path), false, tx)
67+
build_workspace(Path::new(&project_path), false, None, None, tx)
6868
.await
6969
.unwrap(),
7070
BuiltService {
@@ -83,7 +83,7 @@ async fn not_found() {
8383
"{}/tests/resources/non-existing",
8484
env!("CARGO_MANIFEST_DIR")
8585
);
86-
build_workspace(Path::new(&project_path), false, tx)
86+
build_workspace(Path::new(&project_path), false, None, None, tx)
8787
.await
8888
.unwrap();
8989
}
@@ -100,7 +100,7 @@ async fn workspace() {
100100
let project_path = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/resources/workspace");
101101

102102
assert_eq!(
103-
build_workspace(Path::new(&project_path), false, tx)
103+
build_workspace(Path::new(&project_path), false, None, None, tx)
104104
.await
105105
.unwrap(),
106106
BuiltService {

cargo-shuttle/tests/integration/run.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ async fn shuttle_run(working_directory: &str, external: bool) -> String {
4646
port,
4747
external,
4848
release: false,
49+
profile: None,
50+
features: None,
4951
raw: false,
5052
bacon: false,
5153
secret_args: Default::default(),

0 commit comments

Comments
 (0)