Skip to content
Open
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
8 changes: 7 additions & 1 deletion cargo-shuttle/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// Space or comma separated list of features to activate
#[arg(long)]
pub features: Option<String>,
/// Don't display timestamps and log origin tags
#[arg(long)]
pub raw: bool,
Expand Down
20 changes: 18 additions & 2 deletions cargo-shuttle/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
) -> Result<BuiltService> {
let project_path = project_path.to_owned();
Expand Down Expand Up @@ -62,6 +64,8 @@ pub async fn build_workspace(
package,
target,
release_mode,
profile,
features,
project_path.clone(),
metadata.target_directory.clone(),
tx.clone(),
Expand Down Expand Up @@ -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<PathBuf>,
tx: tokio::sync::mpsc::Sender<String>,
Expand All @@ -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 {
Expand Down
9 changes: 8 additions & 1 deletion cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 7 additions & 7 deletions cargo-shuttle/tests/integration/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use cargo_shuttle::builder::{build_workspace, BuiltService};
async fn not_shuttle() {
let (tx, _) = tokio::sync::mpsc::channel::<String>(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();
}
Expand All @@ -21,7 +21,7 @@ async fn not_shuttle() {
async fn not_bin() {
let (tx, _) = tokio::sync::mpsc::channel::<String>(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();
}
Expand All @@ -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();
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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();
}
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions cargo-shuttle/tests/integration/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down