diff --git a/.changes/main_binary_name-exe.md b/.changes/main_binary_name-exe.md new file mode 100644 index 000000000..ba55e61b2 --- /dev/null +++ b/.changes/main_binary_name-exe.md @@ -0,0 +1,7 @@ +--- +"tauri-bundler": "patch:bug" +"tauri-cli": "patch:bug" +"@tauri-apps/cli": "patch:bug" +--- + +Fix `main_binary_name` in custom wix and nsis templates including `.exe` diff --git a/crates/tauri-bundler/src/bundle/settings.rs b/crates/tauri-bundler/src/bundle/settings.rs index eaac60a02..616c5f0fc 100644 --- a/crates/tauri-bundler/src/bundle/settings.rs +++ b/crates/tauri-bundler/src/bundle/settings.rs @@ -869,13 +869,25 @@ impl Settings { .iter() .find(|bin| bin.main) .context("failed to find main binary, make sure you have a `package > default-run` in the Cargo.toml file") - .map(|b| b.name.as_str()) + .map(|b| b.name()) .map_err(Into::into) } /// Returns the path to the specified binary. pub fn binary_path(&self, binary: &BundleBinary) -> PathBuf { - self.project_out_directory.join(binary.name()) + let target_os = self + .target() + .split('-') + .nth(2) + .unwrap_or(std::env::consts::OS); + + let path = self.project_out_directory.join(binary.name()); + + if target_os == "windows" { + path.with_extension("exe") + } else { + path + } } /// Returns the list of binaries to bundle. diff --git a/crates/tauri-bundler/src/bundle/windows/nsis.rs b/crates/tauri-bundler/src/bundle/windows/nsis.rs index 51fdc6c74..37ab9a3e6 100644 --- a/crates/tauri-bundler/src/bundle/windows/nsis.rs +++ b/crates/tauri-bundler/src/bundle/windows/nsis.rs @@ -337,7 +337,7 @@ fn build_nsis_app_installer( data.insert("language_files", to_json(language_files_paths)); let main_binary = settings.main_binary()?; - let main_binary_path = settings.binary_path(main_binary).with_extension("exe"); + let main_binary_path = settings.binary_path(main_binary); data.insert("main_binary_name", to_json(main_binary.name())); data.insert("main_binary_path", to_json(&main_binary_path)); diff --git a/crates/tauri-cli/src/interface/mod.rs b/crates/tauri-cli/src/interface/mod.rs index 3dc3dd58e..3c3bc7b30 100644 --- a/crates/tauri-cli/src/interface/mod.rs +++ b/crates/tauri-cli/src/interface/mod.rs @@ -32,7 +32,7 @@ pub trait AppSettings { features: &[String], ) -> crate::Result; fn app_binary_path(&self, options: &Options) -> crate::Result; - fn get_binaries(&self, target: &str) -> crate::Result>; + fn get_binaries(&self) -> crate::Result>; fn app_name(&self) -> Option; fn lib_name(&self) -> Option; @@ -55,7 +55,7 @@ pub trait AppSettings { tauri_utils::platform::target_triple()? }; - let mut bins = self.get_binaries(&target)?; + let mut bins = self.get_binaries()?; if let Some(main_binary_name) = &config.main_binary_name { let main = bins.iter_mut().find(|b| b.main()).context("no main bin?")?; main.set_name(main_binary_name.to_owned()); diff --git a/crates/tauri-cli/src/interface/rust.rs b/crates/tauri-cli/src/interface/rust.rs index ccb6594ef..4e2548481 100644 --- a/crates/tauri-cli/src/interface/rust.rs +++ b/crates/tauri-cli/src/interface/rust.rs @@ -864,7 +864,7 @@ impl AppSettings for RustAppSettings { } fn app_binary_path(&self, options: &Options) -> crate::Result { - let binaries = self.get_binaries(&self.target_triple)?; + let binaries = self.get_binaries()?; let bin_name = binaries .iter() .find(|x| x.main()) @@ -884,15 +884,9 @@ impl AppSettings for RustAppSettings { Ok(out_dir.join(bin_name).with_extension(ext)) } - fn get_binaries(&self, target: &str) -> crate::Result> { + fn get_binaries(&self) -> crate::Result> { let mut binaries: Vec = vec![]; - let ext = if target.contains("windows") { - ".exe" - } else { - "" - }; - if let Some(bins) = &self.cargo_settings.bin { let default_run = self .package_settings @@ -900,9 +894,12 @@ impl AppSettings for RustAppSettings { .clone() .unwrap_or_default(); for bin in bins { - let name = format!("{}{}", bin.name, ext); let is_main = bin.name == self.cargo_package_settings.name || bin.name == default_run; - binaries.push(BundleBinary::with_path(name, is_main, bin.path.clone())) + binaries.push(BundleBinary::with_path( + bin.name.clone(), + is_main, + bin.path.clone(), + )) } } @@ -943,7 +940,7 @@ impl AppSettings for RustAppSettings { .iter() .any(|bin| bin.name() == name || path.ends_with(bin.src_path().unwrap_or(&"".to_string()))); if !bin_exists { - binaries.push(BundleBinary::new(format!("{name}{ext}"), false)) + binaries.push(BundleBinary::new(name, false)) } } @@ -951,13 +948,13 @@ impl AppSettings for RustAppSettings { if let Some(binary) = binaries.iter_mut().find(|bin| bin.name() == default_run) { binary.set_main(true); } else { - binaries.push(BundleBinary::new(format!("{}{}", default_run, ext), true)); + binaries.push(BundleBinary::new(default_run.clone(), true)); } } match binaries.len() { 0 => binaries.push(BundleBinary::new( - format!("{}{}", self.cargo_package_settings.name, ext), + self.cargo_package_settings.name.clone(), true, )), 1 => binaries.get_mut(0).unwrap().set_main(true),