diff --git a/.changes/cli-profile.md b/.changes/cli-profile.md new file mode 100644 index 000000000000..fa48bfcb45d0 --- /dev/null +++ b/.changes/cli-profile.md @@ -0,0 +1,5 @@ +--- +'cli.rs': 'patch' +--- + +Fix building with a custom cargo profile diff --git a/tooling/cli/src/interface/rust.rs b/tooling/cli/src/interface/rust.rs index 7cb6f01ab90e..8ed4bde81d7f 100644 --- a/tooling/cli/src/interface/rust.rs +++ b/tooling/cli/src/interface/rust.rs @@ -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") { @@ -900,12 +900,12 @@ impl RustAppSettings { &self.cargo_package_settings } - pub fn out_dir(&self, target: Option, debug: bool) -> crate::Result { + pub fn out_dir(&self, target: Option, profile: String) -> crate::Result { get_target_dir( target .as_deref() .or_else(|| self.cargo_config.build().target()), - !debug, + profile, ) } } @@ -932,9 +932,9 @@ fn get_cargo_metadata() -> crate::Result { 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 { +fn get_target_dir(target: Option<&str>, profile: String) -> crate::Result { let mut path = get_cargo_metadata() .with_context(|| "failed to get cargo metadata")? .target_directory; @@ -943,7 +943,7 @@ fn get_target_dir(target: Option<&str>, is_release: bool) -> crate::Result crate::Result { ) } +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, diff --git a/tooling/cli/src/interface/rust/desktop.rs b/tooling/cli/src/interface/rust/desktop.rs index eefca7a2f03b..a09cc6479f2c 100644 --- a/tooling/cli/src/interface/rust/desktop.rs +++ b/tooling/cli/src/interface/rust/desktop.rs @@ -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; @@ -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())