Browse Source

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

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

* clippy
Amr Bashir 2 years ago
parent
commit
fd3b5a16b1

+ 5 - 0
.changes/cli-profile.md

@@ -0,0 +1,5 @@
+---
+'cli.rs': 'patch'
+---
+
+Fix building with a custom cargo profile

+ 15 - 6
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<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,
     )
   }
 }
@@ -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;
@@ -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)
 }
@@ -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,

+ 2 - 2
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())