Skip to content

Commit fd3b5a1

Browse files
authored
fix(cli): find correct binary when --profile is used, closes #6954 (#6979)
* fix(cli): find correct binary when `--profile` is used, closes #6954 * clippy
1 parent 82169e6 commit fd3b5a1

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

.changes/cli-profile.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'cli.rs': 'patch'
3+
---
4+
5+
Fix building with a custom cargo profile

tooling/cli/src/interface/rust.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ impl AppSettings for RustAppSettings {
663663
.expect("Cargo manifest must have the `package.name` field");
664664

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

669669
let binary_extension: String = if self.target_triple.contains("windows") {
@@ -900,12 +900,12 @@ impl RustAppSettings {
900900
&self.cargo_package_settings
901901
}
902902

903-
pub fn out_dir(&self, target: Option<String>, debug: bool) -> crate::Result<PathBuf> {
903+
pub fn out_dir(&self, target: Option<String>, profile: String) -> crate::Result<PathBuf> {
904904
get_target_dir(
905905
target
906906
.as_deref()
907907
.or_else(|| self.cargo_config.build().target()),
908-
!debug,
908+
profile,
909909
)
910910
}
911911
}
@@ -932,9 +932,9 @@ fn get_cargo_metadata() -> crate::Result<CargoMetadata> {
932932
Ok(serde_json::from_slice(&output.stdout)?)
933933
}
934934

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

946-
path.push(if is_release { "release" } else { "debug" });
946+
path.push(profile);
947947

948948
Ok(path)
949949
}
@@ -957,6 +957,15 @@ pub fn get_workspace_dir() -> crate::Result<PathBuf> {
957957
)
958958
}
959959

960+
pub fn get_profile(options: &Options) -> String {
961+
options
962+
.args
963+
.iter()
964+
.position(|a| a == "--profile")
965+
.map(|i| options.args[i + 1].clone())
966+
.unwrap_or_else(|| if options.debug { "debug" } else { "release" }.into())
967+
}
968+
960969
#[allow(unused_variables)]
961970
fn tauri_config_to_bundle_settings(
962971
manifest: &Manifest,

tooling/cli/src/interface/rust/desktop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
use super::{AppSettings, DevChild, ExitReason, Options, RustAppSettings, Target};
5+
use super::{get_profile, AppSettings, DevChild, ExitReason, Options, RustAppSettings, Target};
66
use crate::CommandExt;
77
use tauri_utils::display_path;
88

@@ -125,7 +125,7 @@ pub fn build(
125125
options.target.replace(triple.into());
126126

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

131131
build_production_app(options, available_targets, config_features.clone())

0 commit comments

Comments
 (0)