diff --git a/crates/tauri-bundler/Cargo.toml b/crates/tauri-bundler/Cargo.toml index b7345021a98..f78a8530208 100644 --- a/crates/tauri-bundler/Cargo.toml +++ b/crates/tauri-bundler/Cargo.toml @@ -62,7 +62,6 @@ tauri-macos-sign = { version = "0.1.1-rc.0", path = "../tauri-macos-sign" } [target."cfg(any(target_os = \"macos\", target_os = \"windows\"))".dependencies] regex = "1" -[target."cfg(target_os = \"linux\")".dependencies] heck = "0.5" ar = "0.9.0" md5 = "0.7.0" diff --git a/crates/tauri-bundler/src/bundle/common.rs b/crates/tauri-bundler/src/bundle/common.rs index bab78b7fbe0..67cacaf6995 100644 --- a/crates/tauri-bundler/src/bundle/common.rs +++ b/crates/tauri-bundler/src/bundle/common.rs @@ -3,14 +3,17 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT +use anyhow::Context; +use heck::ToKebabCase; use std::{ ffi::OsStr, fs::{self, File}, io::{self, BufRead, BufReader, BufWriter}, - path::Path, + path::{Path, PathBuf}, process::{Command, ExitStatus, Output, Stdio}, sync::{Arc, Mutex}, }; +use tauri_utils::display_path; /// Returns true if the path has a filename indicating that it is a high-density /// "retina" icon. Specifically, returns true the file stem ends with @@ -126,6 +129,44 @@ pub fn copy_dir(from: &Path, to: &Path) -> crate::Result<()> { Ok(()) } +pub(crate) fn use_v1_bin_name() -> bool { + let env_var = std::env::var("V1_COMPATIBLE_BIN_NAME"); + env_var.as_deref() == Ok("true") || env_var.as_deref() == Ok("1") +} + +pub(crate) fn rename_app( + target: &str, + bin_path: &Path, + product_name: &str, +) -> crate::Result { + let target_os = target + .split('-') + .nth(2) + .unwrap_or(std::env::consts::OS) + .replace("darwin", "macos"); + + let product_name = if target_os == "linux" { + product_name.to_kebab_case() + } else { + product_name.into() + }; + + let product_path = bin_path + .parent() + .unwrap() + .join(product_name) + .with_extension(bin_path.extension().unwrap_or_default()); + + fs::rename(bin_path, &product_path).with_context(|| { + format!( + "failed to rename `{}` to `{}`", + display_path(bin_path), + display_path(&product_path), + ) + })?; + Ok(product_path) +} + /// Copies user-defined files specified in the configuration file to the package. /// /// The configuration object maps the path in the package to the path of the file on the filesystem, diff --git a/crates/tauri-bundler/src/bundle/macos/app.rs b/crates/tauri-bundler/src/bundle/macos/app.rs index b91e43c5df4..5235de3cdf6 100644 --- a/crates/tauri-bundler/src/bundle/macos/app.rs +++ b/crates/tauri-bundler/src/bundle/macos/app.rs @@ -23,7 +23,7 @@ // files into the `Contents` directory of the bundle. use super::{ - super::common::{self, CommandExt}, + super::common::{self, rename_app, use_v1_bin_name, CommandExt}, icon::create_icns_file, sign::{notarize, notarize_auth, sign, NotarizeAuthError, SignTarget}, }; @@ -159,6 +159,9 @@ fn copy_binaries_to_bundle( let dest_path = dest_dir.join(bin.name()); common::copy_file(&bin_path, &dest_path) .with_context(|| format!("Failed to copy binary from {:?}", bin_path))?; + if use_v1_bin_name() && bin.name() == settings.main_binary_name() { + rename_app(settings.target(), &dest_path, settings.product_name())?; + } paths.push(dest_path); } Ok(paths) @@ -200,7 +203,12 @@ fn create_info_plist( plist.insert("CFBundleDisplayName".into(), settings.product_name().into()); plist.insert( "CFBundleExecutable".into(), - settings.main_binary_name().into(), + if use_v1_bin_name() { + settings.product_name() + } else { + settings.main_binary_name() + } + .into(), ); if let Some(path) = bundle_icon_file { plist.insert( diff --git a/crates/tauri-cli/ENVIRONMENT_VARIABLES.md b/crates/tauri-cli/ENVIRONMENT_VARIABLES.md index 5ce3089eeec..d6f821cd59c 100644 --- a/crates/tauri-cli/ENVIRONMENT_VARIABLES.md +++ b/crates/tauri-cli/ENVIRONMENT_VARIABLES.md @@ -37,6 +37,7 @@ These environment variables are inputs to the CLI which may have an equivalent C - `TAURI_WEBVIEW_AUTOMATION` — Enables webview automation (Linux Only). - `TAURI_ANDROID_PROJECT_PATH` — Path of the tauri android project, usually will be `/src-tauri/gen/android`. - `TAURI_IOS_PROJECT_PATH` — Path of the tauri iOS project, usually will be `/src-tauri/gen/ios`. +- `V1_COMPATIBLE_BIN_NAME` — If set, the CLI will rename the main app binary to the `productName`, as it did in Tauri v1. This is useful for allowing users of a Tauri v1 app to update the app to a v2 version via the updater. ### Tauri CLI Hook Commands