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

fix(cli): find correct binary when --profile is used, closes #6954 #6979

Merged
merged 2 commits into from
May 17, 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
5 changes: 5 additions & 0 deletions .changes/cli-profile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'cli.rs': 'patch'
---

Fix building with a custom cargo profile
21 changes: 15 additions & 6 deletions tooling/cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ impl AppSettings for RustAppSettings {
.expect("Cargo manifest must have the `package.name` field");

let out_dir = self
.out_dir(options.target.clone(), options.debug)
.out_dir(options.target.clone(), get_profile(options))
.with_context(|| "failed to get project out directory")?;

let binary_extension: String = if self.target_triple.contains("windows") {
Expand Down Expand Up @@ -900,12 +900,12 @@ impl RustAppSettings {
&self.cargo_package_settings
}

pub fn out_dir(&self, target: Option<String>, debug: bool) -> crate::Result<PathBuf> {
pub fn out_dir(&self, target: Option<String>, profile: String) -> crate::Result<PathBuf> {
get_target_dir(
target
.as_deref()
.or_else(|| self.cargo_config.build().target()),
!debug,
profile,
)
}
}
Expand All @@ -932,9 +932,9 @@ fn get_cargo_metadata() -> crate::Result<CargoMetadata> {
Ok(serde_json::from_slice(&output.stdout)?)
}

/// This function determines the 'target' directory and suffixes it with 'release' or 'debug'
/// This function determines the 'target' directory and suffixes it with the profile
/// to determine where the compiled binary will be located.
fn get_target_dir(target: Option<&str>, is_release: bool) -> crate::Result<PathBuf> {
fn get_target_dir(target: Option<&str>, profile: String) -> crate::Result<PathBuf> {
let mut path = get_cargo_metadata()
.with_context(|| "failed to get cargo metadata")?
.target_directory;
Expand All @@ -943,7 +943,7 @@ fn get_target_dir(target: Option<&str>, is_release: bool) -> crate::Result<PathB
path.push(triple);
}

path.push(if is_release { "release" } else { "debug" });
path.push(profile);

Ok(path)
}
Expand All @@ -957,6 +957,15 @@ pub fn get_workspace_dir() -> crate::Result<PathBuf> {
)
}

pub fn get_profile(options: &Options) -> String {
options
.args
.iter()
.position(|a| a == "--profile")
.map(|i| options.args[i + 1].clone())
.unwrap_or_else(|| if options.debug { "debug" } else { "release" }.into())
}

#[allow(unused_variables)]
fn tauri_config_to_bundle_settings(
manifest: &Manifest,
Expand Down
4 changes: 2 additions & 2 deletions tooling/cli/src/interface/rust/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use super::{AppSettings, DevChild, ExitReason, Options, RustAppSettings, Target};
use super::{get_profile, AppSettings, DevChild, ExitReason, Options, RustAppSettings, Target};
use crate::CommandExt;
use tauri_utils::display_path;

Expand Down Expand Up @@ -125,7 +125,7 @@ pub fn build(
options.target.replace(triple.into());

let triple_out_dir = app_settings
.out_dir(Some(triple.into()), options.debug)
.out_dir(Some(triple.into()), get_profile(&options))
.with_context(|| format!("failed to get {triple} out dir"))?;

build_production_app(options, available_targets, config_features.clone())
Expand Down