Skip to content

Commit

Permalink
refactor(cli&bundler): avoid renaming main executable and reserve car…
Browse files Browse the repository at this point in the history
…go name

closes #8109
closes #8349
  • Loading branch information
amrbashir committed Apr 4, 2024
1 parent 9273d7b commit fecbc76
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 209 deletions.
7 changes: 7 additions & 0 deletions .changes/cli-perserve-cargo-bin-name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri-cli": "patch:breaking"
"@tauri-apps/cli": "patch:breaking"
---

Avoid renaming main binary to product name and perserve the name generated by cargo.

6 changes: 6 additions & 0 deletions .changes/tauri-utils-package-name-removed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-utils": "patch:breaking"
---

Removed `Config::binary_name` and `PackageInfo::package_name`

1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4105,8 +4105,10 @@ fn calculate_window_center_position(
{
use tao::platform::windows::MonitorHandleExtWindows;
use windows::Win32::Graphics::Gdi::{GetMonitorInfoW, HMONITOR, MONITORINFO};
let mut monitor_info = MONITORINFO::default();
monitor_info.cbSize = std::mem::size_of::<MONITORINFO>() as u32;
let mut monitor_info = MONITORINFO {
cbSize: std::mem::size_of::<MONITORINFO>() as u32,
..Default::default()
};
let status = unsafe { GetMonitorInfoW(HMONITOR(target_monitor.hmonitor()), &mut monitor_info) };
if status.into() {
let available_width = monitor_info.rcWork.right - monitor_info.rcWork.left;
Expand Down
3 changes: 0 additions & 3 deletions core/tauri-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ dunce = "1"
log = "0.4.21"
cargo_metadata = { version = "0.18", optional = true }

[target."cfg(target_os = \"linux\")".dependencies]
heck = "0.4"

[target."cfg(target_os = \"macos\")".dependencies]
swift-rs = { version = "1.0.6", optional = true, features = [ "build" ] }

Expand Down
17 changes: 0 additions & 17 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
//! This is a core functionality that is not considered part of the stable API.
//! If you use it, note that it may include breaking changes in the future.

#[cfg(target_os = "linux")]
use heck::ToKebabCase;
#[cfg(feature = "schema")]
use schemars::JsonSchema;
use semver::Version;
Expand Down Expand Up @@ -2056,21 +2054,6 @@ pub struct Config {
pub plugins: PluginConfig,
}

impl Config {
/// The binary name. Returns the product name as kebab-case on Linux,
/// and returns it as is on all other platforms.
pub fn binary_name(&self) -> Option<String> {
#[cfg(target_os = "linux")]
{
self.product_name.as_ref().map(|n| n.to_kebab_case())
}
#[cfg(not(target_os = "linux"))]
{
self.product_name.clone()
}
}
}

/// The plugin configs holds a HashMap mapping a plugin name to its configuration object.
///
/// See more: <https://tauri.app/v1/api/config#pluginconfig>
Expand Down
14 changes: 0 additions & 14 deletions core/tauri-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,6 @@ pub struct PackageInfo {
pub crate_name: &'static str,
}

impl PackageInfo {
/// Returns the application package name.
/// On macOS and Windows it's the `name` field, and on Linux it's the `name` in `kebab-case`.
pub fn package_name(&self) -> String {
#[cfg(target_os = "linux")]
{
use heck::ToKebabCase;
self.name.clone().to_kebab_case()
}
#[cfg(not(target_os = "linux"))]
self.name.clone()
}
}

#[allow(deprecated)]
mod window_effects {
use super::*;
Expand Down
6 changes: 3 additions & 3 deletions core/tauri-utils/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,21 +292,21 @@ fn resource_dir_from<P: AsRef<Path>>(
res = if curr_dir.ends_with("/data/usr/bin") {
// running from the deb bundle dir
exe_dir
.join(format!("../lib/{}", package_info.package_name()))
.join(format!("../lib/{}", package_info.crate_name))
.canonicalize()
.map_err(Into::into)
} else if let Some(appdir) = &env.appdir {
let appdir: &std::path::Path = appdir.as_ref();
Ok(PathBuf::from(format!(
"{}/usr/lib/{}",
appdir.display(),
package_info.package_name()
package_info.crate_name
)))
} else {
// running bundle
Ok(PathBuf::from(format!(
"/usr/lib/{}",
package_info.package_name()
package_info.crate_name
)))
};
}
Expand Down
11 changes: 1 addition & 10 deletions core/tauri/src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1955,16 +1955,7 @@ tauri::Builder::default()
.set_progress_bar(crate::runtime::ProgressBarState {
status: progress_state.status,
progress: progress_state.progress,
desktop_filename: Some(format!(
"{}.desktop",
heck::AsKebabCase(
self
.config()
.product_name
.as_deref()
.unwrap_or_else(|| self.package_info().crate_name)
)
)),
desktop_filename: Some(format!("{}.desktop", self.package_info().crate_name)),
})
.map_err(Into::into)
}
Expand Down
1 change: 0 additions & 1 deletion tooling/bundler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ plist = "1"
regex = "1"

[target."cfg(target_os = \"linux\")".dependencies]
heck = "0.4"
ar = "0.9.0"
md5 = "0.7.0"
rpm = "0.14.0"
Expand Down
4 changes: 2 additions & 2 deletions tooling/bundler/src/bundle/linux/debian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use super::{super::common, freedesktop};
use crate::Settings;
use anyhow::Context;
use flate2::{write::GzEncoder, Compression};
use heck::AsKebabCase;
use tar::HeaderMode;
use walkdir::WalkDir;

Expand Down Expand Up @@ -158,7 +157,8 @@ fn generate_control_file(
// https://www.debian.org/doc/debian-policy/ch-controlfields.html
let dest_path = control_dir.join("control");
let mut file = common::create_file(&dest_path)?;
writeln!(file, "Package: {}", AsKebabCase(settings.product_name()))?;
let package = heck::AsKebabCase(settings.product_name());
writeln!(file, "Package: {}", package)?;
writeln!(file, "Version: {}", settings.version_string())?;
writeln!(file, "Architecture: {arch}")?;
// Installed-Size must be divided by 1024, see https://www.debian.org/doc/debian-policy/ch-controlfields.html#installed-size
Expand Down
2 changes: 1 addition & 1 deletion tooling/bundler/src/bundle/linux/freedesktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn list_icon_files(

/// Generate the icon files and store them under the `data_dir`.
pub fn copy_icon_files(settings: &Settings, data_dir: &Path) -> crate::Result<Vec<Icon>> {
let icons = self::list_icon_files(settings, data_dir)?;
let icons = list_icon_files(settings, data_dir)?;
for (icon, src) in &icons {
common::copy_file(src, &icon.path)?;
}
Expand Down
9 changes: 9 additions & 0 deletions tooling/bundler/src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,15 @@ impl BundleBinary {
}
}

/// Creates a new bundle binary with path.
pub fn with_path(name: String, main: bool, src_path: Option<String>) -> Self {
Self {
name,
src_path,
main,
}
}

/// Sets the src path of the binary.
#[must_use]
pub fn set_src_path(mut self, src_path: Option<String>) -> Self {
Expand Down
28 changes: 14 additions & 14 deletions tooling/bundler/src/bundle/windows/msi/wix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use regex::Regex;
use serde::{Deserialize, Serialize};
use std::{
collections::{BTreeMap, HashMap, HashSet},
fs::{create_dir_all, read_to_string, remove_dir_all, rename, write, File},
fs::{self, File},
io::Write,
path::{Path, PathBuf},
process::Command,
Expand Down Expand Up @@ -155,7 +155,7 @@ fn copy_icon(settings: &Settings, filename: &str, path: &Path) -> crate::Result<
let base_dir = settings.project_out_directory();

let resource_dir = base_dir.join("resources");
create_dir_all(&resource_dir)?;
fs::create_dir_all(&resource_dir)?;
let icon_target_path = resource_dir.join(filename);

let icon_path = std::env::current_dir()?.join(path);
Expand Down Expand Up @@ -411,9 +411,9 @@ pub fn build_wix_app_installer(
let output_path = settings.project_out_directory().join("wix").join(arch);

if output_path.exists() {
remove_dir_all(&output_path)?;
fs::remove_dir_all(&output_path)?;
}
create_dir_all(&output_path)?;
fs::create_dir_all(&output_path)?;

let mut data = BTreeMap::new();

Expand Down Expand Up @@ -488,7 +488,7 @@ pub fn build_wix_app_installer(
if license.ends_with(".rtf") {
data.insert("license", to_json(license));
} else {
let license_contents = read_to_string(license)?;
let license_contents = fs::read_to_string(license)?;
let license_rtf = format!(
r#"{{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{{\fonttbl{{\f0\fnil\fcharset0 Calibri;}}}}
{{\*\generator Riched20 10.0.18362}}\viewkind4\uc1
Expand Down Expand Up @@ -629,7 +629,7 @@ pub fn build_wix_app_installer(

if let Some(path) = custom_template_path {
handlebars
.register_template_string("main.wxs", read_to_string(path)?)
.register_template_string("main.wxs", fs::read_to_string(path)?)
.map_err(|e| e.to_string())
.expect("Failed to setup custom handlebar template");
} else {
Expand Down Expand Up @@ -660,7 +660,7 @@ pub fn build_wix_app_installer(
.expect("Failed to setup Update Task handlebars");
let temp_xml_path = output_path.join("update.xml");
let update_content = skip_uac_task.render("update.xml", &data)?;
write(temp_xml_path, update_content)?;
fs::write(temp_xml_path, update_content)?;

// Create the Powershell script to install the task
let mut skip_uac_task_installer = Handlebars::new();
Expand All @@ -672,7 +672,7 @@ pub fn build_wix_app_installer(
.expect("Failed to setup Update Task Installer handlebars");
let temp_ps1_path = output_path.join("install-task.ps1");
let install_script_content = skip_uac_task_installer.render("install-task.ps1", &data)?;
write(temp_ps1_path, install_script_content)?;
fs::write(temp_ps1_path, install_script_content)?;

// Create the Powershell script to uninstall the task
let mut skip_uac_task_uninstaller = Handlebars::new();
Expand All @@ -684,21 +684,21 @@ pub fn build_wix_app_installer(
.expect("Failed to setup Update Task Uninstaller handlebars");
let temp_ps1_path = output_path.join("uninstall-task.ps1");
let install_script_content = skip_uac_task_uninstaller.render("uninstall-task.ps1", &data)?;
write(temp_ps1_path, install_script_content)?;
fs::write(temp_ps1_path, install_script_content)?;

data.insert("enable_elevated_update_task", to_json(true));
}

let main_wxs_path = output_path.join("main.wxs");
write(main_wxs_path, handlebars.render("main.wxs", &data)?)?;
fs::write(main_wxs_path, handlebars.render("main.wxs", &data)?)?;

let mut candle_inputs = vec![("main.wxs".into(), Vec::new())];

let current_dir = std::env::current_dir()?;
let extension_regex = Regex::new("\"http://schemas.microsoft.com/wix/(\\w+)\"")?;
for fragment_path in fragment_paths {
let fragment_path = current_dir.join(fragment_path);
let fragment = read_to_string(&fragment_path)?;
let fragment = fs::read_to_string(&fragment_path)?;
let mut extensions = Vec::new();
for cap in extension_regex.captures_iter(&fragment) {
extensions.push(wix_toolset_path.join(format!("Wix{}.dll", &cap[1])));
Expand Down Expand Up @@ -734,7 +734,7 @@ pub fn build_wix_app_installer(
});

let locale_contents = match language_config.locale_path {
Some(p) => read_to_string(p)?,
Some(p) => fs::read_to_string(p)?,
None => format!(
r#"<WixLocalization Culture="{}" xmlns="http://schemas.microsoft.com/wix/2006/localization"></WixLocalization>"#,
language.to_lowercase(),
Expand Down Expand Up @@ -786,7 +786,7 @@ pub fn build_wix_app_installer(
let msi_output_path = output_path.join("output.msi");
let msi_path =
app_installer_output_path(settings, &language, settings.version_string(), updater)?;
create_dir_all(msi_path.parent().unwrap())?;
fs::create_dir_all(msi_path.parent().unwrap())?;

log::info!(action = "Running"; "light to produce {}", display_path(&msi_path));

Expand All @@ -797,7 +797,7 @@ pub fn build_wix_app_installer(
&(fragment_extensions.clone().into_iter().collect()),
&msi_output_path,
)?;
rename(&msi_output_path, &msi_path)?;
fs::rename(&msi_output_path, &msi_path)?;
try_sign(&msi_path, settings)?;
output_paths.push(msi_path);
}
Expand Down
20 changes: 10 additions & 10 deletions tooling/bundler/src/bundle/windows/nsis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use tauri_utils::config::{NSISInstallerMode, NsisCompression, WebviewInstallMode

use std::{
collections::{BTreeMap, HashMap},
fs::{copy, create_dir_all, remove_dir_all, rename, write},
fs,
path::{Path, PathBuf},
process::Command,
};
Expand Down Expand Up @@ -93,7 +93,7 @@ pub fn bundle_project(settings: &Settings, updater: bool) -> crate::Result<Vec<P
log::warn!("NSIS directory contains mis-hashed files. Redownloading them.");
for (path, url, hash, hash_algorithim) in mismatched {
let data = download_and_verify(url, hash, *hash_algorithim)?;
write(nsis_toolset_path.join(path), data)?;
fs::write(nsis_toolset_path.join(path), data)?;
}
}
}
Expand All @@ -110,7 +110,7 @@ fn get_and_extract_nsis(nsis_toolset_path: &Path, _tauri_tools_path: &Path) -> c
let data = download_and_verify(NSIS_URL, NSIS_SHA1, HashAlgorithm::Sha1)?;
log::info!("extracting NSIS");
extract_zip(&data, _tauri_tools_path)?;
rename(_tauri_tools_path.join("nsis-3.08"), nsis_toolset_path)?;
fs::rename(_tauri_tools_path.join("nsis-3.08"), nsis_toolset_path)?;
}

let nsis_plugins = nsis_toolset_path.join("Plugins");
Expand All @@ -119,9 +119,9 @@ fn get_and_extract_nsis(nsis_toolset_path: &Path, _tauri_tools_path: &Path) -> c
log::info!("extracting NSIS ApplicationID plugin");
extract_zip(&data, &nsis_plugins)?;

create_dir_all(nsis_plugins.join("x86-unicode"))?;
fs::create_dir_all(nsis_plugins.join("x86-unicode"))?;

copy(
fs::copy(
nsis_plugins
.join("ReleaseUnicode")
.join("ApplicationID.dll"),
Expand All @@ -133,7 +133,7 @@ fn get_and_extract_nsis(nsis_toolset_path: &Path, _tauri_tools_path: &Path) -> c
NSIS_TAURI_UTILS_SHA1,
HashAlgorithm::Sha1,
)?;
write(
fs::write(
nsis_plugins
.join("x86-unicode")
.join("nsis_tauri_utils.dll"),
Expand Down Expand Up @@ -187,9 +187,9 @@ fn build_nsis_app_installer(

let output_path = settings.project_out_directory().join("nsis").join(arch);
if output_path.exists() {
remove_dir_all(&output_path)?;
fs::remove_dir_all(&output_path)?;
}
create_dir_all(&output_path)?;
fs::create_dir_all(&output_path)?;

let mut data = BTreeMap::new();

Expand Down Expand Up @@ -486,7 +486,7 @@ fn build_nsis_app_installer(
},
package_base_name
));
create_dir_all(nsis_installer_path.parent().unwrap())?;
fs::create_dir_all(nsis_installer_path.parent().unwrap())?;

log::info!(action = "Running"; "makensis.exe to produce {}", display_path(&nsis_installer_path));

Expand All @@ -509,7 +509,7 @@ fn build_nsis_app_installer(
.piped()
.context("error running makensis.exe")?;

rename(nsis_output_path, &nsis_installer_path)?;
fs::rename(nsis_output_path, &nsis_installer_path)?;

// Code signing is currently only supported on Windows hosts
#[cfg(target_os = "windows")]
Expand Down

0 comments on commit fecbc76

Please sign in to comment.