Skip to content

Commit 94e9d47

Browse files
fix: fix main_binary_name includes .exe regression on Windows (#11011)
* fix: fix `main_binary_name` includes `.exe` regression on Windows * Update crates/tauri-bundler/src/bundle/settings.rs * Update .changes/main_binary_name-exe.md --------- Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.app>
1 parent 5a0e922 commit 94e9d47

File tree

5 files changed

+34
-18
lines changed

5 files changed

+34
-18
lines changed

.changes/main_binary_name-exe.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri-bundler": "patch:bug"
3+
"tauri-cli": "patch:bug"
4+
"@tauri-apps/cli": "patch:bug"
5+
---
6+
7+
Fix `main_binary_name` in custom wix and nsis templates including `.exe`

crates/tauri-bundler/src/bundle/settings.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -869,13 +869,25 @@ impl Settings {
869869
.iter()
870870
.find(|bin| bin.main)
871871
.context("failed to find main binary, make sure you have a `package > default-run` in the Cargo.toml file")
872-
.map(|b| b.name.as_str())
872+
.map(|b| b.name())
873873
.map_err(Into::into)
874874
}
875875

876876
/// Returns the path to the specified binary.
877877
pub fn binary_path(&self, binary: &BundleBinary) -> PathBuf {
878-
self.project_out_directory.join(binary.name())
878+
let target_os = self
879+
.target()
880+
.split('-')
881+
.nth(2)
882+
.unwrap_or(std::env::consts::OS);
883+
884+
let path = self.project_out_directory.join(binary.name());
885+
886+
if target_os == "windows" {
887+
path.with_extension("exe")
888+
} else {
889+
path
890+
}
879891
}
880892

881893
/// Returns the list of binaries to bundle.

crates/tauri-bundler/src/bundle/windows/nsis.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ fn build_nsis_app_installer(
337337
data.insert("language_files", to_json(language_files_paths));
338338

339339
let main_binary = settings.main_binary()?;
340-
let main_binary_path = settings.binary_path(main_binary).with_extension("exe");
340+
let main_binary_path = settings.binary_path(main_binary);
341341
data.insert("main_binary_name", to_json(main_binary.name()));
342342
data.insert("main_binary_path", to_json(&main_binary_path));
343343

crates/tauri-cli/src/interface/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub trait AppSettings {
3232
features: &[String],
3333
) -> crate::Result<tauri_bundler::BundleSettings>;
3434
fn app_binary_path(&self, options: &Options) -> crate::Result<PathBuf>;
35-
fn get_binaries(&self, target: &str) -> crate::Result<Vec<tauri_bundler::BundleBinary>>;
35+
fn get_binaries(&self) -> crate::Result<Vec<tauri_bundler::BundleBinary>>;
3636
fn app_name(&self) -> Option<String>;
3737
fn lib_name(&self) -> Option<String>;
3838

@@ -55,7 +55,7 @@ pub trait AppSettings {
5555
tauri_utils::platform::target_triple()?
5656
};
5757

58-
let mut bins = self.get_binaries(&target)?;
58+
let mut bins = self.get_binaries()?;
5959
if let Some(main_binary_name) = &config.main_binary_name {
6060
let main = bins.iter_mut().find(|b| b.main()).context("no main bin?")?;
6161
main.set_name(main_binary_name.to_owned());

crates/tauri-cli/src/interface/rust.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ impl AppSettings for RustAppSettings {
864864
}
865865

866866
fn app_binary_path(&self, options: &Options) -> crate::Result<PathBuf> {
867-
let binaries = self.get_binaries(&self.target_triple)?;
867+
let binaries = self.get_binaries()?;
868868
let bin_name = binaries
869869
.iter()
870870
.find(|x| x.main())
@@ -884,25 +884,22 @@ impl AppSettings for RustAppSettings {
884884
Ok(out_dir.join(bin_name).with_extension(ext))
885885
}
886886

887-
fn get_binaries(&self, target: &str) -> crate::Result<Vec<BundleBinary>> {
887+
fn get_binaries(&self) -> crate::Result<Vec<BundleBinary>> {
888888
let mut binaries: Vec<BundleBinary> = vec![];
889889

890-
let ext = if target.contains("windows") {
891-
".exe"
892-
} else {
893-
""
894-
};
895-
896890
if let Some(bins) = &self.cargo_settings.bin {
897891
let default_run = self
898892
.package_settings
899893
.default_run
900894
.clone()
901895
.unwrap_or_default();
902896
for bin in bins {
903-
let name = format!("{}{}", bin.name, ext);
904897
let is_main = bin.name == self.cargo_package_settings.name || bin.name == default_run;
905-
binaries.push(BundleBinary::with_path(name, is_main, bin.path.clone()))
898+
binaries.push(BundleBinary::with_path(
899+
bin.name.clone(),
900+
is_main,
901+
bin.path.clone(),
902+
))
906903
}
907904
}
908905

@@ -943,21 +940,21 @@ impl AppSettings for RustAppSettings {
943940
.iter()
944941
.any(|bin| bin.name() == name || path.ends_with(bin.src_path().unwrap_or(&"".to_string())));
945942
if !bin_exists {
946-
binaries.push(BundleBinary::new(format!("{name}{ext}"), false))
943+
binaries.push(BundleBinary::new(name, false))
947944
}
948945
}
949946

950947
if let Some(default_run) = self.package_settings.default_run.as_ref() {
951948
if let Some(binary) = binaries.iter_mut().find(|bin| bin.name() == default_run) {
952949
binary.set_main(true);
953950
} else {
954-
binaries.push(BundleBinary::new(format!("{}{}", default_run, ext), true));
951+
binaries.push(BundleBinary::new(default_run.clone(), true));
955952
}
956953
}
957954

958955
match binaries.len() {
959956
0 => binaries.push(BundleBinary::new(
960-
format!("{}{}", self.cargo_package_settings.name, ext),
957+
self.cargo_package_settings.name.clone(),
961958
true,
962959
)),
963960
1 => binaries.get_mut(0).unwrap().set_main(true),

0 commit comments

Comments
 (0)