mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-27 15:13:23 +03:00
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>
This commit is contained in:
parent
5a0e922d40
commit
94e9d476ef
7
.changes/main_binary_name-exe.md
Normal file
7
.changes/main_binary_name-exe.md
Normal file
@ -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`
|
@ -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.
|
||||
|
@ -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));
|
||||
|
||||
|
@ -32,7 +32,7 @@ pub trait AppSettings {
|
||||
features: &[String],
|
||||
) -> crate::Result<tauri_bundler::BundleSettings>;
|
||||
fn app_binary_path(&self, options: &Options) -> crate::Result<PathBuf>;
|
||||
fn get_binaries(&self, target: &str) -> crate::Result<Vec<tauri_bundler::BundleBinary>>;
|
||||
fn get_binaries(&self) -> crate::Result<Vec<tauri_bundler::BundleBinary>>;
|
||||
fn app_name(&self) -> Option<String>;
|
||||
fn lib_name(&self) -> Option<String>;
|
||||
|
||||
@ -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());
|
||||
|
@ -864,7 +864,7 @@ impl AppSettings for RustAppSettings {
|
||||
}
|
||||
|
||||
fn app_binary_path(&self, options: &Options) -> crate::Result<PathBuf> {
|
||||
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<Vec<BundleBinary>> {
|
||||
fn get_binaries(&self) -> crate::Result<Vec<BundleBinary>> {
|
||||
let mut binaries: Vec<BundleBinary> = 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),
|
||||
|
Loading…
Reference in New Issue
Block a user