Skip to content

Commit

Permalink
Only add --release arg when not provided by user
Browse files Browse the repository at this point in the history
  • Loading branch information
parasyte committed Apr 11, 2019
1 parent 59b1dd2 commit 9ed84bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,25 @@ struct CargoMessageMessage {
rendered: String,
}

crate fn run(profile: &str, args: &cli::BuildArgs) -> Result<CargoArtifact, SubcommandError> {
crate fn run(args: &cli::BuildArgs) -> Result<CargoArtifact, SubcommandError> {
let verbose = args.verbose();

// Add --release flag if necessary
let build_args = {
let release_flag = "--release".to_owned();

let mut args = args.rest.clone();
if !args.contains(&release_flag) {
args.push(release_flag);
}
args
};

let output = Command::new("cargo")
.arg("xbuild")
.arg("--message-format=json")
.arg(format!("--{}", profile))
.arg(format!("--target={}", args.target))
.args(args.rest.clone())
.args(build_args)
.stderr(Stdio::inherit())
.run(verbose)?;

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ fn build(args: Args) -> Result<(), BuildError> {
let mut args = cli::parse_build_args(args)?;

eprintln!("{:>12} with cargo xbuild", "Building".green().bold());
let artifact = cargo::run("release", &args)?;
let artifact = cargo::run(&args)?;

// Set default program name
if args.name.is_empty() {
Expand Down

0 comments on commit 9ed84bb

Please sign in to comment.